|
1 /* Any copyright is dedicated to the Public Domain. |
|
2 http://creativecommons.org/publicdomain/zero/1.0/ */ |
|
3 |
|
4 function getStyle(node, property) { |
|
5 return node.style.getPropertyValue(property); |
|
6 } |
|
7 |
|
8 let doc; |
|
9 let inspector; |
|
10 |
|
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>" |
|
14 |
|
15 let content = yield loadTab("data:text/html," + encodeURIComponent(html)); |
|
16 doc = content.document; |
|
17 |
|
18 let target = TargetFactory.forTab(gBrowser.selectedTab); |
|
19 let toolbox = yield gDevTools.showToolbox(target, "inspector"); |
|
20 inspector = toolbox.getCurrentPanel(); |
|
21 |
|
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 }); |
|
28 |
|
29 addTest("Test that entering units works", |
|
30 function*() { |
|
31 let node = doc.getElementById("div1"); |
|
32 is(getStyle(node, "padding-top"), "", "Should have the right padding"); |
|
33 let view = yield selectNode(node); |
|
34 |
|
35 let span = view.document.querySelector(".padding.top > span"); |
|
36 is(span.textContent, 3, "Should have the right value in the box model."); |
|
37 |
|
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, "3px", "Should have the right value in the editor."); |
|
42 |
|
43 EventUtils.synthesizeKey("1", {}, view); |
|
44 yield waitForUpdate(); |
|
45 EventUtils.synthesizeKey("e", {}, view); |
|
46 yield waitForUpdate(); |
|
47 |
|
48 is(getStyle(node, "padding-top"), "", "An invalid value is handled cleanly"); |
|
49 |
|
50 EventUtils.synthesizeKey("m", {}, view); |
|
51 yield waitForUpdate(); |
|
52 |
|
53 is(editor.value, "1em", "Should have the right value in the editor."); |
|
54 is(getStyle(node, "padding-top"), "1em", "Should have updated the padding."); |
|
55 |
|
56 EventUtils.synthesizeKey("VK_RETURN", {}, view); |
|
57 yield waitForUpdate(); |
|
58 |
|
59 is(getStyle(node, "padding-top"), "1em", "Should be the right padding.") |
|
60 is(span.textContent, 16, "Should have the right value in the box model."); |
|
61 }); |
|
62 |
|
63 addTest("Test that we pick up the value from a higher style rule", |
|
64 function*() { |
|
65 let node = doc.getElementById("div2"); |
|
66 is(getStyle(node, "border-bottom-width"), "", "Should have the right border-bottom-width"); |
|
67 let view = yield selectNode(node); |
|
68 |
|
69 let span = view.document.querySelector(".border.bottom > span"); |
|
70 is(span.textContent, 16, "Should have the right value in the box model."); |
|
71 |
|
72 EventUtils.synthesizeMouseAtCenter(span, {}, view); |
|
73 let editor = view.document.querySelector(".styleinspector-propertyeditor"); |
|
74 ok(editor, "Should have opened the editor."); |
|
75 is(editor.value, "1em", "Should have the right value in the editor."); |
|
76 |
|
77 EventUtils.synthesizeKey("0", {}, view); |
|
78 yield waitForUpdate(); |
|
79 |
|
80 is(editor.value, "0", "Should have the right value in the editor."); |
|
81 is(getStyle(node, "border-bottom-width"), "0px", "Should have updated the border."); |
|
82 |
|
83 EventUtils.synthesizeKey("VK_RETURN", {}, view); |
|
84 yield waitForUpdate(); |
|
85 |
|
86 is(getStyle(node, "border-bottom-width"), "0px", "Should be the right border-bottom-width.") |
|
87 is(span.textContent, 0, "Should have the right value in the box model."); |
|
88 }); |
|
89 |
|
90 addTest("Test that shorthand properties are parsed correctly", |
|
91 function*() { |
|
92 let node = doc.getElementById("div3"); |
|
93 is(getStyle(node, "padding-right"), "", "Should have the right padding"); |
|
94 let view = yield selectNode(node); |
|
95 |
|
96 let span = view.document.querySelector(".padding.right > span"); |
|
97 is(span.textContent, 32, "Should have the right value in the box model."); |
|
98 |
|
99 EventUtils.synthesizeMouseAtCenter(span, {}, view); |
|
100 let editor = view.document.querySelector(".styleinspector-propertyeditor"); |
|
101 ok(editor, "Should have opened the editor."); |
|
102 is(editor.value, "2em", "Should have the right value in the editor."); |
|
103 |
|
104 EventUtils.synthesizeKey("VK_RETURN", {}, view); |
|
105 yield waitForUpdate(); |
|
106 |
|
107 is(getStyle(node, "padding-right"), "", "Should be the right padding.") |
|
108 is(span.textContent, 32, "Should have the right value in the box model."); |
|
109 }); |