browser/devtools/layoutview/test/browser_editablemodel.js

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:97c584ec9ade
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 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);
34
35 let span = view.document.querySelector(".margin.top > span");
36 is(span.textContent, 5, "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, "5px", "Should have the right value in the editor.");
42
43 EventUtils.synthesizeKey("3", {}, view);
44 yield waitForUpdate();
45
46 is(getStyle(node, "margin-top"), "3px", "Should have updated the margin.");
47
48 EventUtils.synthesizeKey("VK_ESCAPE", {}, view);
49 yield waitForUpdate();
50
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 });
54
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);
60
61 let span = view.document.querySelector(".margin.left > span");
62 is(span.textContent, 10, "Should have the right value in the box model.");
63
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.");
68
69 EventUtils.synthesizeKey("VK_UP", {}, view);
70 yield waitForUpdate();
71
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.");
74
75 EventUtils.synthesizeKey("VK_DOWN", {}, view);
76 yield waitForUpdate();
77
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.");
80
81 EventUtils.synthesizeKey("VK_UP", { shiftKey: true }, view);
82 yield waitForUpdate();
83
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.");
86
87 EventUtils.synthesizeKey("VK_RETURN", {}, view);
88 yield waitForUpdate();
89
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 });
93
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);
99
100 let span = view.document.querySelector(".margin.left > span");
101 is(span.textContent, 20, "Should have the right value in the box model.");
102
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.");
107
108 EventUtils.synthesizeKey("VK_DELETE", {}, view);
109 yield waitForUpdate();
110
111 is(editor.value, "", "Should have the right value in the editor.");
112 is(getStyle(node, "margin-left"), "", "Should have updated the margin.");
113
114 EventUtils.synthesizeKey("VK_ESCAPE", {}, view);
115 yield waitForUpdate();
116
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 });
120
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);
126
127 let span = view.document.querySelector(".margin.right > span");
128 is(span.textContent, 15, "Should have the right value in the box model.");
129
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.");
134
135 EventUtils.synthesizeKey("VK_DELETE", {}, view);
136 yield waitForUpdate();
137
138 is(editor.value, "", "Should have the right value in the editor.");
139 is(getStyle(node, "margin-right"), "", "Should have updated the margin.");
140
141 EventUtils.synthesizeKey("VK_RETURN", {}, view);
142 yield waitForUpdate();
143
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 });

mercurial