browser/devtools/webconsole/test/browser_console_native_getters.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 // Check that native getters and setters for DOM elements work as expected in
     7 // variables view - bug 870220.
     9 const TEST_URI = "data:text/html;charset=utf8,<title>bug870220</title>\n" +
    10                  "<p>hello world\n<p>native getters!";
    12 let gWebConsole, gJSTerm, gVariablesView;
    14 function test()
    15 {
    16   addTab(TEST_URI);
    17   browser.addEventListener("load", function onLoad() {
    18     browser.removeEventListener("load", onLoad, true);
    19     openConsole(null, consoleOpened);
    20   }, true);
    21 }
    23 function consoleOpened(hud)
    24 {
    25   gWebConsole = hud;
    26   gJSTerm = hud.jsterm;
    28   gJSTerm.execute("document");
    30   waitForMessages({
    31     webconsole: hud,
    32     messages: [{
    33       text: "HTMLDocument \u2192 data:text/html;charset=utf8",
    34       category: CATEGORY_OUTPUT,
    35       objects: true,
    36     }],
    37   }).then(onEvalResult);
    38 }
    40 function onEvalResult(aResults)
    41 {
    42   let clickable = aResults[0].clickableElements[0];
    43   ok(clickable, "clickable object found");
    45   gJSTerm.once("variablesview-fetched", onDocumentFetch);
    46   EventUtils.synthesizeMouse(clickable, 2, 2, {}, gWebConsole.iframeWindow)
    47 }
    49 function onDocumentFetch(aEvent, aVar)
    50 {
    51   gVariablesView = aVar._variablesView;
    52   ok(gVariablesView, "variables view object");
    54   findVariableViewProperties(aVar, [
    55     { name: "title", value: "bug870220" },
    56     { name: "bgColor" },
    57   ], { webconsole: gWebConsole }).then(onDocumentPropsFound);
    58 }
    60 function onDocumentPropsFound(aResults)
    61 {
    62   let prop = aResults[1].matchedProp;
    63   ok(prop, "matched the |bgColor| property in the variables view");
    65   // Check that property value updates work.
    66   updateVariablesViewProperty({
    67     property: prop,
    68     field: "value",
    69     string: "'red'",
    70     webconsole: gWebConsole,
    71     callback: onFetchAfterBackgroundUpdate,
    72   });
    73 }
    75 function onFetchAfterBackgroundUpdate(aEvent, aVar)
    76 {
    77   info("onFetchAfterBackgroundUpdate");
    79   is(content.document.bgColor, "red", "document background color changed");
    81   findVariableViewProperties(aVar, [
    82     { name: "bgColor", value: "red" },
    83   ], { webconsole: gWebConsole }).then(testParagraphs);
    84 }
    86 function testParagraphs()
    87 {
    88   gJSTerm.execute("$$('p')");
    90   waitForMessages({
    91     webconsole: gWebConsole,
    92     messages: [{
    93       text: "NodeList [",
    94       category: CATEGORY_OUTPUT,
    95       objects: true,
    96     }],
    97   }).then(onEvalNodeList);
    98 }
   100 function onEvalNodeList(aResults)
   101 {
   102   let clickable = aResults[0].clickableElements[0];
   103   ok(clickable, "clickable object found");
   105   gJSTerm.once("variablesview-fetched", onNodeListFetch);
   106   EventUtils.synthesizeMouse(clickable, 2, 2, {}, gWebConsole.iframeWindow)
   107 }
   109 function onNodeListFetch(aEvent, aVar)
   110 {
   111   gVariablesView = aVar._variablesView;
   112   ok(gVariablesView, "variables view object");
   114   findVariableViewProperties(aVar, [
   115     { name: "0.textContent", value: /hello world/ },
   116     { name: "1.textContent", value: /native getters/ },
   117   ], { webconsole: gWebConsole }).then(() => {
   118     gWebConsole = gJSTerm = gVariablesView = null;
   119     finishTest();
   120   });
   121 }

mercurial