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

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 /* Any copyright is dedicated to the Public Domain.
     2  * http://creativecommons.org/publicdomain/zero/1.0/
     3  */
     5 const TESTROOT = "http://example.com/browser/toolkit/mozapps/extensions/test/xpinstall/";
     7 var tempScope = {};
     8 Components.utils.import("resource://gre/modules/LightweightThemeManager.jsm", tempScope);
     9 var LightweightThemeManager = tempScope.LightweightThemeManager;
    11 function wait_for_notification(aCallback) {
    12   PopupNotifications.panel.addEventListener("popupshown", function() {
    13     PopupNotifications.panel.removeEventListener("popupshown", arguments.callee, false);
    14     aCallback(PopupNotifications.panel);
    15   }, false);
    16 }
    18 var TESTS = [
    19 function test_install_lwtheme() {
    20   is(LightweightThemeManager.currentTheme, null, "Should be no lightweight theme selected");
    22   var pm = Services.perms;
    23   pm.add(makeURI("http://example.com/"), "install", pm.ALLOW_ACTION);
    25   gBrowser.selectedTab = gBrowser.addTab("http://example.com/browser/browser/base/content/test/general/bug592338.html");
    26   gBrowser.selectedBrowser.addEventListener("pageshow", function() {
    27     if (gBrowser.contentDocument.location.href == "about:blank")
    28       return;
    30     gBrowser.selectedBrowser.removeEventListener("pageshow", arguments.callee, false);
    32     executeSoon(function() {
    33       var link = gBrowser.contentDocument.getElementById("theme-install");
    34       EventUtils.synthesizeMouse(link, 2, 2, {}, gBrowser.contentWindow);
    36       is(LightweightThemeManager.currentTheme.id, "test", "Should have installed the test theme");
    38       LightweightThemeManager.currentTheme = null;
    39       gBrowser.removeTab(gBrowser.selectedTab);
    41       Services.perms.remove("example.com", "install");
    43       runNextTest();
    44     });
    45   }, false);
    46 },
    48 function test_lwtheme_switch_theme() {
    49   is(LightweightThemeManager.currentTheme, null, "Should be no lightweight theme selected");
    51   AddonManager.getAddonByID("theme-xpi@tests.mozilla.org", function(aAddon) {
    52     aAddon.userDisabled = false;
    53     ok(aAddon.isActive, "Theme should have immediately enabled");
    54     Services.prefs.setBoolPref("extensions.dss.enabled", false);
    56     var pm = Services.perms;
    57     pm.add(makeURI("http://example.com/"), "install", pm.ALLOW_ACTION);
    59     gBrowser.selectedTab = gBrowser.addTab("http://example.com/browser/browser/base/content/test/general/bug592338.html");
    60     gBrowser.selectedBrowser.addEventListener("pageshow", function() {
    61       if (gBrowser.contentDocument.location.href == "about:blank")
    62         return;
    64       gBrowser.selectedBrowser.removeEventListener("pageshow", arguments.callee, false);
    66       executeSoon(function() {
    67         var link = gBrowser.contentDocument.getElementById("theme-install");
    68         wait_for_notification(function(aPanel) {
    69           is(LightweightThemeManager.currentTheme, null, "Should not have installed the test lwtheme");
    70           ok(aAddon.isActive, "Test theme should still be active");
    72           let notification = aPanel.childNodes[0];
    73           is(notification.button.label, "Restart Now", "Should have seen the right button");
    75           ok(aAddon.userDisabled, "Should be waiting to disable the test theme");
    76           aAddon.userDisabled = false;
    77           Services.prefs.setBoolPref("extensions.dss.enabled", true);
    79           gBrowser.removeTab(gBrowser.selectedTab);
    81           Services.perms.remove("example.com", "install");
    83           runNextTest();
    84         });
    85         EventUtils.synthesizeMouse(link, 2, 2, {}, gBrowser.contentWindow);
    86       });
    87     }, false);
    88   });
    89 }
    90 ];
    92 function runNextTest() {
    93   AddonManager.getAllInstalls(function(aInstalls) {
    94     is(aInstalls.length, 0, "Should be no active installs");
    96     if (TESTS.length == 0) {
    97       AddonManager.getAddonByID("theme-xpi@tests.mozilla.org", function(aAddon) {
    98         aAddon.uninstall();
   100         Services.prefs.setBoolPref("extensions.logging.enabled", false);
   101         Services.prefs.setBoolPref("extensions.dss.enabled", false);
   103         finish();
   104       });
   105       return;
   106     }
   108     info("Running " + TESTS[0].name);
   109     TESTS.shift()();
   110   });
   111 };
   113 function test() {
   114   waitForExplicitFinish();
   116   Services.prefs.setBoolPref("extensions.logging.enabled", true);
   118   AddonManager.getInstallForURL(TESTROOT + "theme.xpi", function(aInstall) {
   119     aInstall.addListener({
   120       onInstallEnded: function(aInstall, aAddon) {
   121         AddonManager.getAddonByID("theme-xpi@tests.mozilla.org", function(aAddon) {
   122           isnot(aAddon, null, "Should have installed the test theme.");
   124           // In order to switch themes while the test is running we turn on dynamic
   125           // theme switching. This means the test isn't exactly correct but should
   126           // do some good
   127           Services.prefs.setBoolPref("extensions.dss.enabled", true);
   129           runNextTest();
   130         });
   131       }
   132     });
   134     aInstall.install();
   135   }, "application/x-xpinstall");
   136 }

mercurial