1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/devtools/styleinspector/test/browser_ruleview_add-property-cancel_02.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,84 @@ 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 +// Testing various inplace-editor behaviors in the rule-view 1.11 +// FIXME: To be split in several test files, and some of the inplace-editor 1.12 +// focus/blur/commit/revert stuff should be factored out in head.js 1.13 + 1.14 +let TEST_URL = 'url("' + TEST_URL_ROOT + 'doc_test_image.png")'; 1.15 +let PAGE_CONTENT = [ 1.16 + '<style type="text/css">', 1.17 + ' #testid {', 1.18 + ' background-color: blue;', 1.19 + ' }', 1.20 + ' .testclass {', 1.21 + ' background-color: green;', 1.22 + ' }', 1.23 + '</style>', 1.24 + '<div id="testid" class="testclass" style="background-color:red;">Styled Node</div>' 1.25 +].join("\n"); 1.26 + 1.27 +let test = asyncTest(function*() { 1.28 + yield addTab("data:text/html,test rule view user changes"); 1.29 + 1.30 + info("Creating the test document"); 1.31 + content.document.body.innerHTML = PAGE_CONTENT; 1.32 + 1.33 + info("Opening the rule-view"); 1.34 + let {toolbox, inspector, view} = yield openRuleView(); 1.35 + 1.36 + info("Selecting the test element"); 1.37 + yield selectNode("#testid", inspector); 1.38 + 1.39 + yield testCreateNewEscape(view); 1.40 +}); 1.41 + 1.42 +function* testCreateNewEscape(view) { 1.43 + info("Test creating a new property and escaping"); 1.44 + 1.45 + let elementRuleEditor = view.element.children[0]._ruleEditor; 1.46 + 1.47 + info("Focusing a new property name in the rule-view"); 1.48 + let editor = yield focusEditableField(elementRuleEditor.closeBrace); 1.49 + 1.50 + is(inplaceEditor(elementRuleEditor.newPropSpan), editor, "The new property editor got focused."); 1.51 + let input = editor.input; 1.52 + 1.53 + info("Entering a value in the property name editor"); 1.54 + input.value = "color"; 1.55 + 1.56 + info("Pressing return to commit and focus the new value field"); 1.57 + let onValueFocus = once(elementRuleEditor.element, "focus", true); 1.58 + let onModifications = elementRuleEditor.rule._applyingModifications; 1.59 + EventUtils.synthesizeKey("VK_RETURN", {}, view.doc.defaultView); 1.60 + yield onValueFocus; 1.61 + yield onModifications; 1.62 + 1.63 + // Getting the new value editor after focus 1.64 + editor = inplaceEditor(view.doc.activeElement); 1.65 + let textProp = elementRuleEditor.rule.textProps[1]; 1.66 + 1.67 + is(elementRuleEditor.rule.textProps.length, 2, "Created a new text property."); 1.68 + is(elementRuleEditor.propertyList.children.length, 2, "Created a property editor."); 1.69 + is(editor, inplaceEditor(textProp.editor.valueSpan), "Editing the value span now."); 1.70 + 1.71 + info("Entering a property value"); 1.72 + editor.input.value = "red"; 1.73 + 1.74 + info("Escaping out of the field"); 1.75 + EventUtils.synthesizeKey("VK_ESCAPE", {}, view.doc.defaultView); 1.76 + 1.77 + info("Checking that the previous field is focused"); 1.78 + let focusedElement = inplaceEditor(elementRuleEditor.rule.textProps[0].editor.valueSpan).input; 1.79 + is(focusedElement, focusedElement.ownerDocument.activeElement, "Correct element has focus"); 1.80 + 1.81 + let onModifications = elementRuleEditor.rule._applyingModifications; 1.82 + EventUtils.synthesizeKey("VK_ESCAPE", {}, view.doc.defaultView); 1.83 + yield onModifications; 1.84 + 1.85 + is(elementRuleEditor.rule.textProps.length, 1, "Removed the new text property."); 1.86 + is(elementRuleEditor.propertyList.children.length, 1, "Removed the property editor."); 1.87 +}