browser/devtools/framework/test/head.js

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     1 /* This Source Code Form is subject to the terms of the Mozilla Public
     2  * License, v. 2.0. If a copy of the MPL was not distributed with this
     3  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     5 let TargetFactory = gDevTools.TargetFactory;
     7 let tempScope = {};
     8 Components.utils.import("resource://gre/modules/devtools/Console.jsm", tempScope);
     9 let console = tempScope.console;
    10 Components.utils.import("resource://gre/modules/Promise.jsm", tempScope);
    11 let promise = tempScope.Promise;
    13 let {devtools} = Components.utils.import("resource://gre/modules/devtools/Loader.jsm", {});
    14 let TargetFactory = devtools.TargetFactory;
    16 gDevTools.testing = true;
    17 SimpleTest.registerCleanupFunction(() => {
    18   gDevTools.testing = false;
    19 });
    21 /**
    22  * Open a new tab at a URL and call a callback on load
    23  */
    24 function addTab(aURL, aCallback)
    25 {
    26   waitForExplicitFinish();
    28   gBrowser.selectedTab = gBrowser.addTab();
    29   if (aURL != null) {
    30     content.location = aURL;
    31   }
    33   let deferred = promise.defer();
    35   let tab = gBrowser.selectedTab;
    36   let target = TargetFactory.forTab(gBrowser.selectedTab);
    37   let browser = gBrowser.getBrowserForTab(tab);
    39   function onTabLoad() {
    40     browser.removeEventListener("load", onTabLoad, true);
    42     if (aCallback != null) {
    43       aCallback(browser, tab, browser.contentDocument);
    44     }
    46     deferred.resolve({ browser: browser, tab: tab, target: target });
    47   }
    49   browser.addEventListener("load", onTabLoad, true);
    50   return deferred.promise;
    51 }
    53 registerCleanupFunction(function tearDown() {
    54   while (gBrowser.tabs.length > 1) {
    55     gBrowser.removeCurrentTab();
    56   }
    57 });
    59 function synthesizeKeyFromKeyTag(aKeyId, document) {
    60   let key = document.getElementById(aKeyId);
    61   isnot(key, null, "Successfully retrieved the <key> node");
    63   let modifiersAttr = key.getAttribute("modifiers");
    65   let name = null;
    67   if (key.getAttribute("keycode"))
    68     name = key.getAttribute("keycode");
    69   else if (key.getAttribute("key"))
    70     name = key.getAttribute("key");
    72   isnot(name, null, "Successfully retrieved keycode/key");
    74   let modifiers = {
    75     shiftKey: modifiersAttr.match("shift"),
    76     ctrlKey: modifiersAttr.match("ctrl"),
    77     altKey: modifiersAttr.match("alt"),
    78     metaKey: modifiersAttr.match("meta"),
    79     accelKey: modifiersAttr.match("accel")
    80   }
    82   EventUtils.synthesizeKey(name, modifiers);
    83 }

mercurial