|
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 increasing/decreasing values in rule view using |
|
8 // arrow keys works correctly. |
|
9 |
|
10 let test = asyncTest(function*() { |
|
11 yield addTab("data:text/html,sample document for bug 722691"); |
|
12 createDocument(); |
|
13 let {toolbox, inspector, view} = yield openRuleView(); |
|
14 |
|
15 yield selectNode("#test", inspector); |
|
16 |
|
17 yield testMarginIncrements(view); |
|
18 yield testVariousUnitIncrements(view); |
|
19 yield testHexIncrements(view); |
|
20 yield testRgbIncrements(view); |
|
21 yield testShorthandIncrements(view); |
|
22 yield testOddCases(view); |
|
23 }); |
|
24 |
|
25 function createDocument() { |
|
26 content.document.body.innerHTML = '<div id="test" style="' + |
|
27 'margin-top:0px;' + |
|
28 'padding-top: 0px;' + |
|
29 'color:#000000;' + |
|
30 'background-color: #000000;" >'+ |
|
31 '</div>'; |
|
32 } |
|
33 |
|
34 function* testMarginIncrements(view) { |
|
35 info("Testing keyboard increments on the margin property"); |
|
36 |
|
37 let idRuleEditor = view.element.children[0]._ruleEditor; |
|
38 let marginPropEditor = idRuleEditor.rule.textProps[0].editor; |
|
39 |
|
40 yield runIncrementTest(marginPropEditor, view, { |
|
41 1: {alt: true, start: "0px", end: "0.1px", selectAll: true}, |
|
42 2: {start: "0px", end: "1px", selectAll: true}, |
|
43 3: {shift: true, start: "0px", end: "10px", selectAll: true}, |
|
44 4: {down: true, alt: true, start: "0.1px", end: "0px", selectAll: true}, |
|
45 5: {down: true, start: "0px", end: "-1px", selectAll: true}, |
|
46 6: {down: true, shift: true, start: "0px", end: "-10px", selectAll: true}, |
|
47 7: {pageUp: true, shift: true, start: "0px", end: "100px", selectAll: true}, |
|
48 8: {pageDown: true, shift: true, start: "0px", end: "-100px", selectAll: true} |
|
49 }); |
|
50 } |
|
51 |
|
52 function* testVariousUnitIncrements(view) { |
|
53 info("Testing keyboard increments on values with various units"); |
|
54 |
|
55 let idRuleEditor = view.element.children[0]._ruleEditor; |
|
56 let paddingPropEditor = idRuleEditor.rule.textProps[1].editor; |
|
57 |
|
58 yield runIncrementTest(paddingPropEditor, view, { |
|
59 1: {start: "0px", end: "1px", selectAll: true}, |
|
60 2: {start: "0pt", end: "1pt", selectAll: true}, |
|
61 3: {start: "0pc", end: "1pc", selectAll: true}, |
|
62 4: {start: "0em", end: "1em", selectAll: true}, |
|
63 5: {start: "0%", end: "1%", selectAll: true}, |
|
64 6: {start: "0in", end: "1in", selectAll: true}, |
|
65 7: {start: "0cm", end: "1cm", selectAll: true}, |
|
66 8: {start: "0mm", end: "1mm", selectAll: true}, |
|
67 9: {start: "0ex", end: "1ex", selectAll: true} |
|
68 }); |
|
69 }; |
|
70 |
|
71 function* testHexIncrements(view) { |
|
72 info("Testing keyboard increments with hex colors"); |
|
73 |
|
74 let idRuleEditor = view.element.children[0]._ruleEditor; |
|
75 let hexColorPropEditor = idRuleEditor.rule.textProps[2].editor; |
|
76 |
|
77 yield runIncrementTest(hexColorPropEditor, view, { |
|
78 1: {start: "#CCCCCC", end: "#CDCDCD", selectAll: true}, |
|
79 2: {shift: true, start: "#CCCCCC", end: "#DCDCDC", selectAll: true}, |
|
80 3: {start: "#CCCCCC", end: "#CDCCCC", selection: [1,3]}, |
|
81 4: {shift: true, start: "#CCCCCC", end: "#DCCCCC", selection: [1,3]}, |
|
82 5: {start: "#FFFFFF", end: "#FFFFFF", selectAll: true}, |
|
83 6: {down: true, shift: true, start: "#000000", end: "#000000", selectAll: true} |
|
84 }); |
|
85 }; |
|
86 |
|
87 function* testRgbIncrements(view) { |
|
88 info("Testing keyboard increments with rgb colors"); |
|
89 |
|
90 let idRuleEditor = view.element.children[0]._ruleEditor; |
|
91 let rgbColorPropEditor = idRuleEditor.rule.textProps[3].editor; |
|
92 |
|
93 yield runIncrementTest(rgbColorPropEditor, view, { |
|
94 1: {start: "rgb(0,0,0)", end: "rgb(0,1,0)", selection: [6,7]}, |
|
95 2: {shift: true, start: "rgb(0,0,0)", end: "rgb(0,10,0)", selection: [6,7]}, |
|
96 3: {start: "rgb(0,255,0)", end: "rgb(0,255,0)", selection: [6,9]}, |
|
97 4: {shift: true, start: "rgb(0,250,0)", end: "rgb(0,255,0)", selection: [6,9]}, |
|
98 5: {down: true, start: "rgb(0,0,0)", end: "rgb(0,0,0)", selection: [6,7]}, |
|
99 6: {down: true, shift: true, start: "rgb(0,5,0)", end: "rgb(0,0,0)", selection: [6,7]} |
|
100 }); |
|
101 }; |
|
102 |
|
103 function* testShorthandIncrements(view) { |
|
104 info("Testing keyboard increments within shorthand values"); |
|
105 |
|
106 let idRuleEditor = view.element.children[0]._ruleEditor; |
|
107 let paddingPropEditor = idRuleEditor.rule.textProps[1].editor; |
|
108 |
|
109 yield runIncrementTest(paddingPropEditor, view, { |
|
110 1: {start: "0px 0px 0px 0px", end: "0px 1px 0px 0px", selection: [4,7]}, |
|
111 2: {shift: true, start: "0px 0px 0px 0px", end: "0px 10px 0px 0px", selection: [4,7]}, |
|
112 3: {start: "0px 0px 0px 0px", end: "1px 0px 0px 0px", selectAll: true}, |
|
113 4: {shift: true, start: "0px 0px 0px 0px", end: "10px 0px 0px 0px", selectAll: true}, |
|
114 5: {down: true, start: "0px 0px 0px 0px", end: "0px 0px -1px 0px", selection: [8,11]}, |
|
115 6: {down: true, shift: true, start: "0px 0px 0px 0px", end: "-10px 0px 0px 0px", selectAll: true} |
|
116 }); |
|
117 }; |
|
118 |
|
119 function* testOddCases(view) { |
|
120 info("Testing some more odd cases"); |
|
121 |
|
122 let idRuleEditor = view.element.children[0]._ruleEditor; |
|
123 let marginPropEditor = idRuleEditor.rule.textProps[0].editor; |
|
124 |
|
125 yield runIncrementTest(marginPropEditor, view, { |
|
126 1: {start: "98.7%", end: "99.7%", selection: [3,3]}, |
|
127 2: {alt: true, start: "98.7%", end: "98.8%", selection: [3,3]}, |
|
128 3: {start: "0", end: "1"}, |
|
129 4: {down: true, start: "0", end: "-1"}, |
|
130 5: {start: "'a=-1'", end: "'a=0'", selection: [4,4]}, |
|
131 6: {start: "0 -1px", end: "0 0px", selection: [2,2]}, |
|
132 7: {start: "url(-1)", end: "url(-1)", selection: [4,4]}, |
|
133 8: {start: "url('test1.1.png')", end: "url('test1.2.png')", selection: [11,11]}, |
|
134 9: {start: "url('test1.png')", end: "url('test2.png')", selection: [9,9]}, |
|
135 10: {shift: true, start: "url('test1.1.png')", end: "url('test11.1.png')", selection: [9,9]}, |
|
136 11: {down: true, start: "url('test-1.png')", end: "url('test-2.png')", selection: [9,11]}, |
|
137 12: {start: "url('test1.1.png')", end: "url('test1.2.png')", selection: [11,12]}, |
|
138 13: {down: true, alt: true, start: "url('test-0.png')", end: "url('test--0.1.png')", selection: [10,11]}, |
|
139 14: {alt: true, start: "url('test--0.1.png')", end: "url('test-0.png')", selection: [10,14]} |
|
140 }); |
|
141 }; |
|
142 |
|
143 function* runIncrementTest(propertyEditor, view, tests) { |
|
144 let editor = yield focusEditableField(propertyEditor.valueSpan); |
|
145 |
|
146 for(let test in tests) { |
|
147 yield testIncrement(editor, tests[test], view); |
|
148 } |
|
149 |
|
150 // Once properties have been set, wait for the inspector to update |
|
151 yield view.inspector.once("inspector-updated"); |
|
152 } |
|
153 |
|
154 function* testIncrement(editor, options, view) { |
|
155 editor.input.value = options.start; |
|
156 let input = editor.input; |
|
157 |
|
158 if (options.selectAll) { |
|
159 input.select(); |
|
160 } else if (options.selection) { |
|
161 input.setSelectionRange(options.selection[0], options.selection[1]); |
|
162 } |
|
163 |
|
164 is(input.value, options.start, "Value initialized at " + options.start); |
|
165 |
|
166 let onKeyUp = once(input, "keyup"); |
|
167 |
|
168 let key; |
|
169 key = options.down ? "VK_DOWN" : "VK_UP"; |
|
170 key = options.pageDown ? "VK_PAGE_DOWN" : options.pageUp ? "VK_PAGE_UP" : key; |
|
171 EventUtils.synthesizeKey(key, {altKey: options.alt, shiftKey: options.shift}, view.doc.defaultView); |
|
172 |
|
173 yield onKeyUp; |
|
174 input = editor.input; |
|
175 is(input.value, options.end, "Value changed to " + options.end); |
|
176 } |