Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
1 /* Any copyright is dedicated to the Public Domain.
2 http://creativecommons.org/publicdomain/zero/1.0/ */
4 function getStyle(node, property) {
5 return node.style.getPropertyValue(property);
6 }
8 let doc;
9 let inspector;
11 let test = asyncTest(function*() {
12 let style = "div { margin: 10px; padding: 3px } #div1 { margin-top: 5px } #div2 { border-bottom: 1em solid black; } #div3 { padding: 2em; }";
13 let html = "<style>" + style + "</style><div id='div1'></div><div id='div2'></div><div id='div3'></div>"
15 let content = yield loadTab("data:text/html," + encodeURIComponent(html));
16 doc = content.document;
18 let target = TargetFactory.forTab(gBrowser.selectedTab);
19 let toolbox = yield gDevTools.showToolbox(target, "inspector");
20 inspector = toolbox.getCurrentPanel();
22 inspector.sidebar.select("layoutview");
23 yield inspector.sidebar.once("layoutview-ready");
24 yield runTests();
25 // TODO: Closing the toolbox in this test leaks - bug 994314
26 // yield gDevTools.closeToolbox(target);
27 });
29 addTest("Test that editing margin dynamically updates the document, pressing escape cancels the changes",
30 function*() {
31 let node = doc.getElementById("div1");
32 is(getStyle(node, "margin-top"), "", "Should be no margin-top on the element.")
33 let view = yield selectNode(node);
35 let span = view.document.querySelector(".margin.top > span");
36 is(span.textContent, 5, "Should have the right value in the box model.");
38 EventUtils.synthesizeMouseAtCenter(span, {}, view);
39 let editor = view.document.querySelector(".styleinspector-propertyeditor");
40 ok(editor, "Should have opened the editor.");
41 is(editor.value, "5px", "Should have the right value in the editor.");
43 EventUtils.synthesizeKey("3", {}, view);
44 yield waitForUpdate();
46 is(getStyle(node, "margin-top"), "3px", "Should have updated the margin.");
48 EventUtils.synthesizeKey("VK_ESCAPE", {}, view);
49 yield waitForUpdate();
51 is(getStyle(node, "margin-top"), "", "Should be no margin-top on the element.")
52 is(span.textContent, 5, "Should have the right value in the box model.");
53 });
55 addTest("Test that arrow keys work correctly and pressing enter commits the changes",
56 function*() {
57 let node = doc.getElementById("div1");
58 is(getStyle(node, "margin-left"), "", "Should be no margin-top on the element.")
59 let view = yield selectNode(node);
61 let span = view.document.querySelector(".margin.left > span");
62 is(span.textContent, 10, "Should have the right value in the box model.");
64 EventUtils.synthesizeMouseAtCenter(span, {}, view);
65 let editor = view.document.querySelector(".styleinspector-propertyeditor");
66 ok(editor, "Should have opened the editor.");
67 is(editor.value, "10px", "Should have the right value in the editor.");
69 EventUtils.synthesizeKey("VK_UP", {}, view);
70 yield waitForUpdate();
72 is(editor.value, "11px", "Should have the right value in the editor.");
73 is(getStyle(node, "margin-left"), "11px", "Should have updated the margin.");
75 EventUtils.synthesizeKey("VK_DOWN", {}, view);
76 yield waitForUpdate();
78 is(editor.value, "10px", "Should have the right value in the editor.");
79 is(getStyle(node, "margin-left"), "10px", "Should have updated the margin.");
81 EventUtils.synthesizeKey("VK_UP", { shiftKey: true }, view);
82 yield waitForUpdate();
84 is(editor.value, "20px", "Should have the right value in the editor.");
85 is(getStyle(node, "margin-left"), "20px", "Should have updated the margin.");
87 EventUtils.synthesizeKey("VK_RETURN", {}, view);
88 yield waitForUpdate();
90 is(getStyle(node, "margin-left"), "20px", "Should be the right margin-top on the element.")
91 is(span.textContent, 20, "Should have the right value in the box model.");
92 });
94 addTest("Test that deleting the value removes the property but escape undoes that",
95 function*() {
96 let node = doc.getElementById("div1");
97 is(getStyle(node, "margin-left"), "20px", "Should be the right margin-top on the element.")
98 let view = yield selectNode(node);
100 let span = view.document.querySelector(".margin.left > span");
101 is(span.textContent, 20, "Should have the right value in the box model.");
103 EventUtils.synthesizeMouseAtCenter(span, {}, view);
104 let editor = view.document.querySelector(".styleinspector-propertyeditor");
105 ok(editor, "Should have opened the editor.");
106 is(editor.value, "20px", "Should have the right value in the editor.");
108 EventUtils.synthesizeKey("VK_DELETE", {}, view);
109 yield waitForUpdate();
111 is(editor.value, "", "Should have the right value in the editor.");
112 is(getStyle(node, "margin-left"), "", "Should have updated the margin.");
114 EventUtils.synthesizeKey("VK_ESCAPE", {}, view);
115 yield waitForUpdate();
117 is(getStyle(node, "margin-left"), "20px", "Should be the right margin-top on the element.")
118 is(span.textContent, 20, "Should have the right value in the box model.");
119 });
121 addTest("Test that deleting the value removes the property",
122 function*() {
123 let node = doc.getElementById("div1");
124 node.style.marginRight = "15px";
125 let view = yield selectNode(node);
127 let span = view.document.querySelector(".margin.right > span");
128 is(span.textContent, 15, "Should have the right value in the box model.");
130 EventUtils.synthesizeMouseAtCenter(span, {}, view);
131 let editor = view.document.querySelector(".styleinspector-propertyeditor");
132 ok(editor, "Should have opened the editor.");
133 is(editor.value, "15px", "Should have the right value in the editor.");
135 EventUtils.synthesizeKey("VK_DELETE", {}, view);
136 yield waitForUpdate();
138 is(editor.value, "", "Should have the right value in the editor.");
139 is(getStyle(node, "margin-right"), "", "Should have updated the margin.");
141 EventUtils.synthesizeKey("VK_RETURN", {}, view);
142 yield waitForUpdate();
144 is(getStyle(node, "margin-right"), "", "Should be the right margin-top on the element.")
145 is(span.textContent, 10, "Should have the right value in the box model.");
146 });