browser/devtools/responsivedesign/test/head.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/ */
     4 "use strict";
     6 let {devtools} = Cu.import("resource:///modules/devtools/gDevTools.jsm", {});
     7 let TargetFactory = devtools.TargetFactory;
     9 // Import the GCLI test helper
    10 let testDir = gTestPath.substr(0, gTestPath.lastIndexOf("/"));
    11 Services.scriptloader.loadSubScript(testDir + "../../../commandline/test/helpers.js", this);
    13 gDevTools.testing = true;
    14 SimpleTest.registerCleanupFunction(() => {
    15   gDevTools.testing = false;
    16 });
    18 /**
    19  * Open the toolbox, with the inspector tool visible.
    20  * @return a promise that resolves when the inspector is ready
    21  */
    22 let openInspector = Task.async(function*() {
    23   info("Opening the inspector");
    24   let target = TargetFactory.forTab(gBrowser.selectedTab);
    26   let inspector, toolbox;
    28   // Checking if the toolbox and the inspector are already loaded
    29   // The inspector-updated event should only be waited for if the inspector
    30   // isn't loaded yet
    31   toolbox = gDevTools.getToolbox(target);
    32   if (toolbox) {
    33     inspector = toolbox.getPanel("inspector");
    34     if (inspector) {
    35       info("Toolbox and inspector already open");
    36       return {
    37         toolbox: toolbox,
    38         inspector: inspector
    39       };
    40     }
    41   }
    43   info("Opening the toolbox");
    44   toolbox = yield gDevTools.showToolbox(target, "inspector");
    45   yield waitForToolboxFrameFocus(toolbox);
    46   inspector = toolbox.getPanel("inspector");
    48   info("Waiting for the inspector to update");
    49   yield inspector.once("inspector-updated");
    51   return {
    52     toolbox: toolbox,
    53     inspector: inspector
    54   };
    55 });
    57 /**
    58  * Wait for the toolbox frame to receive focus after it loads
    59  * @param {Toolbox} toolbox
    60  * @return a promise that resolves when focus has been received
    61  */
    62 function waitForToolboxFrameFocus(toolbox) {
    63   info("Making sure that the toolbox's frame is focused");
    64   let def = promise.defer();
    65   let win = toolbox.frame.contentWindow;
    66   waitForFocus(def.resolve, win);
    67   return def.promise;
    68 }
    70 /**
    71  * Open the toolbox, with the inspector tool visible, and the sidebar that
    72  * corresponds to the given id selected
    73  * @return a promise that resolves when the inspector is ready and the sidebar
    74  * view is visible and ready
    75  */
    76 let openInspectorSideBar = Task.async(function*(id) {
    77   let {toolbox, inspector} = yield openInspector();
    79   if (!hasSideBarTab(inspector, id)) {
    80     info("Waiting for the " + id + " sidebar to be ready");
    81     yield inspector.sidebar.once(id + "-ready");
    82   }
    84   info("Selecting the " + id + " sidebar");
    85   inspector.sidebar.select(id);
    87   return {
    88     toolbox: toolbox,
    89     inspector: inspector,
    90     view: inspector.sidebar.getWindowForTab(id)[id].view
    91   };
    92 });
    94 /**
    95  * Checks whether the inspector's sidebar corresponding to the given id already
    96  * exists
    97  * @param {InspectorPanel}
    98  * @param {String}
    99  * @return {Boolean}
   100  */
   101 function hasSideBarTab(inspector, id) {
   102   return !!inspector.sidebar.getWindowForTab(id);
   103 }
   105 /**
   106  * Open the toolbox, with the inspector tool visible, and the computed-view
   107  * sidebar tab selected.
   108  * @return a promise that resolves when the inspector is ready and the computed
   109  * view is visible and ready
   110  */
   111 function openComputedView() {
   112   return openInspectorSideBar("computedview");
   113 }
   115 /**
   116  * Open the toolbox, with the inspector tool visible, and the rule-view
   117  * sidebar tab selected.
   118  * @return a promise that resolves when the inspector is ready and the rule
   119  * view is visible and ready
   120  */
   121 function openRuleView() {
   122   return openInspectorSideBar("ruleview");
   123 }

mercurial