diff --git a/toolkit/mozapps/extensions/XPIProvider.jsm b/toolkit/mozapps/extensions/XPIProvider.jsm index ac24f740a49..8d0330c4eff 100644 --- a/toolkit/mozapps/extensions/XPIProvider.jsm +++ b/toolkit/mozapps/extensions/XPIProvider.jsm @@ -1268,6 +1268,10 @@ var XPIProvider = { var ww = Cc["@mozilla.org/embedcomp/window-watcher;1"]. getService(Ci.nsIWindowWatcher); ww.openWindow(null, URI_EXTENSION_UPDATE_DIALOG, "", features, variant); + + // Ensure any changes to the add-ons list are flushed to disk + XPIDatabase.writeAddonsList([]); + Services.prefs.setBoolPref(PREF_PENDING_OPERATIONS, false); }, /** diff --git a/toolkit/mozapps/extensions/test/addons/test_bug542391_6/install.rdf b/toolkit/mozapps/extensions/test/addons/test_bug542391_6/install.rdf new file mode 100644 index 00000000000..1e7268709d2 --- /dev/null +++ b/toolkit/mozapps/extensions/test/addons/test_bug542391_6/install.rdf @@ -0,0 +1,23 @@ + + + + + + bug542391_6@tests.mozilla.org + 1.0 + http://localhost:4444/data/test_bug542391.rdf + + + + xpcshell@tests.mozilla.org + 1 + 2 + + + + + Bug 542391 Test 6 + + + diff --git a/toolkit/mozapps/extensions/test/xpcshell/data/test_bug542391.rdf b/toolkit/mozapps/extensions/test/xpcshell/data/test_bug542391.rdf new file mode 100644 index 00000000000..b9da133a7af --- /dev/null +++ b/toolkit/mozapps/extensions/test/xpcshell/data/test_bug542391.rdf @@ -0,0 +1,25 @@ + + + + + + + +
  • + + 1.0 + + + xpcshell@tests.mozilla.org + 1 + 3 + + + +
  • +
    +
    +
    + +
    diff --git a/toolkit/mozapps/extensions/test/xpcshell/test_bug542391.js b/toolkit/mozapps/extensions/test/xpcshell/test_bug542391.js index 4275eec78e8..055b10d4ed7 100644 --- a/toolkit/mozapps/extensions/test/xpcshell/test_bug542391.js +++ b/toolkit/mozapps/extensions/test/xpcshell/test_bug542391.js @@ -37,20 +37,23 @@ * ***** END LICENSE BLOCK ***** */ -const Cc = Components.classes; -const Ci = Components.interfaces; -const Cr = Components.results; - const URI_EXTENSION_UPDATE_DIALOG = "chrome://mozapps/content/extensions/update.xul"; const PREF_EM_DISABLED_ADDONS_LIST = "extensions.disabledAddons"; const PREF_EM_SHOW_MISMATCH_UI = "extensions.showMismatchUI"; +// The test extension uses an insecure update url. +Services.prefs.setBoolPref("extensions.checkUpdateSecurity", false); + +do_load_httpd_js(); +var testserver; + const profileDir = gProfD.clone(); profileDir.append("extensions"); var gInstallUpdate = false; +var gCheckUpdates = false; -// This will be called to show the compatiiblity update dialog. +// This will be called to show the compatibility update dialog. var WindowWatcher = { expected: false, arguments: null, @@ -61,14 +64,24 @@ var WindowWatcher = { this.expected = false; this.arguments = arguments.QueryInterface(AM_Ci.nsIVariant); - if (!gInstallUpdate) - return; + var updated = !gCheckUpdates; + if (gCheckUpdates) { + AddonManager.getAddonByID("bug542391_6@tests.mozilla.org", function(a6) { + a6.findUpdates({ + onUpdateFinished: function() { + updated = true; + } + }, AddonManager.UPDATE_WHEN_NEW_APP_INSTALLED); + }); + } - // Simulate installing an update while in the dialog - var installed = false; - installAllFiles([do_get_addon("test_bug542391_3_2")], function() { - installed = true; - }); + var installed = !gInstallUpdate; + if (gInstallUpdate) { + // Simulate installing an update while in the dialog + installAllFiles([do_get_addon("test_bug542391_3_2")], function() { + installed = true; + }); + } // The dialog is meant to be opened modally and the install operation can be // asynchronous, so we must spin an event loop (like the modal window does) @@ -77,7 +90,7 @@ var WindowWatcher = { getService(AM_Ci.nsIThreadManager). mainThread; - while (!installed) + while (!installed || !updated) thr.processNextEvent(false); }, @@ -103,96 +116,160 @@ registrar.registerFactory(Components.ID("{1dfeb90a-2193-45d5-9cb8-864928b2af55}" "Fake Window Watcher", "@mozilla.org/embedcomp/window-watcher;1", WindowWatcherFactory); -function check_state_v1([a1, a2, a3, a4, a5]) { +function check_state_v1([a1, a2, a3, a4, a5, a6]) { do_check_neq(a1, null); do_check_false(a1.appDisabled); do_check_false(a1.userDisabled); + do_check_true(a1.isActive); + do_check_true(isExtensionInAddonsList(profileDir, a1.id)); do_check_neq(a2, null); do_check_false(a2.appDisabled); do_check_true(a2.userDisabled); + do_check_false(a2.isActive); + do_check_false(isExtensionInAddonsList(profileDir, a2.id)); do_check_neq(a3, null); do_check_false(a3.appDisabled); do_check_false(a3.userDisabled); + do_check_true(a3.isActive); + do_check_true(isExtensionInAddonsList(profileDir, a3.id)); do_check_eq(a3.version, "1.0"); do_check_neq(a4, null); do_check_false(a4.appDisabled); do_check_true(a4.userDisabled); + do_check_false(a4.isActive); + do_check_false(isExtensionInAddonsList(profileDir, a4.id)); do_check_neq(a5, null); do_check_false(a5.appDisabled); do_check_false(a5.userDisabled); + do_check_true(a5.isActive); + do_check_true(isExtensionInAddonsList(profileDir, a5.id)); + + do_check_neq(a6, null); + do_check_false(a6.appDisabled); + do_check_false(a6.userDisabled); + do_check_true(a6.isActive); + do_check_true(isExtensionInAddonsList(profileDir, a6.id)); } -function check_state_v2([a1, a2, a3, a4, a5]) { +function check_state_v2([a1, a2, a3, a4, a5, a6]) { do_check_neq(a1, null); do_check_true(a1.appDisabled); do_check_false(a1.userDisabled); + do_check_false(a1.isActive); + do_check_false(isExtensionInAddonsList(profileDir, a1.id)); do_check_neq(a2, null); do_check_false(a2.appDisabled); do_check_true(a2.userDisabled); + do_check_false(a2.isActive); + do_check_false(isExtensionInAddonsList(profileDir, a2.id)); do_check_neq(a3, null); do_check_false(a3.appDisabled); do_check_false(a3.userDisabled); + do_check_true(a3.isActive); + do_check_true(isExtensionInAddonsList(profileDir, a3.id)); do_check_eq(a3.version, "1.0"); do_check_neq(a4, null); do_check_false(a4.appDisabled); do_check_true(a4.userDisabled); + do_check_false(a4.isActive); + do_check_false(isExtensionInAddonsList(profileDir, a4.id)); do_check_neq(a5, null); do_check_false(a5.appDisabled); do_check_false(a5.userDisabled); + do_check_true(a5.isActive); + do_check_true(isExtensionInAddonsList(profileDir, a5.id)); + + do_check_neq(a6, null); + do_check_false(a6.appDisabled); + do_check_false(a6.userDisabled); + do_check_true(a6.isActive); + do_check_true(isExtensionInAddonsList(profileDir, a6.id)); } -function check_state_v3([a1, a2, a3, a4, a5]) { +function check_state_v3([a1, a2, a3, a4, a5, a6]) { do_check_neq(a1, null); do_check_true(a1.appDisabled); do_check_false(a1.userDisabled); + do_check_false(a1.isActive); + do_check_false(isExtensionInAddonsList(profileDir, a1.id)); do_check_neq(a2, null); do_check_true(a2.appDisabled); do_check_true(a2.userDisabled); + do_check_false(a2.isActive); + do_check_false(isExtensionInAddonsList(profileDir, a2.id)); do_check_neq(a3, null); do_check_true(a3.appDisabled); do_check_false(a3.userDisabled); + do_check_false(a3.isActive); + do_check_false(isExtensionInAddonsList(profileDir, a3.id)); do_check_eq(a3.version, "1.0"); do_check_neq(a4, null); do_check_false(a4.appDisabled); do_check_true(a4.userDisabled); + do_check_false(a4.isActive); + do_check_false(isExtensionInAddonsList(profileDir, a4.id)); do_check_neq(a5, null); do_check_false(a5.appDisabled); do_check_false(a5.userDisabled); + do_check_true(a5.isActive); + do_check_true(isExtensionInAddonsList(profileDir, a5.id)); + + do_check_neq(a6, null); + do_check_false(a6.appDisabled); + do_check_false(a6.userDisabled); + do_check_true(a6.isActive); + do_check_true(isExtensionInAddonsList(profileDir, a6.id)); } -function check_state_v3_2([a1, a2, a3, a4, a5]) { +function check_state_v3_2([a1, a2, a3, a4, a5, a6]) { do_check_neq(a1, null); do_check_true(a1.appDisabled); do_check_false(a1.userDisabled); + do_check_false(a1.isActive); + do_check_false(isExtensionInAddonsList(profileDir, a1.id)); do_check_neq(a2, null); do_check_true(a2.appDisabled); do_check_true(a2.userDisabled); + do_check_false(a2.isActive); + do_check_false(isExtensionInAddonsList(profileDir, a2.id)); do_check_neq(a3, null); do_check_false(a3.appDisabled); do_check_false(a3.userDisabled); + do_check_true(a3.isActive); + do_check_true(isExtensionInAddonsList(profileDir, a3.id)); do_check_eq(a3.version, "2.0"); do_check_neq(a4, null); do_check_false(a4.appDisabled); do_check_true(a4.userDisabled); + do_check_false(a4.isActive); + do_check_false(isExtensionInAddonsList(profileDir, a4.id)); do_check_neq(a5, null); do_check_false(a5.appDisabled); do_check_false(a5.userDisabled); + do_check_true(a5.isActive); + do_check_true(isExtensionInAddonsList(profileDir, a5.id)); + + do_check_neq(a6, null); + do_check_false(a6.appDisabled); + do_check_false(a6.userDisabled); + do_check_true(a6.isActive); + do_check_true(isExtensionInAddonsList(profileDir, a6.id)); } // Install all the test add-ons, disable two of them and "upgrade" the app to @@ -216,6 +293,12 @@ function run_test() { name: "Test Addon 1", }, profileDir); + // Create and configure the HTTP server. + testserver = new nsHttpServer(); + testserver.registerDirectory("/data/", do_get_file("data")); + testserver.registerDirectory("/addons/", do_get_file("addons")); + testserver.start(4444); + startupManager(); dest.remove(true); @@ -224,7 +307,8 @@ function run_test() { do_get_addon("test_bug542391_2"), do_get_addon("test_bug542391_3_1"), do_get_addon("test_bug542391_4"), - do_get_addon("test_bug542391_5")], function() { + do_get_addon("test_bug542391_5"), + do_get_addon("test_bug542391_6")], function() { restartManager(); @@ -239,7 +323,8 @@ function run_test() { "bug542391_2@tests.mozilla.org", "bug542391_3@tests.mozilla.org", "bug542391_4@tests.mozilla.org", - "bug542391_5@tests.mozilla.org"], + "bug542391_5@tests.mozilla.org", + "bug542391_6@tests.mozilla.org"], function(addons) { check_state_v1(addons); @@ -251,7 +336,8 @@ function run_test() { "bug542391_2@tests.mozilla.org", "bug542391_3@tests.mozilla.org", "bug542391_4@tests.mozilla.org", - "bug542391_5@tests.mozilla.org"], + "bug542391_5@tests.mozilla.org", + "bug542391_6@tests.mozilla.org"], function(addons) { check_state_v2(addons); @@ -262,18 +348,25 @@ function run_test() { }); } +function end_test() { + testserver.stop(do_test_finished); +} + // Upgrade to version 3 which will appDisable two more add-ons. Check that the // 3 already disabled add-ons were passed to the mismatch dialog. function run_test_1() { + gCheckUpdates = true; WindowWatcher.expected = true; restartManager("3"); do_check_false(WindowWatcher.expected); + gCheckUpdates = false; AddonManager.getAddonsByIDs(["bug542391_1@tests.mozilla.org", "bug542391_2@tests.mozilla.org", "bug542391_3@tests.mozilla.org", "bug542391_4@tests.mozilla.org", - "bug542391_5@tests.mozilla.org"], + "bug542391_5@tests.mozilla.org", + "bug542391_6@tests.mozilla.org"], function(addons) { check_state_v3(addons); @@ -297,7 +390,8 @@ function run_test_2() { "bug542391_2@tests.mozilla.org", "bug542391_3@tests.mozilla.org", "bug542391_4@tests.mozilla.org", - "bug542391_5@tests.mozilla.org"], + "bug542391_5@tests.mozilla.org", + "bug542391_6@tests.mozilla.org"], function(addons) { check_state_v2(addons); @@ -321,7 +415,8 @@ function run_test_3() { "bug542391_2@tests.mozilla.org", "bug542391_3@tests.mozilla.org", "bug542391_4@tests.mozilla.org", - "bug542391_5@tests.mozilla.org"], + "bug542391_5@tests.mozilla.org", + "bug542391_6@tests.mozilla.org"], function(addons) { check_state_v3(addons); @@ -347,7 +442,8 @@ function run_test_4() { "bug542391_2@tests.mozilla.org", "bug542391_3@tests.mozilla.org", "bug542391_4@tests.mozilla.org", - "bug542391_5@tests.mozilla.org"], + "bug542391_5@tests.mozilla.org", + "bug542391_6@tests.mozilla.org"], function(addons) { check_state_v2(addons); @@ -371,12 +467,14 @@ function run_test_5() { WindowWatcher.expected = true; restartManager("3"); do_check_false(WindowWatcher.expected); + gInstallUpdate = false; AddonManager.getAddonsByIDs(["bug542391_1@tests.mozilla.org", "bug542391_2@tests.mozilla.org", "bug542391_3@tests.mozilla.org", "bug542391_4@tests.mozilla.org", - "bug542391_5@tests.mozilla.org"], + "bug542391_5@tests.mozilla.org", + "bug542391_6@tests.mozilla.org"], function(addons) { check_state_v3_2(addons);