author | Marco Bonardo <mbonardo@mozilla.com> |
Wed, 01 Apr 2015 19:09:26 +0200 | |
changeset 237231 | 79b0d1c565a81ecc0cd4ff21695dc19c3786eded |
parent 237230 | 45af6b8fe218a27d74f207e7cd902404f0230c4f |
child 237232 | 46e43ff8cdb50b3c52d4e6353dc8b02016944d48 |
push id | 57898 |
push user | cbook@mozilla.com |
push date | Thu, 02 Apr 2015 12:14:17 +0000 |
treeherder | mozilla-inbound@63c87250946e [default view] [failures only] |
perfherder | [talos] [build metrics] [platform microbench] (compared to previous push) |
reviewers | ttaubert |
bugs | 1094888 |
milestone | 40.0a1 |
first release with | nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
|
last release without | nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
|
--- a/browser/components/nsBrowserGlue.js +++ b/browser/components/nsBrowserGlue.js @@ -377,16 +377,21 @@ BrowserGlue.prototype = { else if (data == "force-distribution-customization") { this._distributionCustomizer.applyPrefDefaults(); this._distributionCustomizer.applyCustomizations(); // To apply distribution bookmarks use "places-init-complete". } else if (data == "force-places-init") { this._initPlaces(false); } + else if (data == "smart-bookmarks-init") { + this.ensurePlacesDefaultQueriesInitialized().then(() => { + Services.obs.notifyObservers(null, "test-smart-bookmarks-done", null); + }); + } break; case "initial-migration-will-import-default-bookmarks": this._migrationImportsDefaultBookmarks = true; break; case "initial-migration-did-import-default-bookmarks": this._initPlaces(true); break; case "handle-xul-text-link": @@ -1492,17 +1497,17 @@ BrowserGlue.prototype = { // happens during a common startup. // Otherwise, if any kind of import runs, smart bookmarks creation should be // delayed till the import operations has finished. Not doing so would // cause them to be overwritten by the newly imported bookmarks. if (!importBookmarks) { // Now apply distribution customized bookmarks. // This should always run after Places initialization. this._distributionCustomizer.applyBookmarks(); - this.ensurePlacesDefaultQueriesInitialized(); + yield this.ensurePlacesDefaultQueriesInitialized(); } else { // An import operation is about to run. // Don't try to recreate smart bookmarks if autoExportHTML is true or // smart bookmarks are disabled. let smartBookmarksVersion = 0; try { smartBookmarksVersion = Services.prefs.getIntPref("browser.places.smartBookmarksVersion"); @@ -1527,17 +1532,17 @@ BrowserGlue.prototype = { Cu.reportError("Bookmarks.html file could be corrupt. " + e); } try { // Now apply distribution customized bookmarks. // This should always run after Places initialization. this._distributionCustomizer.applyBookmarks(); // Ensure that smart bookmarks are created once the operation is // complete. - this.ensurePlacesDefaultQueriesInitialized(); + yield this.ensurePlacesDefaultQueriesInitialized(); } catch (e) { Cu.reportError(e); } } else { Cu.reportError("Unable to find bookmarks.html file."); } @@ -2036,18 +2041,17 @@ BrowserGlue.prototype = { // ------------------------------ // public nsIBrowserGlue members // ------------------------------ sanitize: function BG_sanitize(aParentWindow) { this._sanitizer.sanitize(aParentWindow); }, - ensurePlacesDefaultQueriesInitialized: - function BG_ensurePlacesDefaultQueriesInitialized() { + ensurePlacesDefaultQueriesInitialized: Task.async(function* () { // This is actual version of the smart bookmarks, must be increased every // time smart bookmarks change. // When adding a new smart bookmark below, its newInVersion property must // be set to the version it has been added in, we will compare its value // to users' smartBookmarksVersion and add new smart bookmarks without // recreating old deleted ones. const SMART_BOOKMARKS_VERSION = 7; const SMART_BOOKMARKS_ANNO = "Places/SmartBookmark"; @@ -2210,17 +2214,17 @@ BrowserGlue.prototype = { } catch(ex) { Components.utils.reportError(ex); } finally { Services.prefs.setIntPref(SMART_BOOKMARKS_PREF, SMART_BOOKMARKS_VERSION); Services.prefs.savePrefFile(null); } - }, + }), // this returns the most recent non-popup browser window getMostRecentBrowserWindow: function BG_getMostRecentBrowserWindow() { return RecentWindow.getMostRecentBrowserWindow(); }, #ifdef MOZ_SERVICES_SYNC /**
--- a/browser/components/nsIBrowserGlue.idl +++ b/browser/components/nsIBrowserGlue.idl @@ -18,30 +18,25 @@ interface nsIDOMWindow; * elegant or stable in the mozilla codebase, but its aim is rather pragmatic: * 1) reducing the performance overhead which affects browser window load; * 2) allow global hooks (e.g. startup and shutdown observers) which survive * browser windows to accomplish browser-related activities, such as shutdown * sanitization (see bug #284086) * */ -[scriptable, uuid(781df699-17dc-4237-b3d7-876ddb7085e3)] +[scriptable, uuid(ea083cb7-6b9d-4695-8b34-2e8f6ce2a860)] interface nsIBrowserGlue : nsISupports { /** * Deletes privacy sensitive data according to user preferences * * @param aParentWindow an optionally null window which is the parent of the * sanitization dialog * */ void sanitize(in nsIDOMWindow aParentWindow); /** - * Add Smart Bookmarks special queries to bookmarks menu and toolbar folder. - */ - void ensurePlacesDefaultQueriesInitialized(); - - /** * Gets the most recent window that's a browser (but not a popup) */ nsIDOMWindow getMostRecentBrowserWindow(); };
--- a/browser/components/places/tests/unit/head_bookmarks.js +++ b/browser/components/places/tests/unit/head_bookmarks.js @@ -85,8 +85,37 @@ let createCorruptDB = Task.async(functio // Create a corrupt database. let dir = yield OS.File.getCurrentDirectory(); let src = OS.Path.join(dir, "corruptDB.sqlite"); yield OS.File.copy(src, dbPath); // Check there's a DB now. Assert.ok((yield OS.File.exists(dbPath)), "should have a DB now"); }); + +/** + * Rebuilds smart bookmarks listening to console output to report any message or + * exception generated. + * + * @return {Promise} + * Resolved when done. + */ +function rebuildSmartBookmarks() { + let consoleListener = { + observe(aMsg) { + do_throw("Got console message: " + aMsg.message); + }, + QueryInterface: XPCOMUtils.generateQI([ Ci.nsIConsoleListener ]), + }; + Services.console.reset(); + Services.console.registerListener(consoleListener); + do_register_cleanup(() => { + try { + Services.console.unregisterListener(consoleListener); + } catch (ex) { /* will likely fail */ } + }); + Cc["@mozilla.org/browser/browserglue;1"] + .getService(Ci.nsIObserver) + .observe(null, "browser-glue-test", "smart-bookmarks-init"); + return promiseTopicObserved("test-smart-bookmarks-done").then(() => { + Services.console.unregisterListener(consoleListener); + }); +}
--- a/browser/components/places/tests/unit/test_421483.js +++ b/browser/components/places/tests/unit/test_421483.js @@ -14,29 +14,29 @@ let gluesvc = Cc["@mozilla.org/browser/b gluesvc.observe(null, "initial-migration-will-import-default-bookmarks", ""); function run_test() { run_next_test(); } add_task(function* smart_bookmarks_disabled() { Services.prefs.setIntPref("browser.places.smartBookmarksVersion", -1); - gluesvc.ensurePlacesDefaultQueriesInitialized(); + yield rebuildSmartBookmarks(); let smartBookmarkItemIds = PlacesUtils.annotations.getItemsWithAnnotation(SMART_BOOKMARKS_ANNO); Assert.equal(smartBookmarkItemIds.length, 0); do_print("check that pref has not been bumped up"); Assert.equal(Services.prefs.getIntPref("browser.places.smartBookmarksVersion"), -1); }); add_task(function* create_smart_bookmarks() { Services.prefs.setIntPref("browser.places.smartBookmarksVersion", 0); - gluesvc.ensurePlacesDefaultQueriesInitialized(); + yield rebuildSmartBookmarks(); let smartBookmarkItemIds = PlacesUtils.annotations.getItemsWithAnnotation(SMART_BOOKMARKS_ANNO); Assert.notEqual(smartBookmarkItemIds.length, 0); do_print("check that pref has been bumped up"); Assert.ok(Services.prefs.getIntPref("browser.places.smartBookmarksVersion") > 0); }); @@ -46,17 +46,17 @@ add_task(function* remove_smart_bookmark PlacesUtils.annotations.getItemsWithAnnotation(SMART_BOOKMARKS_ANNO); let smartBookmarksCount = smartBookmarkItemIds.length; do_print("remove one smart bookmark and restore"); let guid = yield PlacesUtils.promiseItemGuid(smartBookmarkItemIds[0]); yield PlacesUtils.bookmarks.remove(guid); Services.prefs.setIntPref("browser.places.smartBookmarksVersion", 0); - gluesvc.ensurePlacesDefaultQueriesInitialized(); + yield rebuildSmartBookmarks(); smartBookmarkItemIds = PlacesUtils.annotations.getItemsWithAnnotation(SMART_BOOKMARKS_ANNO); Assert.equal(smartBookmarkItemIds.length, smartBookmarksCount); do_print("check that pref has been bumped up"); Assert.ok(Services.prefs.getIntPref("browser.places.smartBookmarksVersion") > 0); }); @@ -83,17 +83,17 @@ add_task(function* move_smart_bookmark_r guid: guid, parentGuid: subfolder.guid, index: PlacesUtils.bookmarks.DEFAULT_INDEX, title: "new title" }); // restore Services.prefs.setIntPref("browser.places.smartBookmarksVersion", 0); - gluesvc.ensurePlacesDefaultQueriesInitialized(); + yield rebuildSmartBookmarks(); smartBookmarkItemIds = PlacesUtils.annotations.getItemsWithAnnotation(SMART_BOOKMARKS_ANNO); Assert.equal(smartBookmarkItemIds.length, smartBookmarksCount); guid = yield PlacesUtils.promiseItemGuid(smartBookmarkItemIds[0]); bm = yield PlacesUtils.bookmarks.fetch(guid); Assert.equal(bm.parentGuid, subfolder.guid);
--- a/browser/components/places/tests/unit/test_browserGlue_smartBookmarks.js +++ b/browser/components/places/tests/unit/test_browserGlue_smartBookmarks.js @@ -30,37 +30,16 @@ function countFolderChildren(aFolderItem let node = rootNode.getChild(i); let title = PlacesUtils.nodeIsSeparator(node) ? "---" : node.title; print("Found child(" + i + "): " + title); } rootNode.containerOpen = false; return cc; } -/** - * Rebuilds smart bookmarks listening to console output to report any message or - * exception generated when calling ensurePlacesDefaultQueriesInitialized(). - */ -function rebuildSmartBookmarks() { - let consoleListener = { - observe: function(aMsg) { - do_throw("Got console message: " + aMsg.message); - }, - - QueryInterface: XPCOMUtils.generateQI([ - Ci.nsIConsoleListener - ]), - }; - Services.console.reset(); - Services.console.registerListener(consoleListener); - Cc["@mozilla.org/browser/browserglue;1"].getService(Ci.nsIBrowserGlue) - .ensurePlacesDefaultQueriesInitialized(); - Services.console.unregisterListener(consoleListener); -} - add_task(function* setup() { // Initialize browserGlue, but remove it's listener to places-init-complete. let bg = Cc["@mozilla.org/browser/browserglue;1"].getService(Ci.nsIObserver); // Initialize Places. PlacesUtils.history; // Wait for Places init notification. @@ -84,17 +63,17 @@ add_task(function* test_version_0() { Assert.ok(yield PlacesUtils.bookmarks.fetch({ parentGuid: PlacesUtils.bookmarks.menuGuid, index: 0 })); // Set preferences. Services.prefs.setIntPref(PREF_SMART_BOOKMARKS_VERSION, 0); - rebuildSmartBookmarks(); + yield rebuildSmartBookmarks(); // Count items. Assert.equal(countFolderChildren(PlacesUtils.toolbarFolderId), SMART_BOOKMARKS_ON_TOOLBAR + DEFAULT_BOOKMARKS_ON_TOOLBAR); Assert.equal(countFolderChildren(PlacesUtils.bookmarksMenuFolderId), SMART_BOOKMARKS_ON_MENU + DEFAULT_BOOKMARKS_ON_MENU); // Check version has been updated. @@ -121,17 +100,17 @@ add_task(function* test_version_change() Assert.equal(countFolderChildren(PlacesUtils.toolbarFolderId), SMART_BOOKMARKS_ON_TOOLBAR + DEFAULT_BOOKMARKS_ON_TOOLBAR); Assert.equal(countFolderChildren(PlacesUtils.bookmarksMenuFolderId), SMART_BOOKMARKS_ON_MENU + DEFAULT_BOOKMARKS_ON_MENU); // Set preferences. Services.prefs.setIntPref(PREF_SMART_BOOKMARKS_VERSION, 1); - rebuildSmartBookmarks(); + yield rebuildSmartBookmarks(); // Count items. Assert.equal(countFolderChildren(PlacesUtils.toolbarFolderId), SMART_BOOKMARKS_ON_TOOLBAR + DEFAULT_BOOKMARKS_ON_TOOLBAR); Assert.equal(countFolderChildren(PlacesUtils.bookmarksMenuFolderId), SMART_BOOKMARKS_ON_MENU + DEFAULT_BOOKMARKS_ON_MENU); // Check smart bookmark has been replaced, itemId has changed. @@ -168,17 +147,17 @@ add_task(function* test_version_change_p index: 1 }); yield checkItemHasAnnotation(bm.guid, SMART_BOOKMARKS_ANNO); let secondItemTitle = bm.title; // Set preferences. Services.prefs.setIntPref(PREF_SMART_BOOKMARKS_VERSION, 1); - rebuildSmartBookmarks(); + yield rebuildSmartBookmarks(); // Count items. Assert.equal(countFolderChildren(PlacesUtils.toolbarFolderId), SMART_BOOKMARKS_ON_TOOLBAR + DEFAULT_BOOKMARKS_ON_TOOLBAR); Assert.equal(countFolderChildren(PlacesUtils.bookmarksMenuFolderId), SMART_BOOKMARKS_ON_MENU + DEFAULT_BOOKMARKS_ON_MENU); // Check smart bookmarks are still in correct position. @@ -235,17 +214,17 @@ add_task(function* test_version_change_p parentGuid: PlacesUtils.bookmarks.menuGuid, index: PlacesUtils.bookmarks.DEFAULT_INDEX }); Assert.equal(bm.guid, bm1.guid); // Set preferences. Services.prefs.setIntPref(PREF_SMART_BOOKMARKS_VERSION, 1); - rebuildSmartBookmarks(); + yield rebuildSmartBookmarks(); // Count items. Assert.equal(countFolderChildren(PlacesUtils.toolbarFolderId), SMART_BOOKMARKS_ON_TOOLBAR + DEFAULT_BOOKMARKS_ON_TOOLBAR); Assert.equal(countFolderChildren(PlacesUtils.bookmarksMenuFolderId), SMART_BOOKMARKS_ON_MENU + DEFAULT_BOOKMARKS_ON_MENU); // Check smart bookmarks are still in correct position. @@ -289,17 +268,17 @@ add_task(function* test_recreation() { Assert.equal(countFolderChildren(PlacesUtils.toolbarFolderId), DEFAULT_BOOKMARKS_ON_TOOLBAR); Assert.equal(countFolderChildren(PlacesUtils.bookmarksMenuFolderId), SMART_BOOKMARKS_ON_MENU + DEFAULT_BOOKMARKS_ON_MENU); // Set preferences. Services.prefs.setIntPref(PREF_SMART_BOOKMARKS_VERSION, 1); - rebuildSmartBookmarks(); + yield rebuildSmartBookmarks(); // Count items. // We should not have recreated the smart bookmark on toolbar. Assert.equal(countFolderChildren(PlacesUtils.toolbarFolderId), DEFAULT_BOOKMARKS_ON_TOOLBAR); Assert.equal(countFolderChildren(PlacesUtils.bookmarksMenuFolderId), SMART_BOOKMARKS_ON_MENU + DEFAULT_BOOKMARKS_ON_MENU); @@ -315,17 +294,17 @@ add_task(function* test_recreation_versi Assert.equal(countFolderChildren(PlacesUtils.toolbarFolderId), DEFAULT_BOOKMARKS_ON_TOOLBAR); Assert.equal(countFolderChildren(PlacesUtils.bookmarksMenuFolderId), SMART_BOOKMARKS_ON_MENU + DEFAULT_BOOKMARKS_ON_MENU); // Set preferences. Services.prefs.setIntPref(PREF_SMART_BOOKMARKS_VERSION, 0); - rebuildSmartBookmarks(); + yield rebuildSmartBookmarks(); // Count items. // We should not have recreated the smart bookmark on toolbar. Assert.equal(countFolderChildren(PlacesUtils.toolbarFolderId), SMART_BOOKMARKS_ON_TOOLBAR + DEFAULT_BOOKMARKS_ON_TOOLBAR); Assert.equal(countFolderChildren(PlacesUtils.bookmarksMenuFolderId), SMART_BOOKMARKS_ON_MENU + DEFAULT_BOOKMARKS_ON_MENU);