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