michael@0: /* vim: set ft=javascript ts=2 et sw=2 tw=80: */
michael@0: /* Any copyright is dedicated to the Public Domain.
michael@0: http://creativecommons.org/publicdomain/zero/1.0/ */
michael@0:
michael@0: "use strict";
michael@0:
michael@0: // Test cancelling the addition of a new property in the rule-view
michael@0:
michael@0: let test = asyncTest(function*() {
michael@0: yield addTab("data:text/html;charset=utf-8,browser_ruleview_ui.js");
michael@0: let {toolbox, inspector, view} = yield openRuleView();
michael@0:
michael@0: info("Creating the test document");
michael@0: let style = "" +
michael@0: "#testid {" +
michael@0: " background-color: blue;" +
michael@0: "}" +
michael@0: ".testclass, .unmatched {" +
michael@0: " background-color: green;" +
michael@0: "}";
michael@0: let styleNode = addStyle(content.document, style);
michael@0: content.document.body.innerHTML = "
Styled Node
" +
michael@0: "Styled Node
";
michael@0:
michael@0: yield testCancelNew(inspector, view);
michael@0: yield testCancelNewOnEscape(inspector, view);
michael@0: yield inspector.once("inspector-updated");
michael@0: });
michael@0:
michael@0: function* testCancelNew(inspector, ruleView) {
michael@0: // Start at the beginning: start to add a rule to the element's style
michael@0: // declaration, but leave it empty.
michael@0:
michael@0: let elementRuleEditor = ruleView.element.children[0]._ruleEditor;
michael@0: let editor = yield focusEditableField(elementRuleEditor.closeBrace);
michael@0:
michael@0: is(inplaceEditor(elementRuleEditor.newPropSpan), editor,
michael@0: "Property editor is focused");
michael@0:
michael@0: let onBlur = once(editor.input, "blur");
michael@0: editor.input.blur();
michael@0: yield onBlur;
michael@0:
michael@0: ok(!elementRuleEditor.rule._applyingModifications, "Shouldn't have an outstanding modification request after a cancel.");
michael@0: is(elementRuleEditor.rule.textProps.length, 0, "Should have canceled creating a new text property.");
michael@0: ok(!elementRuleEditor.propertyList.hasChildNodes(), "Should not have any properties.");
michael@0: }
michael@0:
michael@0: function* testCancelNewOnEscape(inspector, ruleView) {
michael@0: // Start at the beginning: start to add a rule to the element's style
michael@0: // declaration, add some text, then press escape.
michael@0:
michael@0: let elementRuleEditor = ruleView.element.children[0]._ruleEditor;
michael@0: let editor = yield focusEditableField(elementRuleEditor.closeBrace);
michael@0:
michael@0: is(inplaceEditor(elementRuleEditor.newPropSpan), editor, "Next focused editor should be the new property editor.");
michael@0: for (let ch of "background") {
michael@0: EventUtils.sendChar(ch, ruleView.doc.defaultView);
michael@0: }
michael@0:
michael@0: let onBlur = once(editor.input, "blur");
michael@0: EventUtils.synthesizeKey("VK_ESCAPE", {});
michael@0: yield onBlur;
michael@0:
michael@0: ok(!elementRuleEditor.rule._applyingModifications, "Shouldn't have an outstanding modification request after a cancel.");
michael@0: is(elementRuleEditor.rule.textProps.length, 0, "Should have canceled creating a new text property.");
michael@0: ok(!elementRuleEditor.propertyList.hasChildNodes(), "Should not have any properties.");
michael@0: }