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 cancelling the addition of a new property in the rule-view
9 let test = asyncTest(function*() {
10 yield addTab("data:text/html;charset=utf-8,browser_ruleview_ui.js");
11 let {toolbox, inspector, view} = yield openRuleView();
13 info("Creating the test document");
14 let style = "" +
15 "#testid {" +
16 " background-color: blue;" +
17 "}" +
18 ".testclass, .unmatched {" +
19 " background-color: green;" +
20 "}";
21 let styleNode = addStyle(content.document, style);
22 content.document.body.innerHTML = "<div id='testid' class='testclass'>Styled Node</div>" +
23 "<div id='testid2'>Styled Node</div>";
25 yield testCancelNew(inspector, view);
26 yield testCancelNewOnEscape(inspector, view);
27 yield inspector.once("inspector-updated");
28 });
30 function* testCancelNew(inspector, ruleView) {
31 // Start at the beginning: start to add a rule to the element's style
32 // declaration, but leave it empty.
34 let elementRuleEditor = ruleView.element.children[0]._ruleEditor;
35 let editor = yield focusEditableField(elementRuleEditor.closeBrace);
37 is(inplaceEditor(elementRuleEditor.newPropSpan), editor,
38 "Property editor is focused");
40 let onBlur = once(editor.input, "blur");
41 editor.input.blur();
42 yield onBlur;
44 ok(!elementRuleEditor.rule._applyingModifications, "Shouldn't have an outstanding modification request after a cancel.");
45 is(elementRuleEditor.rule.textProps.length, 0, "Should have canceled creating a new text property.");
46 ok(!elementRuleEditor.propertyList.hasChildNodes(), "Should not have any properties.");
47 }
49 function* testCancelNewOnEscape(inspector, ruleView) {
50 // Start at the beginning: start to add a rule to the element's style
51 // declaration, add some text, then press escape.
53 let elementRuleEditor = ruleView.element.children[0]._ruleEditor;
54 let editor = yield focusEditableField(elementRuleEditor.closeBrace);
56 is(inplaceEditor(elementRuleEditor.newPropSpan), editor, "Next focused editor should be the new property editor.");
57 for (let ch of "background") {
58 EventUtils.sendChar(ch, ruleView.doc.defaultView);
59 }
61 let onBlur = once(editor.input, "blur");
62 EventUtils.synthesizeKey("VK_ESCAPE", {});
63 yield onBlur;
65 ok(!elementRuleEditor.rule._applyingModifications, "Shouldn't have an outstanding modification request after a cancel.");
66 is(elementRuleEditor.rule.textProps.length, 0, "Should have canceled creating a new text property.");
67 ok(!elementRuleEditor.propertyList.hasChildNodes(), "Should not have any properties.");
68 }