michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. michael@0: */ michael@0: michael@0: const URI_EXTENSION_UPDATE_DIALOG = "chrome://mozapps/content/extensions/update.xul"; michael@0: const PREF_EM_SHOW_MISMATCH_UI = "extensions.showMismatchUI"; michael@0: michael@0: // The test extension uses an insecure update url. michael@0: Services.prefs.setBoolPref("extensions.checkUpdateSecurity", false); michael@0: michael@0: const Cc = Components.classes; michael@0: const Ci = Components.interfaces; michael@0: const Cu = Components.utils; michael@0: const Cr = Components.results; michael@0: michael@0: Cu.import("resource://testing-common/httpd.js"); michael@0: var testserver; michael@0: michael@0: const profileDir = gProfD.clone(); michael@0: profileDir.append("extensions"); michael@0: michael@0: var gInstallUpdate = false; michael@0: var gCheckUpdates = false; michael@0: michael@0: // This will be called to show the compatibility update dialog. michael@0: var WindowWatcher = { michael@0: expected: false, michael@0: arguments: null, michael@0: michael@0: openWindow: function(parent, url, name, features, arguments) { michael@0: do_check_true(Services.startup.interrupted); michael@0: do_check_eq(url, URI_EXTENSION_UPDATE_DIALOG); michael@0: do_check_true(this.expected); michael@0: this.expected = false; michael@0: this.arguments = arguments.QueryInterface(AM_Ci.nsIVariant); michael@0: michael@0: var updated = !gCheckUpdates; michael@0: if (gCheckUpdates) { michael@0: AddonManager.getAddonByID("bug542391_6@tests.mozilla.org", function(a6) { michael@0: a6.findUpdates({ michael@0: onUpdateFinished: function() { michael@0: AddonManagerPrivate.removeStartupChange("disabled", "bug542391_6@tests.mozilla.org"); michael@0: updated = true; michael@0: } michael@0: }, AddonManager.UPDATE_WHEN_NEW_APP_INSTALLED); michael@0: }); michael@0: } michael@0: michael@0: var installed = !gInstallUpdate; michael@0: if (gInstallUpdate) { michael@0: // Simulate installing an update while in the dialog michael@0: installAllFiles([do_get_addon("test_bug542391_3_2")], function() { michael@0: AddonManagerPrivate.removeStartupChange("disabled", "bug542391_3@tests.mozilla.org"); michael@0: AddonManagerPrivate.addStartupChange("updated", "bug542391_3@tests.mozilla.org"); michael@0: installed = true; michael@0: }); michael@0: } michael@0: michael@0: // The dialog is meant to be opened modally and the install operation can be michael@0: // asynchronous, so we must spin an event loop (like the modal window does) michael@0: // until the install is complete michael@0: let thr = AM_Cc["@mozilla.org/thread-manager;1"]. michael@0: getService(AM_Ci.nsIThreadManager). michael@0: mainThread; michael@0: michael@0: while (!installed || !updated) michael@0: thr.processNextEvent(false); michael@0: }, michael@0: michael@0: QueryInterface: function(iid) { michael@0: if (iid.equals(Ci.nsIWindowWatcher) michael@0: || iid.equals(Ci.nsISupports)) michael@0: return this; michael@0: michael@0: throw Cr.NS_ERROR_NO_INTERFACE; michael@0: } michael@0: } michael@0: michael@0: var WindowWatcherFactory = { michael@0: createInstance: function createInstance(outer, iid) { michael@0: if (outer != null) michael@0: throw Components.results.NS_ERROR_NO_AGGREGATION; michael@0: return WindowWatcher.QueryInterface(iid); michael@0: } michael@0: }; michael@0: michael@0: var registrar = Components.manager.QueryInterface(Components.interfaces.nsIComponentRegistrar); michael@0: registrar.registerFactory(Components.ID("{1dfeb90a-2193-45d5-9cb8-864928b2af55}"), michael@0: "Fake Window Watcher", michael@0: "@mozilla.org/embedcomp/window-watcher;1", WindowWatcherFactory); michael@0: michael@0: function check_state_v1([a1, a2, a3, a4, a5, a6]) { michael@0: do_check_neq(a1, null); michael@0: do_check_false(a1.appDisabled); michael@0: do_check_false(a1.userDisabled); michael@0: do_check_true(a1.isActive); michael@0: do_check_true(isExtensionInAddonsList(profileDir, a1.id)); michael@0: michael@0: do_check_neq(a2, null); michael@0: do_check_false(a2.appDisabled); michael@0: do_check_true(a2.userDisabled); michael@0: do_check_false(a2.isActive); michael@0: do_check_false(isExtensionInAddonsList(profileDir, a2.id)); michael@0: michael@0: do_check_neq(a3, null); michael@0: do_check_false(a3.appDisabled); michael@0: do_check_false(a3.userDisabled); michael@0: do_check_true(a3.isActive); michael@0: do_check_true(isExtensionInAddonsList(profileDir, a3.id)); michael@0: do_check_eq(a3.version, "1.0"); michael@0: michael@0: do_check_neq(a4, null); michael@0: do_check_false(a4.appDisabled); michael@0: do_check_true(a4.userDisabled); michael@0: do_check_false(a4.isActive); michael@0: do_check_false(isExtensionInAddonsList(profileDir, a4.id)); michael@0: michael@0: do_check_neq(a5, null); michael@0: do_check_false(a5.appDisabled); michael@0: do_check_false(a5.userDisabled); michael@0: do_check_true(a5.isActive); michael@0: do_check_true(isExtensionInAddonsList(profileDir, a5.id)); michael@0: michael@0: do_check_neq(a6, null); michael@0: do_check_false(a6.appDisabled); michael@0: do_check_false(a6.userDisabled); michael@0: do_check_true(a6.isActive); michael@0: do_check_true(isExtensionInAddonsList(profileDir, a6.id)); michael@0: } michael@0: michael@0: function check_state_v1_2([a1, a2, a3, a4, a5, a6]) { michael@0: do_check_neq(a1, null); michael@0: do_check_false(a1.appDisabled); michael@0: do_check_false(a1.userDisabled); michael@0: do_check_true(a1.isActive); michael@0: do_check_true(isExtensionInAddonsList(profileDir, a1.id)); michael@0: michael@0: do_check_neq(a2, null); michael@0: do_check_false(a2.appDisabled); michael@0: do_check_true(a2.userDisabled); michael@0: do_check_false(a2.isActive); michael@0: do_check_false(isExtensionInAddonsList(profileDir, a2.id)); michael@0: michael@0: do_check_neq(a3, null); michael@0: do_check_true(a3.appDisabled); michael@0: do_check_false(a3.userDisabled); michael@0: do_check_false(a3.isActive); michael@0: do_check_false(isExtensionInAddonsList(profileDir, a3.id)); michael@0: do_check_eq(a3.version, "2.0"); michael@0: michael@0: do_check_neq(a4, null); michael@0: do_check_false(a4.appDisabled); michael@0: do_check_true(a4.userDisabled); michael@0: do_check_false(a4.isActive); michael@0: do_check_false(isExtensionInAddonsList(profileDir, a4.id)); michael@0: michael@0: do_check_neq(a5, null); michael@0: do_check_false(a5.appDisabled); michael@0: do_check_false(a5.userDisabled); michael@0: do_check_true(a5.isActive); michael@0: do_check_true(isExtensionInAddonsList(profileDir, a5.id)); michael@0: michael@0: do_check_neq(a6, null); michael@0: do_check_false(a6.appDisabled); michael@0: do_check_false(a6.userDisabled); michael@0: do_check_true(a6.isActive); michael@0: do_check_true(isExtensionInAddonsList(profileDir, a6.id)); michael@0: } michael@0: michael@0: function check_state_v2([a1, a2, a3, a4, a5, a6]) { michael@0: do_check_neq(a1, null); michael@0: do_check_true(a1.appDisabled); michael@0: do_check_false(a1.userDisabled); michael@0: do_check_false(a1.isActive); michael@0: do_check_false(isExtensionInAddonsList(profileDir, a1.id)); michael@0: michael@0: do_check_neq(a2, null); michael@0: do_check_false(a2.appDisabled); michael@0: do_check_true(a2.userDisabled); michael@0: do_check_false(a2.isActive); michael@0: do_check_false(isExtensionInAddonsList(profileDir, a2.id)); michael@0: michael@0: do_check_neq(a3, null); michael@0: do_check_false(a3.appDisabled); michael@0: do_check_false(a3.userDisabled); michael@0: do_check_true(a3.isActive); michael@0: do_check_true(isExtensionInAddonsList(profileDir, a3.id)); michael@0: do_check_eq(a3.version, "1.0"); michael@0: michael@0: do_check_neq(a4, null); michael@0: do_check_false(a4.appDisabled); michael@0: do_check_true(a4.userDisabled); michael@0: do_check_false(a4.isActive); michael@0: do_check_false(isExtensionInAddonsList(profileDir, a4.id)); michael@0: michael@0: do_check_neq(a5, null); michael@0: do_check_false(a5.appDisabled); michael@0: do_check_false(a5.userDisabled); michael@0: do_check_true(a5.isActive); michael@0: do_check_true(isExtensionInAddonsList(profileDir, a5.id)); michael@0: michael@0: do_check_neq(a6, null); michael@0: do_check_false(a6.appDisabled); michael@0: do_check_false(a6.userDisabled); michael@0: do_check_true(a6.isActive); michael@0: do_check_true(isExtensionInAddonsList(profileDir, a6.id)); michael@0: } michael@0: michael@0: function check_state_v3([a1, a2, a3, a4, a5, a6]) { michael@0: do_check_neq(a1, null); michael@0: do_check_true(a1.appDisabled); michael@0: do_check_false(a1.userDisabled); michael@0: do_check_false(a1.isActive); michael@0: do_check_false(isExtensionInAddonsList(profileDir, a1.id)); michael@0: michael@0: do_check_neq(a2, null); michael@0: do_check_true(a2.appDisabled); michael@0: do_check_true(a2.userDisabled); michael@0: do_check_false(a2.isActive); michael@0: do_check_false(isExtensionInAddonsList(profileDir, a2.id)); michael@0: michael@0: do_check_neq(a3, null); michael@0: do_check_true(a3.appDisabled); michael@0: do_check_false(a3.userDisabled); michael@0: do_check_false(a3.isActive); michael@0: do_check_false(isExtensionInAddonsList(profileDir, a3.id)); michael@0: do_check_eq(a3.version, "1.0"); michael@0: michael@0: do_check_neq(a4, null); michael@0: do_check_false(a4.appDisabled); michael@0: do_check_true(a4.userDisabled); michael@0: do_check_false(a4.isActive); michael@0: do_check_false(isExtensionInAddonsList(profileDir, a4.id)); michael@0: michael@0: do_check_neq(a5, null); michael@0: do_check_false(a5.appDisabled); michael@0: do_check_false(a5.userDisabled); michael@0: do_check_true(a5.isActive); michael@0: do_check_true(isExtensionInAddonsList(profileDir, a5.id)); michael@0: michael@0: do_check_neq(a6, null); michael@0: do_check_false(a6.appDisabled); michael@0: do_check_false(a6.userDisabled); michael@0: do_check_true(a6.isActive); michael@0: do_check_true(isExtensionInAddonsList(profileDir, a6.id)); michael@0: } michael@0: michael@0: function check_state_v3_2([a1, a2, a3, a4, a5, a6]) { michael@0: do_check_neq(a1, null); michael@0: do_check_true(a1.appDisabled); michael@0: do_check_false(a1.userDisabled); michael@0: do_check_false(a1.isActive); michael@0: do_check_false(isExtensionInAddonsList(profileDir, a1.id)); michael@0: michael@0: do_check_neq(a2, null); michael@0: do_check_true(a2.appDisabled); michael@0: do_check_true(a2.userDisabled); michael@0: do_check_false(a2.isActive); michael@0: do_check_false(isExtensionInAddonsList(profileDir, a2.id)); michael@0: michael@0: do_check_neq(a3, null); michael@0: do_check_false(a3.appDisabled); michael@0: do_check_false(a3.userDisabled); michael@0: do_check_true(a3.isActive); michael@0: do_check_true(isExtensionInAddonsList(profileDir, a3.id)); michael@0: do_check_eq(a3.version, "2.0"); michael@0: michael@0: do_check_neq(a4, null); michael@0: do_check_false(a4.appDisabled); michael@0: do_check_true(a4.userDisabled); michael@0: do_check_false(a4.isActive); michael@0: do_check_false(isExtensionInAddonsList(profileDir, a4.id)); michael@0: michael@0: do_check_neq(a5, null); michael@0: do_check_false(a5.appDisabled); michael@0: do_check_false(a5.userDisabled); michael@0: do_check_true(a5.isActive); michael@0: do_check_true(isExtensionInAddonsList(profileDir, a5.id)); michael@0: michael@0: do_check_neq(a6, null); michael@0: do_check_false(a6.appDisabled); michael@0: do_check_false(a6.userDisabled); michael@0: do_check_true(a6.isActive); michael@0: do_check_true(isExtensionInAddonsList(profileDir, a6.id)); michael@0: } michael@0: michael@0: // Install all the test add-ons, disable two of them and "upgrade" the app to michael@0: // version 2 which will appDisable one. michael@0: function run_test() { michael@0: do_test_pending(); michael@0: createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1"); michael@0: michael@0: Services.prefs.setBoolPref(PREF_EM_SHOW_MISMATCH_UI, true); michael@0: michael@0: // Add an extension to the profile to make sure the dialog doesn't show up michael@0: // on new profiles michael@0: var dest = writeInstallRDFForExtension({ michael@0: id: "addon1@tests.mozilla.org", michael@0: version: "1.0", michael@0: targetApplications: [{ michael@0: id: "xpcshell@tests.mozilla.org", michael@0: minVersion: "1", michael@0: maxVersion: "1" michael@0: }], michael@0: name: "Test Addon 1", michael@0: }, profileDir); michael@0: michael@0: // Create and configure the HTTP server. michael@0: testserver = new HttpServer(); michael@0: testserver.registerDirectory("/data/", do_get_file("data")); michael@0: testserver.registerDirectory("/addons/", do_get_file("addons")); michael@0: testserver.start(4444); michael@0: michael@0: startupManager(); michael@0: michael@0: dest.remove(true); michael@0: michael@0: installAllFiles([do_get_addon("test_bug542391_1"), michael@0: do_get_addon("test_bug542391_2"), michael@0: do_get_addon("test_bug542391_3_1"), michael@0: do_get_addon("test_bug542391_4"), michael@0: do_get_addon("test_bug542391_5"), michael@0: do_get_addon("test_bug542391_6")], function install_and_restart() { michael@0: michael@0: restartManager(); michael@0: check_startup_changes("installed", []); michael@0: check_startup_changes("updated", []); michael@0: check_startup_changes("uninstalled", ["addon1@tests.mozilla.org"]); michael@0: check_startup_changes("disabled", []); michael@0: check_startup_changes("enabled", []); michael@0: michael@0: AddonManager.getAddonsByIDs(["bug542391_2@tests.mozilla.org", michael@0: "bug542391_4@tests.mozilla.org"], michael@0: callback_soon(function disable_and_restart([a2, a4]) { michael@0: do_check_true(a2 != null && a4 != null); michael@0: a2.userDisabled = true; michael@0: a4.userDisabled = true; michael@0: restartManager(); michael@0: check_startup_changes("installed", []); michael@0: check_startup_changes("updated", []); michael@0: check_startup_changes("uninstalled", []); michael@0: check_startup_changes("disabled", []); michael@0: check_startup_changes("enabled", []); michael@0: michael@0: AddonManager.getAddonsByIDs(["bug542391_1@tests.mozilla.org", michael@0: "bug542391_2@tests.mozilla.org", michael@0: "bug542391_3@tests.mozilla.org", michael@0: "bug542391_4@tests.mozilla.org", michael@0: "bug542391_5@tests.mozilla.org", michael@0: "bug542391_6@tests.mozilla.org"], michael@0: callback_soon(function(addons) { michael@0: check_state_v1(addons); michael@0: michael@0: WindowWatcher.expected = true; michael@0: restartManager("2"); michael@0: check_startup_changes("installed", []); michael@0: check_startup_changes("updated", []); michael@0: check_startup_changes("uninstalled", []); michael@0: check_startup_changes("disabled", ["bug542391_1@tests.mozilla.org"]); michael@0: check_startup_changes("enabled", []); michael@0: do_check_false(WindowWatcher.expected); michael@0: michael@0: AddonManager.getAddonsByIDs(["bug542391_1@tests.mozilla.org", michael@0: "bug542391_2@tests.mozilla.org", michael@0: "bug542391_3@tests.mozilla.org", michael@0: "bug542391_4@tests.mozilla.org", michael@0: "bug542391_5@tests.mozilla.org", michael@0: "bug542391_6@tests.mozilla.org"], michael@0: function(addons) { michael@0: check_state_v2(addons); michael@0: michael@0: do_execute_soon(run_test_1); michael@0: }); michael@0: })); michael@0: })); michael@0: }); michael@0: } michael@0: michael@0: function end_test() { michael@0: testserver.stop(do_test_finished); michael@0: } michael@0: michael@0: // Upgrade to version 3 which will appDisable two more add-ons. Check that the michael@0: // 3 already disabled add-ons were passed to the mismatch dialog. michael@0: function run_test_1() { michael@0: gCheckUpdates = true; michael@0: WindowWatcher.expected = true; michael@0: restartManager("3"); michael@0: check_startup_changes("installed", []); michael@0: check_startup_changes("updated", []); michael@0: check_startup_changes("uninstalled", []); michael@0: check_startup_changes("disabled", ["bug542391_3@tests.mozilla.org"]); michael@0: check_startup_changes("enabled", []); michael@0: do_check_false(WindowWatcher.expected); michael@0: gCheckUpdates = false; michael@0: michael@0: AddonManager.getAddonsByIDs(["bug542391_1@tests.mozilla.org", michael@0: "bug542391_2@tests.mozilla.org", michael@0: "bug542391_3@tests.mozilla.org", michael@0: "bug542391_4@tests.mozilla.org", michael@0: "bug542391_5@tests.mozilla.org", michael@0: "bug542391_6@tests.mozilla.org"], michael@0: function(addons) { michael@0: check_state_v3(addons); michael@0: michael@0: do_check_eq(WindowWatcher.arguments.length, 3); michael@0: do_check_true(WindowWatcher.arguments.indexOf("bug542391_1@tests.mozilla.org") >= 0); michael@0: do_check_true(WindowWatcher.arguments.indexOf("bug542391_2@tests.mozilla.org") >= 0); michael@0: do_check_true(WindowWatcher.arguments.indexOf("bug542391_4@tests.mozilla.org") >= 0); michael@0: michael@0: do_execute_soon(run_test_2); michael@0: }); michael@0: } michael@0: michael@0: // Downgrade to version 2 which will remove appDisable from two add-ons and michael@0: // should pass all 4 previously disabled add-ons. michael@0: function run_test_2() { michael@0: WindowWatcher.expected = true; michael@0: restartManager("2"); michael@0: check_startup_changes("installed", []); michael@0: check_startup_changes("updated", []); michael@0: check_startup_changes("uninstalled", []); michael@0: check_startup_changes("disabled", []); michael@0: check_startup_changes("enabled", ["bug542391_3@tests.mozilla.org"]); michael@0: do_check_false(WindowWatcher.expected); michael@0: michael@0: AddonManager.getAddonsByIDs(["bug542391_1@tests.mozilla.org", michael@0: "bug542391_2@tests.mozilla.org", michael@0: "bug542391_3@tests.mozilla.org", michael@0: "bug542391_4@tests.mozilla.org", michael@0: "bug542391_5@tests.mozilla.org", michael@0: "bug542391_6@tests.mozilla.org"], michael@0: function(addons) { michael@0: check_state_v2(addons); michael@0: michael@0: do_check_eq(WindowWatcher.arguments.length, 4); michael@0: do_check_true(WindowWatcher.arguments.indexOf("bug542391_1@tests.mozilla.org") >= 0); michael@0: do_check_true(WindowWatcher.arguments.indexOf("bug542391_2@tests.mozilla.org") >= 0); michael@0: do_check_true(WindowWatcher.arguments.indexOf("bug542391_3@tests.mozilla.org") >= 0); michael@0: do_check_true(WindowWatcher.arguments.indexOf("bug542391_4@tests.mozilla.org") >= 0); michael@0: michael@0: do_execute_soon(run_test_5); michael@0: }); michael@0: } michael@0: michael@0: // Upgrade to version 3 which will appDisable two more add-ons. Check that when michael@0: // the upgrade dialog updates an add-on no restart is necessary michael@0: function run_test_5() { michael@0: Services.prefs.setBoolPref(PREF_EM_SHOW_MISMATCH_UI, true); michael@0: gInstallUpdate = true; michael@0: michael@0: WindowWatcher.expected = true; michael@0: restartManager("3"); michael@0: check_startup_changes("installed", []); michael@0: check_startup_changes("updated", ["bug542391_3@tests.mozilla.org"]); michael@0: check_startup_changes("uninstalled", []); michael@0: check_startup_changes("disabled", []); michael@0: check_startup_changes("enabled", []); michael@0: do_check_false(WindowWatcher.expected); michael@0: gInstallUpdate = false; michael@0: michael@0: AddonManager.getAddonsByIDs(["bug542391_1@tests.mozilla.org", michael@0: "bug542391_2@tests.mozilla.org", michael@0: "bug542391_3@tests.mozilla.org", michael@0: "bug542391_4@tests.mozilla.org", michael@0: "bug542391_5@tests.mozilla.org", michael@0: "bug542391_6@tests.mozilla.org"], michael@0: function(addons) { michael@0: check_state_v3_2(addons); michael@0: michael@0: do_check_eq(WindowWatcher.arguments.length, 3); michael@0: do_check_true(WindowWatcher.arguments.indexOf("bug542391_1@tests.mozilla.org") >= 0); michael@0: do_check_true(WindowWatcher.arguments.indexOf("bug542391_2@tests.mozilla.org") >= 0); michael@0: do_check_true(WindowWatcher.arguments.indexOf("bug542391_4@tests.mozilla.org") >= 0); michael@0: michael@0: do_execute_soon(run_test_6); michael@0: }); michael@0: } michael@0: michael@0: // Downgrade to version 1 which will appEnable all the add-ons michael@0: function run_test_6() { michael@0: WindowWatcher.expected = true; michael@0: restartManager("1"); michael@0: check_startup_changes("installed", []); michael@0: check_startup_changes("updated", []); michael@0: check_startup_changes("uninstalled", []); michael@0: check_startup_changes("disabled", ["bug542391_3@tests.mozilla.org"]); michael@0: check_startup_changes("enabled", ["bug542391_1@tests.mozilla.org"]); michael@0: do_check_false(WindowWatcher.expected); michael@0: michael@0: AddonManager.getAddonsByIDs(["bug542391_1@tests.mozilla.org", michael@0: "bug542391_2@tests.mozilla.org", michael@0: "bug542391_3@tests.mozilla.org", michael@0: "bug542391_4@tests.mozilla.org", michael@0: "bug542391_5@tests.mozilla.org", michael@0: "bug542391_6@tests.mozilla.org"], michael@0: function(addons) { michael@0: check_state_v1_2(addons); michael@0: michael@0: end_test(); michael@0: }); michael@0: }