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: // Testing various inplace-editor behaviors in the rule-view michael@0: // FIXME: To be split in several test files, and some of the inplace-editor michael@0: // focus/blur/commit/revert stuff should be factored out in head.js michael@0: michael@0: let TEST_URL = 'url("' + TEST_URL_ROOT + 'doc_test_image.png")'; michael@0: let PAGE_CONTENT = [ michael@0: '', michael@0: '
Styled Node
' michael@0: ].join("\n"); michael@0: michael@0: let test = asyncTest(function*() { michael@0: yield addTab("data:text/html,test rule view user changes"); michael@0: michael@0: info("Creating the test document"); michael@0: content.document.body.innerHTML = PAGE_CONTENT; michael@0: michael@0: info("Opening the rule-view"); michael@0: let {toolbox, inspector, view} = yield openRuleView(); michael@0: michael@0: info("Selecting the test element"); michael@0: yield selectNode("#testid", inspector); michael@0: michael@0: yield testCreateNewEscape(view); michael@0: }); michael@0: michael@0: function* testCreateNewEscape(view) { michael@0: info("Test creating a new property and escaping"); michael@0: michael@0: let elementRuleEditor = view.element.children[0]._ruleEditor; michael@0: michael@0: info("Focusing a new property name in the rule-view"); michael@0: let editor = yield focusEditableField(elementRuleEditor.closeBrace); michael@0: michael@0: is(inplaceEditor(elementRuleEditor.newPropSpan), editor, "The new property editor got focused."); michael@0: let input = editor.input; michael@0: michael@0: info("Entering a value in the property name editor"); michael@0: input.value = "color"; michael@0: michael@0: info("Pressing return to commit and focus the new value field"); michael@0: let onValueFocus = once(elementRuleEditor.element, "focus", true); michael@0: let onModifications = elementRuleEditor.rule._applyingModifications; michael@0: EventUtils.synthesizeKey("VK_RETURN", {}, view.doc.defaultView); michael@0: yield onValueFocus; michael@0: yield onModifications; michael@0: michael@0: // Getting the new value editor after focus michael@0: editor = inplaceEditor(view.doc.activeElement); michael@0: let textProp = elementRuleEditor.rule.textProps[1]; michael@0: michael@0: is(elementRuleEditor.rule.textProps.length, 2, "Created a new text property."); michael@0: is(elementRuleEditor.propertyList.children.length, 2, "Created a property editor."); michael@0: is(editor, inplaceEditor(textProp.editor.valueSpan), "Editing the value span now."); michael@0: michael@0: info("Entering a property value"); michael@0: editor.input.value = "red"; michael@0: michael@0: info("Escaping out of the field"); michael@0: EventUtils.synthesizeKey("VK_ESCAPE", {}, view.doc.defaultView); michael@0: michael@0: info("Checking that the previous field is focused"); michael@0: let focusedElement = inplaceEditor(elementRuleEditor.rule.textProps[0].editor.valueSpan).input; michael@0: is(focusedElement, focusedElement.ownerDocument.activeElement, "Correct element has focus"); michael@0: michael@0: let onModifications = elementRuleEditor.rule._applyingModifications; michael@0: EventUtils.synthesizeKey("VK_ESCAPE", {}, view.doc.defaultView); michael@0: yield onModifications; michael@0: michael@0: is(elementRuleEditor.rule.textProps.length, 1, "Removed the new text property."); michael@0: is(elementRuleEditor.propertyList.children.length, 1, "Removed the property editor."); michael@0: }