|
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 original value is correctly displayed when ESCaping out of the |
|
8 // inplace editor in the style inspector. |
|
9 |
|
10 const originalValue = "#00F"; |
|
11 |
|
12 // Test data format |
|
13 // { |
|
14 // value: what char sequence to type, |
|
15 // commitKey: what key to type to "commit" the change, |
|
16 // modifiers: commitKey modifiers, |
|
17 // expected: what value is expected as a result |
|
18 // } |
|
19 const testData = [ |
|
20 {value: "red", commitKey: "VK_ESCAPE", modifiers: {}, expected: originalValue}, |
|
21 {value: "red", commitKey: "VK_RETURN", modifiers: {}, expected: "#F00"}, |
|
22 {value: "invalid", commitKey: "VK_RETURN", modifiers: {}, expected: "invalid"}, |
|
23 {value: "blue", commitKey: "VK_TAB", modifiers: {shiftKey: true}, expected: "blue"} |
|
24 ]; |
|
25 |
|
26 let test = asyncTest(function*() { |
|
27 yield addTab("data:text/html,test escaping property change reverts back to original value"); |
|
28 |
|
29 info("Creating the test document"); |
|
30 createDocument(); |
|
31 |
|
32 info("Opening the rule view"); |
|
33 let {toolbox, inspector, view} = yield openRuleView(); |
|
34 |
|
35 info("Selecting the test node"); |
|
36 yield selectNode("#testid", inspector); |
|
37 |
|
38 info("Iterating over the test data"); |
|
39 for (let data of testData) { |
|
40 yield runTestData(view, data); |
|
41 } |
|
42 }); |
|
43 |
|
44 function createDocument() { |
|
45 let style = '' + |
|
46 '#testid {' + |
|
47 ' color: ' + originalValue + ';' + |
|
48 '}'; |
|
49 |
|
50 let node = content.document.createElement('style'); |
|
51 node.setAttribute("type", "text/css"); |
|
52 node.textContent = style; |
|
53 content.document.getElementsByTagName("head")[0].appendChild(node); |
|
54 |
|
55 content.document.body.innerHTML = '<div id="testid">Styled Node</div>'; |
|
56 } |
|
57 |
|
58 function* runTestData(view, {value, commitKey, modifiers, expected}) { |
|
59 let idRuleEditor = view.element.children[1]._ruleEditor; |
|
60 let propEditor = idRuleEditor.rule.textProps[0].editor; |
|
61 |
|
62 info("Focusing the inplace editor field"); |
|
63 let editor = yield focusEditableField(propEditor.valueSpan); |
|
64 is(inplaceEditor(propEditor.valueSpan), editor, "Focused editor should be the value span."); |
|
65 |
|
66 info("Entering test data " + value) |
|
67 for (let ch of value) { |
|
68 EventUtils.sendChar(ch, view.doc.defaultView); |
|
69 } |
|
70 |
|
71 info("Waiting for focus on the field"); |
|
72 let onBlur = once(editor.input, "blur"); |
|
73 |
|
74 info("Entering the commit key " + commitKey + " " + modifiers); |
|
75 EventUtils.synthesizeKey(commitKey, modifiers); |
|
76 yield onBlur; |
|
77 |
|
78 if (commitKey === "VK_ESCAPE") { |
|
79 is(propEditor.valueSpan.textContent, expected, "Value is as expected: " + expected); |
|
80 } else { |
|
81 yield once(view.element, "CssRuleViewChanged"); |
|
82 is(propEditor.valueSpan.textContent, expected, "Value is as expected: " + expected); |
|
83 } |
|
84 } |