tor-browser

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

test_360se_bookmarks.js (2083B)


      1 "use strict";
      2 
      3 const { CustomizableUI } = ChromeUtils.importESModule(
      4  "moz-src:///browser/components/customizableui/CustomizableUI.sys.mjs"
      5 );
      6 
      7 add_task(async function () {
      8  registerFakePath("AppData", do_get_file("AppData/Roaming/"));
      9 
     10  let migrator = await MigrationUtils.getMigrator("chromium-360se");
     11  // Sanity check for the source.
     12  Assert.ok(await migrator.isSourceAvailable());
     13 
     14  let importedToBookmarksToolbar = false;
     15  let itemsSeen = { bookmarks: 0, folders: 0 };
     16 
     17  let listener = events => {
     18    for (let event of events) {
     19      itemsSeen[
     20        event.itemType == PlacesUtils.bookmarks.TYPE_FOLDER
     21          ? "folders"
     22          : "bookmarks"
     23      ]++;
     24      if (event.parentGuid == PlacesUtils.bookmarks.toolbarGuid) {
     25        importedToBookmarksToolbar = true;
     26      }
     27    }
     28  };
     29  PlacesUtils.observers.addListener(["bookmark-added"], listener);
     30  let observerNotified = false;
     31  Services.obs.addObserver((aSubject, aTopic, aData) => {
     32    let [toolbar, visibility] = JSON.parse(aData);
     33    Assert.equal(
     34      toolbar,
     35      CustomizableUI.AREA_BOOKMARKS,
     36      "Notification should be received for bookmarks toolbar"
     37    );
     38    Assert.equal(
     39      visibility,
     40      "true",
     41      "Notification should say to reveal the bookmarks toolbar"
     42    );
     43    observerNotified = true;
     44  }, "browser-set-toolbar-visibility");
     45 
     46  await promiseMigration(migrator, MigrationUtils.resourceTypes.BOOKMARKS, {
     47    id: "Default",
     48  });
     49  PlacesUtils.observers.removeListener(["bookmark-added"], listener);
     50 
     51  // Check the bookmarks have been imported to all the expected parents.
     52  Assert.ok(importedToBookmarksToolbar, "Bookmarks imported in the toolbar");
     53  Assert.equal(itemsSeen.bookmarks, 8, "Should import all bookmarks.");
     54  Assert.equal(itemsSeen.folders, 2, "Should import all folders.");
     55  // Check that the telemetry matches:
     56  Assert.equal(
     57    MigrationUtils._importQuantities.bookmarks,
     58    itemsSeen.bookmarks + itemsSeen.folders,
     59    "Telemetry reporting correct."
     60  );
     61  Assert.ok(observerNotified, "The observer should be notified upon migration");
     62 });