tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

FileSystemBaseHandle-getUniqueId.js (3669B)


      1 'use strict';
      2 
      3 directory_test(async (t, root_dir) => {
      4  assert_equals(await root_dir.getUniqueId(), await root_dir.getUniqueId());
      5 
      6  const subdir = await createDirectory('subdir-name', root_dir);
      7  assert_equals(await subdir.getUniqueId(), await subdir.getUniqueId());
      8 }, 'identical directory handles return the same ID');
      9 
     10 directory_test(async (t, root_dir) => {
     11  const subdir = await createDirectory('subdir-name', root_dir);
     12 
     13  assert_not_equals(await root_dir.getUniqueId(), await subdir.getUniqueId());
     14 }, 'different directories return different IDs');
     15 
     16 directory_test(async (t, root_dir) => {
     17  const subdir = await createDirectory('subdir-name', root_dir);
     18  const subdir2 = await root_dir.getDirectoryHandle('subdir-name');
     19 
     20  assert_equals(await subdir.getUniqueId(), await subdir2.getUniqueId());
     21 }, 'different handles for the same directory return the same ID');
     22 
     23 directory_test(async (t, root_dir) => {
     24  const handle = await createEmptyFile('foo.txt', root_dir);
     25 
     26  assert_equals(await handle.getUniqueId(), await handle.getUniqueId());
     27 }, 'identical file handles return the same unique ID');
     28 
     29 directory_test(async (t, root_dir) => {
     30  const handle1 = await createEmptyFile('foo.txt', root_dir);
     31  const handle2 = await createEmptyFile('bar.txt', root_dir);
     32 
     33  assert_not_equals(await handle1.getUniqueId(), await handle2.getUniqueId());
     34 }, 'different files return different IDs');
     35 
     36 directory_test(async (t, root_dir) => {
     37  const handle1 = await createEmptyFile('foo.txt', root_dir);
     38  const handle2 = await root_dir.getFileHandle('foo.txt');
     39 
     40  assert_equals(await handle1.getUniqueId(), await handle2.getUniqueId());
     41 }, 'different handles for the same file return the same ID');
     42 
     43 directory_test(async (t, root_dir) => {
     44  const handle1 = await createEmptyFile('foo.txt', root_dir);
     45  const subdir = await createDirectory('subdir-name', root_dir);
     46  const handle2 = await createEmptyFile('foo.txt', subdir);
     47 
     48  assert_not_equals(await handle1.getUniqueId(), await handle2.getUniqueId());
     49 }, 'two files of the same name in different directories return different IDs');
     50 
     51 directory_test(async (t, root_dir) => {
     52  const handle1 = await createEmptyFile('foo.txt', root_dir);
     53  const handle2 = await createDirectory('subdir-name', root_dir);
     54 
     55  assert_not_equals(await handle1.getUniqueId(), await handle2.getUniqueId());
     56 }, 'a file and a directory return different IDs');
     57 
     58 directory_test(async (t, root_dir) => {
     59  const file_handle = await createEmptyFile('foo', root_dir);
     60  const file_id = await file_handle.getUniqueId();
     61 
     62  // Remove the file.
     63  await root_dir.removeEntry('foo');
     64 
     65  // Create a directory of the same name and path.
     66  const dir_handle = await createDirectory('foo', root_dir);
     67  assert_not_equals(await dir_handle.getUniqueId(), file_id);
     68 }, 'a file and a directory of the same path return different IDs');
     69 
     70 directory_test(async (t, root_dir) => {
     71  const handle = await createEmptyFile('foo.txt', root_dir);
     72  const id_before = await handle.getUniqueId();
     73 
     74  // Write to the file. The unique ID should not change.
     75  const writable = await cleanup_writable(t, await handle.createWritable());
     76  await writable.write("blah");
     77  await writable.close();
     78 
     79  assert_equals(await handle.getUniqueId(), id_before);
     80 }, 'unique ID of a file handle does not change after writes');
     81 
     82 directory_test(async (t, root_dir) => {
     83  const subdir = await createDirectory('subdir-name', root_dir);
     84 
     85  const UUIDRegex =
     86      /^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$/
     87  assert_true(UUIDRegex.test(await root_dir.getUniqueId()));
     88  assert_true(UUIDRegex.test(await subdir.getUniqueId()));
     89 }, 'unique ID is in GUID version 4 format');