toolkit/mozapps/extensions/test/xpcshell/test_bug596343.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/toolkit/mozapps/extensions/test/xpcshell/test_bug596343.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,79 @@
     1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/.
     1.7 + */
     1.8 +
     1.9 +const URI_EXTENSION_SELECT_DIALOG     = "chrome://mozapps/content/extensions/selectAddons.xul";
    1.10 +const URI_EXTENSION_UPDATE_DIALOG     = "chrome://mozapps/content/extensions/update.xul";
    1.11 +const PREF_EM_SHOW_MISMATCH_UI        = "extensions.showMismatchUI";
    1.12 +const PREF_SHOWN_SELECTION_UI         = "extensions.shownSelectionUI";
    1.13 +
    1.14 +const profileDir = gProfD.clone();
    1.15 +profileDir.append("extensions");
    1.16 +
    1.17 +var gExpectedURL = null;
    1.18 +
    1.19 +// This will be called to show the any update dialog.
    1.20 +var WindowWatcher = {
    1.21 +  openWindow: function(parent, url, name, features, arguments) {
    1.22 +    do_check_eq(url, gExpectedURL);
    1.23 +    gExpectedURL = null;
    1.24 +  },
    1.25 +
    1.26 +  QueryInterface: function(iid) {
    1.27 +    if (iid.equals(AM_Ci.nsIWindowWatcher)
    1.28 +     || iid.equals(AM_Ci.nsISupports))
    1.29 +      return this;
    1.30 +
    1.31 +    throw Components.results.NS_ERROR_NO_INTERFACE;
    1.32 +  }
    1.33 +}
    1.34 +
    1.35 +var WindowWatcherFactory = {
    1.36 +  createInstance: function createInstance(outer, iid) {
    1.37 +    if (outer != null)
    1.38 +      throw Components.results.NS_ERROR_NO_AGGREGATION;
    1.39 +    return WindowWatcher.QueryInterface(iid);
    1.40 +  }
    1.41 +};
    1.42 +
    1.43 +var registrar = Components.manager.QueryInterface(Components.interfaces.nsIComponentRegistrar);
    1.44 +registrar.registerFactory(Components.ID("{1dfeb90a-2193-45d5-9cb8-864928b2af55}"),
    1.45 +                          "Fake Window Watcher",
    1.46 +                          "@mozilla.org/embedcomp/window-watcher;1", WindowWatcherFactory);
    1.47 +
    1.48 +// Tests that the selection UI is displayed when upgrading an existing profile
    1.49 +function run_test() {
    1.50 +  createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1");
    1.51 +
    1.52 +  Services.prefs.setBoolPref(PREF_EM_SHOW_MISMATCH_UI, true);
    1.53 +
    1.54 +  var dest = writeInstallRDFForExtension({
    1.55 +    id: "addon1@tests.mozilla.org",
    1.56 +    version: "1.0",
    1.57 +    targetApplications: [{
    1.58 +      id: "xpcshell@tests.mozilla.org",
    1.59 +      minVersion: "1",
    1.60 +      maxVersion: "1"
    1.61 +    }],
    1.62 +    name: "Test Addon 1",
    1.63 +  }, profileDir);
    1.64 +
    1.65 +  startupManager();
    1.66 +
    1.67 +  // For a new profile it should disable showing the selection UI in the future
    1.68 +  do_check_true(Services.prefs.getBoolPref(PREF_SHOWN_SELECTION_UI));
    1.69 +  Services.prefs.clearUserPref(PREF_SHOWN_SELECTION_UI);
    1.70 +
    1.71 +  gExpectedURL = URI_EXTENSION_SELECT_DIALOG;
    1.72 +  restartManager("2");
    1.73 +
    1.74 +  do_check_true(Services.prefs.getBoolPref(PREF_SHOWN_SELECTION_UI));
    1.75 +  do_check_eq(gExpectedURL, null);
    1.76 +
    1.77 +  gExpectedURL = URI_EXTENSION_UPDATE_DIALOG;
    1.78 +
    1.79 +  restartManager("3");
    1.80 +
    1.81 +  do_check_eq(gExpectedURL, null);
    1.82 +}

mercurial