|
1 /* vim: set ft=javascript ts=2 et sw=2 tw=80: */ |
|
2 /* Any copyright is dedicated to the Public Domain. |
|
3 http://creativecommons.org/publicdomain/zero/1.0/ */ |
|
4 |
|
5 "use strict"; |
|
6 |
|
7 // Test that changes are previewed when editing a property value |
|
8 |
|
9 // Format |
|
10 // { |
|
11 // value : what to type in the field |
|
12 // expected : expected computed style on the targeted element |
|
13 // } |
|
14 const TEST_DATA = [ |
|
15 {value: "inline", expected: "inline"}, |
|
16 {value: "inline-block", expected: "inline-block"}, |
|
17 |
|
18 // Invalid property values should not apply, and should fall back to default |
|
19 {value: "red", expected: "block"}, |
|
20 {value: "something", expected: "block"}, |
|
21 |
|
22 {escape: true, value: "inline", expected: "block"} |
|
23 ]; |
|
24 |
|
25 let test = asyncTest(function*() { |
|
26 yield addTab("data:text/html,test rule view live preview on user changes"); |
|
27 |
|
28 let style = '#testid {display:block;}'; |
|
29 let styleNode = addStyle(content.document, style); |
|
30 content.document.body.innerHTML = '<div id="testid">Styled Node</div><span>inline element</span>'; |
|
31 let testElement = getNode("#testid"); |
|
32 |
|
33 let {toolbox, inspector, view} = yield openRuleView(); |
|
34 yield selectNode(testElement, inspector); |
|
35 |
|
36 for (let data of TEST_DATA) { |
|
37 yield testLivePreviewData(data, view, testElement); |
|
38 } |
|
39 }); |
|
40 |
|
41 |
|
42 function* testLivePreviewData(data, ruleView, testElement) { |
|
43 let idRuleEditor = ruleView.element.children[1]._ruleEditor; |
|
44 let propEditor = idRuleEditor.rule.textProps[0].editor; |
|
45 |
|
46 info("Focusing the property value inplace-editor"); |
|
47 let editor = yield focusEditableField(propEditor.valueSpan); |
|
48 is(inplaceEditor(propEditor.valueSpan), editor, "The focused editor is the value"); |
|
49 |
|
50 info("Enter a value in the editor") |
|
51 for (let ch of data.value) { |
|
52 EventUtils.sendChar(ch, ruleView.doc.defaultView); |
|
53 } |
|
54 if (data.escape) { |
|
55 EventUtils.synthesizeKey("VK_ESCAPE", {}); |
|
56 } else { |
|
57 EventUtils.synthesizeKey("VK_RETURN", {}); |
|
58 } |
|
59 |
|
60 yield wait(1); |
|
61 |
|
62 // While the editor is still focused in, the display should have changed already |
|
63 is(content.getComputedStyle(testElement).display, |
|
64 data.expected, |
|
65 "Element should be previewed as " + data.expected); |
|
66 } |