From 554ec1a33f0eafe6bf87dd98738b735324529517 Mon Sep 17 00:00:00 2001 From: Mark Banner Date: Wed, 12 Oct 2016 16:08:55 +0100 Subject: [PATCH] Bug 1309589 - Cleanup old loop.* preferences in profiles after Firefox Hello removal. r=mikedeboer MozReview-Commit-ID: KNOJzUL7hRv --HG-- extra : rebase_source : 2a36dd1ffe41e7b673ee4dc514a74c57c4b85390 --- browser/components/nsBrowserGlue.js | 7 +++- browser/components/tests/unit/head.js | 9 ++++++ ...test_browserGlue_migration_loop_cleanup.js | 32 +++++++++++++++++++ .../tests/unit/test_distribution.js | 8 ----- browser/components/tests/unit/xpcshell.ini | 2 ++ 5 files changed, 49 insertions(+), 9 deletions(-) create mode 100644 browser/components/tests/unit/head.js create mode 100644 browser/components/tests/unit/test_browserGlue_migration_loop_cleanup.js diff --git a/browser/components/nsBrowserGlue.js b/browser/components/nsBrowserGlue.js index f6a9cb3294fa..8974d9c6af00 100644 --- a/browser/components/nsBrowserGlue.js +++ b/browser/components/nsBrowserGlue.js @@ -1779,7 +1779,7 @@ BrowserGlue.prototype = { }, _migrateUI: function BG__migrateUI() { - const UI_VERSION = 40; + const UI_VERSION = 41; const BROWSER_DOCURL = "chrome://browser/content/browser.xul"; let currentUIVersion; @@ -2105,6 +2105,11 @@ BrowserGlue.prototype = { } } + if (currentUIVersion < 41) { + const Preferences = Cu.import("resource://gre/modules/Preferences.jsm", {}).Preferences; + Preferences.resetBranch("loop."); + } + // Update the migration version. Services.prefs.setIntPref("browser.migration.version", UI_VERSION); }, diff --git a/browser/components/tests/unit/head.js b/browser/components/tests/unit/head.js new file mode 100644 index 000000000000..3d4e23452b9b --- /dev/null +++ b/browser/components/tests/unit/head.js @@ -0,0 +1,9 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +const {interfaces: Ci, classes: Cc, results: Cr, utils: Cu} = Components; + +Cu.import("resource://gre/modules/Services.jsm"); + +var gProfD = do_get_profile().QueryInterface(Ci.nsILocalFile); diff --git a/browser/components/tests/unit/test_browserGlue_migration_loop_cleanup.js b/browser/components/tests/unit/test_browserGlue_migration_loop_cleanup.js new file mode 100644 index 000000000000..a68503db302a --- /dev/null +++ b/browser/components/tests/unit/test_browserGlue_migration_loop_cleanup.js @@ -0,0 +1,32 @@ +const UI_VERSION = 41; +const TOPIC_BROWSERGLUE_TEST = "browser-glue-test"; +const TOPICDATA_BROWSERGLUE_TEST = "force-ui-migration"; + +var gBrowserGlue = Cc["@mozilla.org/browser/browserglue;1"] + .getService(Ci.nsIObserver); + +Services.prefs.setIntPref("browser.migration.version", UI_VERSION - 1); + +add_task(function* test_check_cleanup_loop_prefs() { + Services.prefs.setBoolPref("loop.createdRoom", true); + Services.prefs.setBoolPref("loop1.createdRoom", true); + Services.prefs.setBoolPref("loo.createdRoom", true); + + // Simulate a migration. + gBrowserGlue.observe(null, TOPIC_BROWSERGLUE_TEST, TOPICDATA_BROWSERGLUE_TEST); + + Assert.throws(() => Services.prefs.getBoolPref("loop.createdRoom"), + /NS_ERROR_UNEXPECTED/, + "should have cleared old loop preference 'loop.createdRoom'"); + Assert.ok(Services.prefs.getBoolPref("loop1.createdRoom"), + "should have left non-loop pref 'loop1.createdRoom' untouched"); + Assert.ok(Services.prefs.getBoolPref("loo.createdRoom"), + "should have left non-loop pref 'loo.createdRoom' untouched"); +}); + +do_register_cleanup(() => { + Services.prefs.clearUserPref("browser.migration.version"); + Services.prefs.clearUserPref("loop.createdRoom"); + Services.prefs.clearUserPref("loop1.createdRoom"); + Services.prefs.clearUserPref("loo.createdRoom"); +}); diff --git a/browser/components/tests/unit/test_distribution.js b/browser/components/tests/unit/test_distribution.js index fd01989239b7..75648298d12f 100644 --- a/browser/components/tests/unit/test_distribution.js +++ b/browser/components/tests/unit/test_distribution.js @@ -5,12 +5,6 @@ * Tests that preferences are properly set by distribution.ini */ -var Ci = Components.interfaces; -var Cc = Components.classes; -var Cr = Components.results; -var Cu = Components.utils; - -Cu.import("resource://gre/modules/Services.jsm"); Cu.import("resource://gre/modules/LoadContextInfo.jsm"); // Import common head. @@ -31,8 +25,6 @@ const TOPIC_BROWSERGLUE_TEST = "browser-glue-test"; function installDistributionEngine() { const XRE_APP_DISTRIBUTION_DIR = "XREAppDist"; - const gProfD = do_get_profile().QueryInterface(Ci.nsILocalFile); - let dir = gProfD.clone(); dir.append("distribution"); let distDir = dir.clone(); diff --git a/browser/components/tests/unit/xpcshell.ini b/browser/components/tests/unit/xpcshell.ini index 28802bacb778..2e2f4b1df8f9 100644 --- a/browser/components/tests/unit/xpcshell.ini +++ b/browser/components/tests/unit/xpcshell.ini @@ -1,4 +1,5 @@ [DEFAULT] +head = head.js firefox-appdir = browser skip-if = toolkit == 'android' || toolkit == 'gonk' support-files = @@ -6,3 +7,4 @@ support-files = data/engine-de-DE.xml [test_distribution.js] +[test_browserGlue_migration_loop_cleanup.js]