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 // Testing various inplace-editor behaviors in the rule-view
8 // FIXME: To be split in several test files, and some of the inplace-editor
9 // focus/blur/commit/revert stuff should be factored out in head.js
11 let TEST_URL = 'url("' + TEST_URL_ROOT + 'doc_test_image.png")';
12 let PAGE_CONTENT = [
13 '<style type="text/css">',
14 ' #testid {',
15 ' background-color: blue;',
16 ' }',
17 ' .testclass {',
18 ' background-color: green;',
19 ' }',
20 '</style>',
21 '<div id="testid" class="testclass" style="background-color:red;">Styled Node</div>'
22 ].join("\n");
24 let test = asyncTest(function*() {
25 yield addTab("data:text/html,test rule view user changes");
27 info("Creating the test document");
28 content.document.body.innerHTML = PAGE_CONTENT;
30 info("Opening the rule-view");
31 let {toolbox, inspector, view} = yield openRuleView();
33 info("Selecting the test element");
34 yield selectNode("#testid", inspector);
36 yield testCreateNewEscape(view);
37 });
39 function* testCreateNewEscape(view) {
40 info("Test creating a new property and escaping");
42 let elementRuleEditor = view.element.children[0]._ruleEditor;
44 info("Focusing a new property name in the rule-view");
45 let editor = yield focusEditableField(elementRuleEditor.closeBrace);
47 is(inplaceEditor(elementRuleEditor.newPropSpan), editor, "The new property editor got focused.");
48 let input = editor.input;
50 info("Entering a value in the property name editor");
51 input.value = "color";
53 info("Pressing return to commit and focus the new value field");
54 let onValueFocus = once(elementRuleEditor.element, "focus", true);
55 let onModifications = elementRuleEditor.rule._applyingModifications;
56 EventUtils.synthesizeKey("VK_RETURN", {}, view.doc.defaultView);
57 yield onValueFocus;
58 yield onModifications;
60 // Getting the new value editor after focus
61 editor = inplaceEditor(view.doc.activeElement);
62 let textProp = elementRuleEditor.rule.textProps[1];
64 is(elementRuleEditor.rule.textProps.length, 2, "Created a new text property.");
65 is(elementRuleEditor.propertyList.children.length, 2, "Created a property editor.");
66 is(editor, inplaceEditor(textProp.editor.valueSpan), "Editing the value span now.");
68 info("Entering a property value");
69 editor.input.value = "red";
71 info("Escaping out of the field");
72 EventUtils.synthesizeKey("VK_ESCAPE", {}, view.doc.defaultView);
74 info("Checking that the previous field is focused");
75 let focusedElement = inplaceEditor(elementRuleEditor.rule.textProps[0].editor.valueSpan).input;
76 is(focusedElement, focusedElement.ownerDocument.activeElement, "Correct element has focus");
78 let onModifications = elementRuleEditor.rule._applyingModifications;
79 EventUtils.synthesizeKey("VK_ESCAPE", {}, view.doc.defaultView);
80 yield onModifications;
82 is(elementRuleEditor.rule.textProps.length, 1, "Removed the new text property.");
83 is(elementRuleEditor.propertyList.children.length, 1, "Removed the property editor.");
84 }