Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
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/ */
5 "use strict";
7 // Test original value is correctly displayed when ESCaping out of the
8 // inplace editor in the style inspector.
10 const originalValue = "#00F";
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 ];
26 let test = asyncTest(function*() {
27 yield addTab("data:text/html,test escaping property change reverts back to original value");
29 info("Creating the test document");
30 createDocument();
32 info("Opening the rule view");
33 let {toolbox, inspector, view} = yield openRuleView();
35 info("Selecting the test node");
36 yield selectNode("#testid", inspector);
38 info("Iterating over the test data");
39 for (let data of testData) {
40 yield runTestData(view, data);
41 }
42 });
44 function createDocument() {
45 let style = '' +
46 '#testid {' +
47 ' color: ' + originalValue + ';' +
48 '}';
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);
55 content.document.body.innerHTML = '<div id="testid">Styled Node</div>';
56 }
58 function* runTestData(view, {value, commitKey, modifiers, expected}) {
59 let idRuleEditor = view.element.children[1]._ruleEditor;
60 let propEditor = idRuleEditor.rule.textProps[0].editor;
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.");
66 info("Entering test data " + value)
67 for (let ch of value) {
68 EventUtils.sendChar(ch, view.doc.defaultView);
69 }
71 info("Waiting for focus on the field");
72 let onBlur = once(editor.input, "blur");
74 info("Entering the commit key " + commitKey + " " + modifiers);
75 EventUtils.synthesizeKey(commitKey, modifiers);
76 yield onBlur;
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 }