browser/devtools/webconsole/test/browser_console_native_getters.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/browser/devtools/webconsole/test/browser_console_native_getters.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,121 @@
     1.4 +/*
     1.5 + * Any copyright is dedicated to the Public Domain.
     1.6 + * http://creativecommons.org/publicdomain/zero/1.0/
     1.7 + */
     1.8 +
     1.9 +// Check that native getters and setters for DOM elements work as expected in
    1.10 +// variables view - bug 870220.
    1.11 +
    1.12 +const TEST_URI = "data:text/html;charset=utf8,<title>bug870220</title>\n" +
    1.13 +                 "<p>hello world\n<p>native getters!";
    1.14 +
    1.15 +let gWebConsole, gJSTerm, gVariablesView;
    1.16 +
    1.17 +function test()
    1.18 +{
    1.19 +  addTab(TEST_URI);
    1.20 +  browser.addEventListener("load", function onLoad() {
    1.21 +    browser.removeEventListener("load", onLoad, true);
    1.22 +    openConsole(null, consoleOpened);
    1.23 +  }, true);
    1.24 +}
    1.25 +
    1.26 +function consoleOpened(hud)
    1.27 +{
    1.28 +  gWebConsole = hud;
    1.29 +  gJSTerm = hud.jsterm;
    1.30 +
    1.31 +  gJSTerm.execute("document");
    1.32 +
    1.33 +  waitForMessages({
    1.34 +    webconsole: hud,
    1.35 +    messages: [{
    1.36 +      text: "HTMLDocument \u2192 data:text/html;charset=utf8",
    1.37 +      category: CATEGORY_OUTPUT,
    1.38 +      objects: true,
    1.39 +    }],
    1.40 +  }).then(onEvalResult);
    1.41 +}
    1.42 +
    1.43 +function onEvalResult(aResults)
    1.44 +{
    1.45 +  let clickable = aResults[0].clickableElements[0];
    1.46 +  ok(clickable, "clickable object found");
    1.47 +
    1.48 +  gJSTerm.once("variablesview-fetched", onDocumentFetch);
    1.49 +  EventUtils.synthesizeMouse(clickable, 2, 2, {}, gWebConsole.iframeWindow)
    1.50 +}
    1.51 +
    1.52 +function onDocumentFetch(aEvent, aVar)
    1.53 +{
    1.54 +  gVariablesView = aVar._variablesView;
    1.55 +  ok(gVariablesView, "variables view object");
    1.56 +
    1.57 +  findVariableViewProperties(aVar, [
    1.58 +    { name: "title", value: "bug870220" },
    1.59 +    { name: "bgColor" },
    1.60 +  ], { webconsole: gWebConsole }).then(onDocumentPropsFound);
    1.61 +}
    1.62 +
    1.63 +function onDocumentPropsFound(aResults)
    1.64 +{
    1.65 +  let prop = aResults[1].matchedProp;
    1.66 +  ok(prop, "matched the |bgColor| property in the variables view");
    1.67 +
    1.68 +  // Check that property value updates work.
    1.69 +  updateVariablesViewProperty({
    1.70 +    property: prop,
    1.71 +    field: "value",
    1.72 +    string: "'red'",
    1.73 +    webconsole: gWebConsole,
    1.74 +    callback: onFetchAfterBackgroundUpdate,
    1.75 +  });
    1.76 +}
    1.77 +
    1.78 +function onFetchAfterBackgroundUpdate(aEvent, aVar)
    1.79 +{
    1.80 +  info("onFetchAfterBackgroundUpdate");
    1.81 +
    1.82 +  is(content.document.bgColor, "red", "document background color changed");
    1.83 +
    1.84 +  findVariableViewProperties(aVar, [
    1.85 +    { name: "bgColor", value: "red" },
    1.86 +  ], { webconsole: gWebConsole }).then(testParagraphs);
    1.87 +}
    1.88 +
    1.89 +function testParagraphs()
    1.90 +{
    1.91 +  gJSTerm.execute("$$('p')");
    1.92 +
    1.93 +  waitForMessages({
    1.94 +    webconsole: gWebConsole,
    1.95 +    messages: [{
    1.96 +      text: "NodeList [",
    1.97 +      category: CATEGORY_OUTPUT,
    1.98 +      objects: true,
    1.99 +    }],
   1.100 +  }).then(onEvalNodeList);
   1.101 +}
   1.102 +
   1.103 +function onEvalNodeList(aResults)
   1.104 +{
   1.105 +  let clickable = aResults[0].clickableElements[0];
   1.106 +  ok(clickable, "clickable object found");
   1.107 +
   1.108 +  gJSTerm.once("variablesview-fetched", onNodeListFetch);
   1.109 +  EventUtils.synthesizeMouse(clickable, 2, 2, {}, gWebConsole.iframeWindow)
   1.110 +}
   1.111 +
   1.112 +function onNodeListFetch(aEvent, aVar)
   1.113 +{
   1.114 +  gVariablesView = aVar._variablesView;
   1.115 +  ok(gVariablesView, "variables view object");
   1.116 +
   1.117 +  findVariableViewProperties(aVar, [
   1.118 +    { name: "0.textContent", value: /hello world/ },
   1.119 +    { name: "1.textContent", value: /native getters/ },
   1.120 +  ], { webconsole: gWebConsole }).then(() => {
   1.121 +    gWebConsole = gJSTerm = gVariablesView = null;
   1.122 +    finishTest();
   1.123 +  });
   1.124 +}

mercurial