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

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/browser/devtools/styleinspector/test/browser_ruleview_add-property-cancel_03.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,68 @@
     1.4 +/* vim: set ft=javascript ts=2 et sw=2 tw=80: */
     1.5 +/* Any copyright is dedicated to the Public Domain.
     1.6 + http://creativecommons.org/publicdomain/zero/1.0/ */
     1.7 +
     1.8 +"use strict";
     1.9 +
    1.10 +// Test cancelling the addition of a new property in the rule-view
    1.11 +
    1.12 +let test = asyncTest(function*() {
    1.13 +  yield addTab("data:text/html;charset=utf-8,browser_ruleview_ui.js");
    1.14 +  let {toolbox, inspector, view} = yield openRuleView();
    1.15 +
    1.16 +  info("Creating the test document");
    1.17 +  let style = "" +
    1.18 +    "#testid {" +
    1.19 +    "  background-color: blue;" +
    1.20 +    "}" +
    1.21 +    ".testclass, .unmatched {" +
    1.22 +    "  background-color: green;" +
    1.23 +    "}";
    1.24 +  let styleNode = addStyle(content.document, style);
    1.25 +  content.document.body.innerHTML = "<div id='testid' class='testclass'>Styled Node</div>" +
    1.26 +                                    "<div id='testid2'>Styled Node</div>";
    1.27 +
    1.28 +  yield testCancelNew(inspector, view);
    1.29 +  yield testCancelNewOnEscape(inspector, view);
    1.30 +  yield inspector.once("inspector-updated");
    1.31 +});
    1.32 +
    1.33 +function* testCancelNew(inspector, ruleView) {
    1.34 +  // Start at the beginning: start to add a rule to the element's style
    1.35 +  // declaration, but leave it empty.
    1.36 +
    1.37 +  let elementRuleEditor = ruleView.element.children[0]._ruleEditor;
    1.38 +  let editor = yield focusEditableField(elementRuleEditor.closeBrace);
    1.39 +
    1.40 +  is(inplaceEditor(elementRuleEditor.newPropSpan), editor,
    1.41 +    "Property editor is focused");
    1.42 +
    1.43 +  let onBlur = once(editor.input, "blur");
    1.44 +  editor.input.blur();
    1.45 +  yield onBlur;
    1.46 +
    1.47 +  ok(!elementRuleEditor.rule._applyingModifications, "Shouldn't have an outstanding modification request after a cancel.");
    1.48 +  is(elementRuleEditor.rule.textProps.length, 0, "Should have canceled creating a new text property.");
    1.49 +  ok(!elementRuleEditor.propertyList.hasChildNodes(), "Should not have any properties.");
    1.50 +}
    1.51 +
    1.52 +function* testCancelNewOnEscape(inspector, ruleView) {
    1.53 +  // Start at the beginning: start to add a rule to the element's style
    1.54 +  // declaration, add some text, then press escape.
    1.55 +
    1.56 +  let elementRuleEditor = ruleView.element.children[0]._ruleEditor;
    1.57 +  let editor = yield focusEditableField(elementRuleEditor.closeBrace);
    1.58 +
    1.59 +  is(inplaceEditor(elementRuleEditor.newPropSpan), editor, "Next focused editor should be the new property editor.");
    1.60 +  for (let ch of "background") {
    1.61 +    EventUtils.sendChar(ch, ruleView.doc.defaultView);
    1.62 +  }
    1.63 +
    1.64 +  let onBlur = once(editor.input, "blur");
    1.65 +  EventUtils.synthesizeKey("VK_ESCAPE", {});
    1.66 +  yield onBlur;
    1.67 +
    1.68 +  ok(!elementRuleEditor.rule._applyingModifications, "Shouldn't have an outstanding modification request after a cancel.");
    1.69 +  is(elementRuleEditor.rule.textProps.length, 0, "Should have canceled creating a new text property.");
    1.70 +  ok(!elementRuleEditor.propertyList.hasChildNodes(), "Should not have any properties.");
    1.71 +}

mercurial