|
1 |
|
2 /* Any copyright is dedicated to the Public Domain. |
|
3 http://creativecommons.org/publicdomain/zero/1.0/ */ |
|
4 |
|
5 function getStyle(node, property) { |
|
6 return node.style.getPropertyValue(property); |
|
7 } |
|
8 |
|
9 let doc; |
|
10 let inspector; |
|
11 |
|
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>" |
|
15 |
|
16 let content = yield loadTab("data:text/html," + encodeURIComponent(html)); |
|
17 doc = content.document; |
|
18 |
|
19 let target = TargetFactory.forTab(gBrowser.selectedTab); |
|
20 let toolbox = yield gDevTools.showToolbox(target, "inspector"); |
|
21 inspector = toolbox.getCurrentPanel(); |
|
22 |
|
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 }); |
|
29 |
|
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); |
|
35 |
|
36 let span = view.document.querySelector(".padding.bottom > span"); |
|
37 is(span.textContent, 5, "Should have the right value in the box model."); |
|
38 |
|
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."); |
|
43 |
|
44 EventUtils.synthesizeKey("7", {}, view); |
|
45 yield waitForUpdate(); |
|
46 |
|
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"); |
|
49 |
|
50 EventUtils.synthesizeKey("VK_RETURN", {}, view); |
|
51 yield waitForUpdate(); |
|
52 |
|
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 }); |
|
56 |
|
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); |
|
62 |
|
63 let span = view.document.querySelector(".padding.left > span"); |
|
64 is(span.textContent, 5, "Should have the right value in the box model."); |
|
65 |
|
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."); |
|
70 |
|
71 EventUtils.synthesizeKey("8", {}, view); |
|
72 yield waitForUpdate(); |
|
73 |
|
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"); |
|
76 |
|
77 EventUtils.synthesizeKey("VK_ESCAPE", {}, view); |
|
78 yield waitForUpdate(); |
|
79 |
|
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 }); |
|
83 |
|
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); |
|
89 |
|
90 let span = view.document.querySelector(".padding.left > span"); |
|
91 is(span.textContent, 5, "Should have the right value in the box model."); |
|
92 |
|
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."); |
|
97 |
|
98 EventUtils.synthesizeKey("VK_DELETE", {}, view); |
|
99 yield waitForUpdate(); |
|
100 |
|
101 is(editor.value, "", "Should have the right value in the editor."); |
|
102 is(getStyle(node, "padding-left"), "", "Should have updated the padding"); |
|
103 |
|
104 EventUtils.synthesizeKey("VK_RETURN", {}, view); |
|
105 yield waitForUpdate(); |
|
106 |
|
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 }); |
|
110 |
|
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); |
|
116 |
|
117 let span = view.document.querySelector(".padding.left > span"); |
|
118 is(span.textContent, 5, "Should have the right value in the box model."); |
|
119 |
|
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."); |
|
124 |
|
125 EventUtils.synthesizeKey("VK_DELETE", {}, view); |
|
126 yield waitForUpdate(); |
|
127 |
|
128 is(editor.value, "", "Should have the right value in the editor."); |
|
129 is(getStyle(node, "padding-left"), "", "Should have updated the padding"); |
|
130 |
|
131 EventUtils.synthesizeKey("VK_ESCAPE", {}, view); |
|
132 yield waitForUpdate(); |
|
133 |
|
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 }); |