browser/devtools/webconsole/test/browser_console_native_getters.js

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:b18675e3a872
1 /*
2 * Any copyright is dedicated to the Public Domain.
3 * http://creativecommons.org/publicdomain/zero/1.0/
4 */
5
6 // Check that native getters and setters for DOM elements work as expected in
7 // variables view - bug 870220.
8
9 const TEST_URI = "data:text/html;charset=utf8,<title>bug870220</title>\n" +
10 "<p>hello world\n<p>native getters!";
11
12 let gWebConsole, gJSTerm, gVariablesView;
13
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 }
22
23 function consoleOpened(hud)
24 {
25 gWebConsole = hud;
26 gJSTerm = hud.jsterm;
27
28 gJSTerm.execute("document");
29
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 }
39
40 function onEvalResult(aResults)
41 {
42 let clickable = aResults[0].clickableElements[0];
43 ok(clickable, "clickable object found");
44
45 gJSTerm.once("variablesview-fetched", onDocumentFetch);
46 EventUtils.synthesizeMouse(clickable, 2, 2, {}, gWebConsole.iframeWindow)
47 }
48
49 function onDocumentFetch(aEvent, aVar)
50 {
51 gVariablesView = aVar._variablesView;
52 ok(gVariablesView, "variables view object");
53
54 findVariableViewProperties(aVar, [
55 { name: "title", value: "bug870220" },
56 { name: "bgColor" },
57 ], { webconsole: gWebConsole }).then(onDocumentPropsFound);
58 }
59
60 function onDocumentPropsFound(aResults)
61 {
62 let prop = aResults[1].matchedProp;
63 ok(prop, "matched the |bgColor| property in the variables view");
64
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 }
74
75 function onFetchAfterBackgroundUpdate(aEvent, aVar)
76 {
77 info("onFetchAfterBackgroundUpdate");
78
79 is(content.document.bgColor, "red", "document background color changed");
80
81 findVariableViewProperties(aVar, [
82 { name: "bgColor", value: "red" },
83 ], { webconsole: gWebConsole }).then(testParagraphs);
84 }
85
86 function testParagraphs()
87 {
88 gJSTerm.execute("$$('p')");
89
90 waitForMessages({
91 webconsole: gWebConsole,
92 messages: [{
93 text: "NodeList [",
94 category: CATEGORY_OUTPUT,
95 objects: true,
96 }],
97 }).then(onEvalNodeList);
98 }
99
100 function onEvalNodeList(aResults)
101 {
102 let clickable = aResults[0].clickableElements[0];
103 ok(clickable, "clickable object found");
104
105 gJSTerm.once("variablesview-fetched", onNodeListFetch);
106 EventUtils.synthesizeMouse(clickable, 2, 2, {}, gWebConsole.iframeWindow)
107 }
108
109 function onNodeListFetch(aEvent, aVar)
110 {
111 gVariablesView = aVar._variablesView;
112 ok(gVariablesView, "variables view object");
113
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