test_Safari_bookmarks.js (2912B)
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("ULibDir", do_get_file("Library/")); 9 const faviconPath = do_get_file( 10 "Library/Safari/Favicon Cache/favicons.db" 11 ).path; 12 13 let migrator = await MigrationUtils.getMigrator("safari"); 14 // Sanity check for the source. 15 Assert.ok(await migrator.isSourceAvailable()); 16 17 // Wait for the imported bookmarks. We don't check that "From Safari" 18 // folders are created on the toolbar since the profile 19 // we're importing to has less than 3 bookmarks in the destination 20 // so a "From Safari" folder isn't created. 21 let expectedParentGuids = [PlacesUtils.bookmarks.toolbarGuid]; 22 let itemCount = 0; 23 24 let gotFolder = false; 25 let listener = events => { 26 for (let event of events) { 27 itemCount++; 28 if ( 29 event.itemType == PlacesUtils.bookmarks.TYPE_FOLDER && 30 event.title == "Food and Travel" 31 ) { 32 gotFolder = true; 33 } 34 if (expectedParentGuids.length) { 35 let index = expectedParentGuids.indexOf(event.parentGuid); 36 Assert.notEqual(index, -1, "Found expected parent"); 37 expectedParentGuids.splice(index, 1); 38 } 39 } 40 }; 41 PlacesUtils.observers.addListener(["bookmark-added"], listener); 42 let observerNotified = false; 43 Services.obs.addObserver((aSubject, aTopic, aData) => { 44 let [toolbar, visibility] = JSON.parse(aData); 45 Assert.equal( 46 toolbar, 47 CustomizableUI.AREA_BOOKMARKS, 48 "Notification should be received for bookmarks toolbar" 49 ); 50 Assert.equal( 51 visibility, 52 "true", 53 "Notification should say to reveal the bookmarks toolbar" 54 ); 55 observerNotified = true; 56 }, "browser-set-toolbar-visibility"); 57 58 await promiseMigration(migrator, MigrationUtils.resourceTypes.BOOKMARKS); 59 PlacesUtils.observers.removeListener(["bookmark-added"], listener); 60 61 // Check the bookmarks have been imported to all the expected parents. 62 Assert.ok(!expectedParentGuids.length, "No more expected parents"); 63 Assert.ok(gotFolder, "Should have seen the folder get imported"); 64 Assert.equal(itemCount, 14, "Should import all 14 items."); 65 // Check that the telemetry matches: 66 Assert.equal( 67 MigrationUtils._importQuantities.bookmarks, 68 itemCount, 69 "Telemetry reporting correct." 70 ); 71 72 // Check that favicons migrated 73 let faviconURIs = await MigrationUtils.getRowsFromDBWithoutLocks( 74 faviconPath, 75 "Safari Bookmark Favicons", 76 `SELECT I.uuid, I.url AS favicon_url, P.url 77 FROM icon_info I 78 INNER JOIN page_url P ON I.uuid = P.uuid;` 79 ); 80 let pageUrls = Array.from(faviconURIs, row => 81 Services.io.newURI(row.getResultByName("url")) 82 ); 83 await assertFavicons(pageUrls); 84 Assert.ok(observerNotified, "The observer should be notified upon migration"); 85 });