browser/devtools/webconsole/test/browser_webconsole_output_dom_elements_02.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 /*
     2  * Any copyright is dedicated to the Public Domain.
     3  * http://creativecommons.org/publicdomain/zero/1.0/
     4  */
     6 // Test the inspector links in the webconsole output for DOM Nodes actually
     7 // open the inspector and select the right node
     9 const TEST_URI = "http://example.com/browser/browser/devtools/webconsole/test/test-console-output-dom-elements.html";
    11 const TEST_DATA = [
    12   {
    13     // The first test shouldn't be returning the body element as this is the
    14     // default selected node, so re-selecting it won't fire the inspector-updated
    15     // event
    16     input: "testNode()",
    17     output: '<p some-attribute="some-value">'
    18   },
    19   {
    20     input: "testBodyNode()",
    21     output: '<body id="body-id" class="body-class">'
    22   },
    23   {
    24     input: "testNodeInIframe()",
    25     output: '<p>'
    26   },
    27   {
    28     input: "testDocumentElement()",
    29     output: '<html lang="en-US" dir="ltr">'
    30   }
    31 ];
    33 function test() {
    34   Task.spawn(function*() {
    35     let {tab} = yield loadTab(TEST_URI);
    36     let hud = yield openConsole(tab);
    37     let toolbox = gDevTools.getToolbox(hud.target);
    39     // Loading the inspector panel at first, to make it possible to listen for
    40     // new node selections
    41     yield toolbox.selectTool("inspector");
    42     let inspector = toolbox.getCurrentPanel();
    43     yield toolbox.selectTool("webconsole");
    45     info("Iterating over the test data");
    46     for (let data of TEST_DATA) {
    47       let [result] = yield jsEval(data.input, hud, {text: data.output});
    48       let {widget, msg} = yield getWidgetAndMessage(result);
    50       let inspectorIcon = msg.querySelector(".open-inspector");
    51       ok(inspectorIcon, "Inspector icon found in the ElementNode widget");
    53       info("Clicking on the inspector icon and waiting for the inspector to be selected");
    54       let onInspectorSelected = toolbox.once("inspector-selected");
    55       let onInspectorUpdated = inspector.once("inspector-updated");
    56       let onNewNode = toolbox.selection.once("new-node");
    58       EventUtils.synthesizeMouseAtCenter(inspectorIcon, {},
    59         inspectorIcon.ownerDocument.defaultView);
    60       yield onInspectorSelected;
    61       yield onInspectorUpdated;
    62       yield onNewNode;
    63       ok(true, "Inspector selected and new node got selected");
    65       let rawNode = content.wrappedJSObject[data.input.replace(/\(\)/g, "")]();
    66       is(inspector.selection.node.wrappedJSObject, rawNode,
    67          "The current inspector selection is correct");
    69       info("Switching back to the console");
    70       yield toolbox.selectTool("webconsole");
    71     }
    72   }).then(finishTest);
    73 }
    75 function jsEval(input, hud, message) {
    76   info("Executing '" + input + "' in the web console");
    78   hud.jsterm.clearOutput();
    79   hud.jsterm.execute(input);
    81   return waitForMessages({
    82     webconsole: hud,
    83     messages: [message]
    84   });
    85 }
    87 function* getWidgetAndMessage(result) {
    88   info("Getting the output ElementNode widget");
    90   let msg = [...result.matched][0];
    91   let widget = [...msg._messageObject.widgets][0];
    92   ok(widget, "ElementNode widget found in the output");
    94   info("Waiting for the ElementNode widget to be linked to the inspector");
    95   yield widget.linkToInspector();
    97   return {widget: widget, msg: msg};
    98 }

mercurial