tor-browser

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

test_remote_settings_sync_history.js (1686B)


      1 "use strict";
      2 
      3 async function clear_state() {
      4  await new SyncHistory("").clear();
      5 }
      6 add_task(clear_state);
      7 
      8 add_task(async function test_entries_are_stored_by_source() {
      9  const history = new SyncHistory();
     10  await history.store("42", "success", { pi: "3.14" });
     11  // Check that history is isolated by source.
     12  await new SyncHistory("main/cfr").store("88", "error");
     13 
     14  const l = await history.list();
     15 
     16  Assert.deepEqual(l, [
     17    {
     18      timestamp: 42,
     19      status: "success",
     20      infos: { pi: "3.14" },
     21      datetime: new Date(42),
     22    },
     23  ]);
     24 });
     25 add_task(clear_state);
     26 
     27 add_task(
     28  async function test_old_entries_are_removed_keep_fixed_size_per_source() {
     29    const history = new SyncHistory("settings-sync", { size: 3 });
     30    const anotherHistory = await new SyncHistory("main/cfr");
     31 
     32    await history.store("42", "success");
     33    await history.store("41", "sync_error");
     34    await history.store("43", "up_to_date");
     35 
     36    let l = await history.list();
     37    Assert.equal(l.length, 3);
     38 
     39    await history.store("44", "success");
     40    await anotherHistory.store("44", "success");
     41 
     42    l = await history.list();
     43    Assert.equal(l.length, 3);
     44    Assert.ok(!l.map(e => e.timestamp).includes(41));
     45 
     46    l = await anotherHistory.list();
     47    Assert.equal(l.length, 1);
     48  }
     49 );
     50 add_task(clear_state);
     51 
     52 add_task(async function test_entries_are_sorted_by_timestamp_desc() {
     53  const history = new SyncHistory("settings-sync");
     54  await history.store("42", "success");
     55  await history.store("41", "sync_error");
     56  await history.store("44", "up_to_date");
     57 
     58  const l = await history.list();
     59 
     60  Assert.deepEqual(
     61    l.map(e => e.timestamp),
     62    [44, 42, 41]
     63  );
     64 });
     65 add_task(clear_state);