browser/devtools/styleinspector/test/browser_ruleview_add-property-cancel_02.js

branch
TOR_BUG_9701
changeset 15
b8a032363ba2
equal deleted inserted replaced
-1:000000000000 0:e5ba038fdd63
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 // 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
10
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");
23
24 let test = asyncTest(function*() {
25 yield addTab("data:text/html,test rule view user changes");
26
27 info("Creating the test document");
28 content.document.body.innerHTML = PAGE_CONTENT;
29
30 info("Opening the rule-view");
31 let {toolbox, inspector, view} = yield openRuleView();
32
33 info("Selecting the test element");
34 yield selectNode("#testid", inspector);
35
36 yield testCreateNewEscape(view);
37 });
38
39 function* testCreateNewEscape(view) {
40 info("Test creating a new property and escaping");
41
42 let elementRuleEditor = view.element.children[0]._ruleEditor;
43
44 info("Focusing a new property name in the rule-view");
45 let editor = yield focusEditableField(elementRuleEditor.closeBrace);
46
47 is(inplaceEditor(elementRuleEditor.newPropSpan), editor, "The new property editor got focused.");
48 let input = editor.input;
49
50 info("Entering a value in the property name editor");
51 input.value = "color";
52
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;
59
60 // Getting the new value editor after focus
61 editor = inplaceEditor(view.doc.activeElement);
62 let textProp = elementRuleEditor.rule.textProps[1];
63
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.");
67
68 info("Entering a property value");
69 editor.input.value = "red";
70
71 info("Escaping out of the field");
72 EventUtils.synthesizeKey("VK_ESCAPE", {}, view.doc.defaultView);
73
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");
77
78 let onModifications = elementRuleEditor.rule._applyingModifications;
79 EventUtils.synthesizeKey("VK_ESCAPE", {}, view.doc.defaultView);
80 yield onModifications;
81
82 is(elementRuleEditor.rule.textProps.length, 1, "Removed the new text property.");
83 is(elementRuleEditor.propertyList.children.length, 1, "Removed the property editor.");
84 }

mercurial