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
2 /* Any copyright is dedicated to the Public Domain.
3 http://creativecommons.org/publicdomain/zero/1.0/ */
5 function getStyle(node, property) {
6 return node.style.getPropertyValue(property);
7 }
9 let doc;
10 let inspector;
12 let test = asyncTest(function*() {
13 let style = "div { margin: 10px; padding: 3px } #div1 { margin-top: 5px } #div2 { border-bottom: 1em solid black; } #div3 { padding: 2em; }";
14 let html = "<style>" + style + "</style><div id='div1'></div><div id='div2'></div><div id='div3'></div>"
16 let content = yield loadTab("data:text/html," + encodeURIComponent(html));
17 doc = content.document;
19 let target = TargetFactory.forTab(gBrowser.selectedTab);
20 let toolbox = yield gDevTools.showToolbox(target, "inspector");
21 inspector = toolbox.getCurrentPanel();
23 inspector.sidebar.select("layoutview");
24 yield inspector.sidebar.once("layoutview-ready");
25 yield runTests();
26 // TODO: Closing the toolbox in this test leaks - bug 994314
27 // yield gDevTools.closeToolbox(target);
28 });
30 addTest("When all properties are set on the node editing one should work",
31 function*() {
32 let node = doc.getElementById("div1");
33 node.style.padding = "5px";
34 let view = yield selectNode(node);
36 let span = view.document.querySelector(".padding.bottom > span");
37 is(span.textContent, 5, "Should have the right value in the box model.");
39 EventUtils.synthesizeMouseAtCenter(span, {}, view);
40 let editor = view.document.querySelector(".styleinspector-propertyeditor");
41 ok(editor, "Should have opened the editor.");
42 is(editor.value, "5px", "Should have the right value in the editor.");
44 EventUtils.synthesizeKey("7", {}, view);
45 yield waitForUpdate();
47 is(editor.value, "7", "Should have the right value in the editor.");
48 is(getStyle(node, "padding-bottom"), "7px", "Should have updated the padding");
50 EventUtils.synthesizeKey("VK_RETURN", {}, view);
51 yield waitForUpdate();
53 is(getStyle(node, "padding-bottom"), "7px", "Should be the right padding.")
54 is(span.textContent, 7, "Should have the right value in the box model.");
55 });
57 addTest("When all properties are set on the node editing one should work",
58 function*() {
59 let node = doc.getElementById("div1");
60 node.style.padding = "5px";
61 let view = yield selectNode(node);
63 let span = view.document.querySelector(".padding.left > span");
64 is(span.textContent, 5, "Should have the right value in the box model.");
66 EventUtils.synthesizeMouseAtCenter(span, {}, view);
67 let editor = view.document.querySelector(".styleinspector-propertyeditor");
68 ok(editor, "Should have opened the editor.");
69 is(editor.value, "5px", "Should have the right value in the editor.");
71 EventUtils.synthesizeKey("8", {}, view);
72 yield waitForUpdate();
74 is(editor.value, "8", "Should have the right value in the editor.");
75 is(getStyle(node, "padding-left"), "8px", "Should have updated the padding");
77 EventUtils.synthesizeKey("VK_ESCAPE", {}, view);
78 yield waitForUpdate();
80 is(getStyle(node, "padding-left"), "5px", "Should be the right padding.")
81 is(span.textContent, 5, "Should have the right value in the box model.");
82 });
84 addTest("When all properties are set on the node deleting one should work",
85 function*() {
86 let node = doc.getElementById("div1");
87 node.style.padding = "5px";
88 let view = yield selectNode(node);
90 let span = view.document.querySelector(".padding.left > span");
91 is(span.textContent, 5, "Should have the right value in the box model.");
93 EventUtils.synthesizeMouseAtCenter(span, {}, view);
94 let editor = view.document.querySelector(".styleinspector-propertyeditor");
95 ok(editor, "Should have opened the editor.");
96 is(editor.value, "5px", "Should have the right value in the editor.");
98 EventUtils.synthesizeKey("VK_DELETE", {}, view);
99 yield waitForUpdate();
101 is(editor.value, "", "Should have the right value in the editor.");
102 is(getStyle(node, "padding-left"), "", "Should have updated the padding");
104 EventUtils.synthesizeKey("VK_RETURN", {}, view);
105 yield waitForUpdate();
107 is(getStyle(node, "padding-left"), "", "Should be the right padding.")
108 is(span.textContent, 3, "Should have the right value in the box model.");
109 });
111 addTest("When all properties are set on the node deleting one then cancelling should work",
112 function*() {
113 let node = doc.getElementById("div1");
114 node.style.padding = "5px";
115 let view = yield selectNode(node);
117 let span = view.document.querySelector(".padding.left > span");
118 is(span.textContent, 5, "Should have the right value in the box model.");
120 EventUtils.synthesizeMouseAtCenter(span, {}, view);
121 let editor = view.document.querySelector(".styleinspector-propertyeditor");
122 ok(editor, "Should have opened the editor.");
123 is(editor.value, "5px", "Should have the right value in the editor.");
125 EventUtils.synthesizeKey("VK_DELETE", {}, view);
126 yield waitForUpdate();
128 is(editor.value, "", "Should have the right value in the editor.");
129 is(getStyle(node, "padding-left"), "", "Should have updated the padding");
131 EventUtils.synthesizeKey("VK_ESCAPE", {}, view);
132 yield waitForUpdate();
134 is(getStyle(node, "padding-left"), "5px", "Should be the right padding.")
135 is(span.textContent, 5, "Should have the right value in the box model.");
136 });