tor-browser

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

test_browserGlue_migrate.js (2065B)


      1 /* Any copyright is dedicated to the Public Domain.
      2   http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 /**
      5 * Tests that nsBrowserGlue does not overwrite bookmarks imported from the
      6 * migrators.  They usually run before nsBrowserGlue, so if we find any
      7 * bookmark on init, we should not try to import.
      8 */
      9 
     10 function run_test() {
     11  // Create our bookmarks.html from bookmarks.glue.html.
     12  create_bookmarks_html("bookmarks.glue.html");
     13 
     14  // Remove current database file.
     15  clearDB();
     16 
     17  run_next_test();
     18 }
     19 
     20 registerCleanupFunction(remove_bookmarks_html);
     21 
     22 add_task(async function test_migrate_bookmarks() {
     23  // Initialize Places through the History Service and check that a new
     24  // database has been created.
     25  Assert.equal(
     26    PlacesUtils.history.databaseStatus,
     27    PlacesUtils.history.DATABASE_STATUS_CREATE
     28  );
     29 
     30  // A migrator would run before Places initialization, so mimic
     31  // that behavior adding a bookmark and notifying the migration.
     32  let { PlacesBrowserStartup } = ChromeUtils.importESModule(
     33    "moz-src:///browser/components/places/PlacesBrowserStartup.sys.mjs"
     34  );
     35  PlacesBrowserStartup.willImportDefaultBookmarks();
     36 
     37  await PlacesUtils.bookmarks.insert({
     38    parentGuid: PlacesUtils.bookmarks.menuGuid,
     39    index: PlacesUtils.bookmarks.DEFAULT_INDEX,
     40    type: PlacesUtils.bookmarks.TYPE_BOOKMARK,
     41    url: "http://mozilla.org/",
     42    title: "migrated",
     43  });
     44 
     45  let promise = promiseTopicObserved("places-browser-init-complete");
     46  PlacesBrowserStartup.didImportDefaultBookmarks();
     47  await promise;
     48 
     49  // Check the created bookmark still exists.
     50  let bm = await PlacesUtils.bookmarks.fetch({
     51    parentGuid: PlacesUtils.bookmarks.menuGuid,
     52    index: 0,
     53  });
     54  Assert.equal(bm.title, "migrated");
     55 
     56  // Check that we have not imported any new bookmark.
     57  Assert.ok(
     58    !(await PlacesUtils.bookmarks.fetch({
     59      parentGuid: PlacesUtils.bookmarks.menuGuid,
     60      index: 1,
     61    }))
     62  );
     63 
     64  Assert.ok(
     65    !(await PlacesUtils.bookmarks.fetch({
     66      parentGuid: PlacesUtils.bookmarks.toolbarGuid,
     67      index: 0,
     68    }))
     69  );
     70 });