browser/base/content/test/general/browser_bug592338.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/browser/base/content/test/general/browser_bug592338.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,136 @@
     1.4 +/* Any copyright is dedicated to the Public Domain.
     1.5 + * http://creativecommons.org/publicdomain/zero/1.0/
     1.6 + */
     1.7 +
     1.8 +const TESTROOT = "http://example.com/browser/toolkit/mozapps/extensions/test/xpinstall/";
     1.9 +
    1.10 +var tempScope = {};
    1.11 +Components.utils.import("resource://gre/modules/LightweightThemeManager.jsm", tempScope);
    1.12 +var LightweightThemeManager = tempScope.LightweightThemeManager;
    1.13 +
    1.14 +function wait_for_notification(aCallback) {
    1.15 +  PopupNotifications.panel.addEventListener("popupshown", function() {
    1.16 +    PopupNotifications.panel.removeEventListener("popupshown", arguments.callee, false);
    1.17 +    aCallback(PopupNotifications.panel);
    1.18 +  }, false);
    1.19 +}
    1.20 +
    1.21 +var TESTS = [
    1.22 +function test_install_lwtheme() {
    1.23 +  is(LightweightThemeManager.currentTheme, null, "Should be no lightweight theme selected");
    1.24 +
    1.25 +  var pm = Services.perms;
    1.26 +  pm.add(makeURI("http://example.com/"), "install", pm.ALLOW_ACTION);
    1.27 +
    1.28 +  gBrowser.selectedTab = gBrowser.addTab("http://example.com/browser/browser/base/content/test/general/bug592338.html");
    1.29 +  gBrowser.selectedBrowser.addEventListener("pageshow", function() {
    1.30 +    if (gBrowser.contentDocument.location.href == "about:blank")
    1.31 +      return;
    1.32 +
    1.33 +    gBrowser.selectedBrowser.removeEventListener("pageshow", arguments.callee, false);
    1.34 +
    1.35 +    executeSoon(function() {
    1.36 +      var link = gBrowser.contentDocument.getElementById("theme-install");
    1.37 +      EventUtils.synthesizeMouse(link, 2, 2, {}, gBrowser.contentWindow);
    1.38 +
    1.39 +      is(LightweightThemeManager.currentTheme.id, "test", "Should have installed the test theme");
    1.40 +
    1.41 +      LightweightThemeManager.currentTheme = null;
    1.42 +      gBrowser.removeTab(gBrowser.selectedTab);
    1.43 +
    1.44 +      Services.perms.remove("example.com", "install");
    1.45 +
    1.46 +      runNextTest();
    1.47 +    });
    1.48 +  }, false);
    1.49 +},
    1.50 +
    1.51 +function test_lwtheme_switch_theme() {
    1.52 +  is(LightweightThemeManager.currentTheme, null, "Should be no lightweight theme selected");
    1.53 +
    1.54 +  AddonManager.getAddonByID("theme-xpi@tests.mozilla.org", function(aAddon) {
    1.55 +    aAddon.userDisabled = false;
    1.56 +    ok(aAddon.isActive, "Theme should have immediately enabled");
    1.57 +    Services.prefs.setBoolPref("extensions.dss.enabled", false);
    1.58 +
    1.59 +    var pm = Services.perms;
    1.60 +    pm.add(makeURI("http://example.com/"), "install", pm.ALLOW_ACTION);
    1.61 +
    1.62 +    gBrowser.selectedTab = gBrowser.addTab("http://example.com/browser/browser/base/content/test/general/bug592338.html");
    1.63 +    gBrowser.selectedBrowser.addEventListener("pageshow", function() {
    1.64 +      if (gBrowser.contentDocument.location.href == "about:blank")
    1.65 +        return;
    1.66 +
    1.67 +      gBrowser.selectedBrowser.removeEventListener("pageshow", arguments.callee, false);
    1.68 +
    1.69 +      executeSoon(function() {
    1.70 +        var link = gBrowser.contentDocument.getElementById("theme-install");
    1.71 +        wait_for_notification(function(aPanel) {
    1.72 +          is(LightweightThemeManager.currentTheme, null, "Should not have installed the test lwtheme");
    1.73 +          ok(aAddon.isActive, "Test theme should still be active");
    1.74 +
    1.75 +          let notification = aPanel.childNodes[0];
    1.76 +          is(notification.button.label, "Restart Now", "Should have seen the right button");
    1.77 +
    1.78 +          ok(aAddon.userDisabled, "Should be waiting to disable the test theme");
    1.79 +          aAddon.userDisabled = false;
    1.80 +          Services.prefs.setBoolPref("extensions.dss.enabled", true);
    1.81 +
    1.82 +          gBrowser.removeTab(gBrowser.selectedTab);
    1.83 +
    1.84 +          Services.perms.remove("example.com", "install");
    1.85 +
    1.86 +          runNextTest();
    1.87 +        });
    1.88 +        EventUtils.synthesizeMouse(link, 2, 2, {}, gBrowser.contentWindow);
    1.89 +      });
    1.90 +    }, false);
    1.91 +  });
    1.92 +}
    1.93 +];
    1.94 +
    1.95 +function runNextTest() {
    1.96 +  AddonManager.getAllInstalls(function(aInstalls) {
    1.97 +    is(aInstalls.length, 0, "Should be no active installs");
    1.98 +
    1.99 +    if (TESTS.length == 0) {
   1.100 +      AddonManager.getAddonByID("theme-xpi@tests.mozilla.org", function(aAddon) {
   1.101 +        aAddon.uninstall();
   1.102 +
   1.103 +        Services.prefs.setBoolPref("extensions.logging.enabled", false);
   1.104 +        Services.prefs.setBoolPref("extensions.dss.enabled", false);
   1.105 +
   1.106 +        finish();
   1.107 +      });
   1.108 +      return;
   1.109 +    }
   1.110 +
   1.111 +    info("Running " + TESTS[0].name);
   1.112 +    TESTS.shift()();
   1.113 +  });
   1.114 +};
   1.115 +
   1.116 +function test() {
   1.117 +  waitForExplicitFinish();
   1.118 +
   1.119 +  Services.prefs.setBoolPref("extensions.logging.enabled", true);
   1.120 +
   1.121 +  AddonManager.getInstallForURL(TESTROOT + "theme.xpi", function(aInstall) {
   1.122 +    aInstall.addListener({
   1.123 +      onInstallEnded: function(aInstall, aAddon) {
   1.124 +        AddonManager.getAddonByID("theme-xpi@tests.mozilla.org", function(aAddon) {
   1.125 +          isnot(aAddon, null, "Should have installed the test theme.");
   1.126 +
   1.127 +          // In order to switch themes while the test is running we turn on dynamic
   1.128 +          // theme switching. This means the test isn't exactly correct but should
   1.129 +          // do some good
   1.130 +          Services.prefs.setBoolPref("extensions.dss.enabled", true);
   1.131 +
   1.132 +          runNextTest();
   1.133 +        });
   1.134 +      }
   1.135 +    });
   1.136 +
   1.137 +    aInstall.install();
   1.138 +  }, "application/x-xpinstall");
   1.139 +}

mercurial