browser/devtools/webconsole/test/browser_console_native_getters.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

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

mercurial