summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/fs/script-tests/FileSystemBaseHandle-isSameEntry.js
blob: e3b6d1891e1ec1bafbbeeac3652944c9c699638c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
'use strict';

directory_test(async (t, root_dir) => {
  assert_true(await root_dir.isSameEntry(root_dir));

  const subdir = await createDirectory(t, 'subdir-name', root_dir);
  assert_true(await subdir.isSameEntry(subdir));
}, 'isSameEntry for identical directory handles returns true');

directory_test(async (t, root_dir) => {
  const subdir = await createDirectory(t, 'subdir-name', root_dir);

  assert_false(await root_dir.isSameEntry(subdir));
  assert_false(await subdir.isSameEntry(root_dir));
}, 'isSameEntry for different directories returns false');

directory_test(async (t, root_dir) => {
  const subdir = await createDirectory(t, 'subdir-name', root_dir);
  const subdir2 = await root_dir.getDirectoryHandle('subdir-name');

  assert_true(await subdir.isSameEntry(subdir2));
  assert_true(await subdir2.isSameEntry(subdir));
}, 'isSameEntry for different handles for the same directory');

directory_test(async (t, root_dir) => {
  const handle = await createEmptyFile(t, 'mtime.txt', root_dir);

  assert_true(await handle.isSameEntry(handle));
}, 'isSameEntry for identical file handles returns true');

directory_test(async (t, root_dir) => {
  const handle1 = await createEmptyFile(t, 'mtime.txt', root_dir);
  const handle2 = await createEmptyFile(t, 'foo.txt', root_dir);

  assert_false(await handle1.isSameEntry(handle2));
  assert_false(await handle2.isSameEntry(handle1));
}, 'isSameEntry for different files returns false');

directory_test(async (t, root_dir) => {
  const handle1 = await createEmptyFile(t, 'mtime.txt', root_dir);
  const handle2 = await root_dir.getFileHandle('mtime.txt');

  assert_true(await handle1.isSameEntry(handle2));
  assert_true(await handle2.isSameEntry(handle1));
}, 'isSameEntry for different handles for the same file');

directory_test(async (t, root_dir) => {
  const handle1 = await createEmptyFile(t, 'mtime.txt', root_dir);
  const subdir = await createDirectory(t, 'subdir-name', root_dir);
  const handle2 = await createEmptyFile(t, 'mtime.txt', subdir);

  assert_false(await handle1.isSameEntry(handle2));
  assert_false(await handle2.isSameEntry(handle1));
}, 'isSameEntry comparing a file to a file in a different directory returns false');

directory_test(async (t, root_dir) => {
  const handle1 = await createEmptyFile(t, 'mtime.txt', root_dir);
  const handle2 = await createDirectory(t, 'subdir-name', root_dir);

  assert_false(await handle1.isSameEntry(handle2));
  assert_false(await handle2.isSameEntry(handle1));
}, 'isSameEntry comparing a file to a directory returns false');

directory_test(async (t, root_dir) => {
  const filename = 'foo';
  const handle1 = await createEmptyFile(t, filename, root_dir);
  // Remove the file and create a new file of the same path.
  await root_dir.removeEntry(filename);
  const handle2 = await createEmptyFile(t, filename, root_dir);

  assert_true(
      await handle1.isSameEntry(handle2),
      'two file handles pointing at the same path should be considered the same entry');
  assert_true(
      await handle2.isSameEntry(handle1),
      'two file handles pointing at the same path should be considered the same entry');
}, 'isSameEntry comparing two files pointing to the same path returns true');

directory_test(async (t, root_dir) => {
  const filename = 'foo';
  const handle1 = await createDirectory(t, filename, root_dir);
  // Remove the directory and create a new directory of the same path.
  await root_dir.removeEntry(filename);
  const handle2 = await createDirectory(t, filename, root_dir);

  assert_true(
      await handle1.isSameEntry(handle2),
      'two directory handles pointing at the same path should be considered the same entry');
  assert_true(
      await handle2.isSameEntry(handle1),
      'two directory handles pointing at the same path should be considered the same entry');
}, 'isSameEntry comparing two directories pointing to the same path returns true');

directory_test(async (t, root_dir) => {
  const filename = 'foo';
  const dir_handle = await createDirectory(t, filename, root_dir);
  // Remove the directory and create a file of the same path.
  await root_dir.removeEntry(filename);
  const file_handle = await createEmptyFile(t, filename, root_dir);

  assert_false(
      await dir_handle.isSameEntry(file_handle),
      'a file and directory handle pointing at the same path should not be considered the same entry');
  assert_false(
      await file_handle.isSameEntry(dir_handle),
      'a file and directory handle pointing at the same path should not be considered the same entry');
}, 'isSameEntry comparing a file to a directory of the same path returns false');