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 testCreateNew(view);
michael@0: });
michael@0:
michael@0: function* testCreateNew(view) {
michael@0: info("Test creating a new property");
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 background-color in the property name editor");
michael@0: input.value = "background-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[0];
michael@0:
michael@0: is(elementRuleEditor.rule.textProps.length, 1, "Created a new text property.");
michael@0: is(elementRuleEditor.propertyList.children.length, 1, "Created a property editor.");
michael@0: is(editor, inplaceEditor(textProp.editor.valueSpan), "Editing the value span now.");
michael@0:
michael@0: info("Entering a value and bluring the field to expect a rule change");
michael@0: editor.input.value = "#XYZ";
michael@0: let onBlur = once(editor.input, "blur");
michael@0: let onModifications = elementRuleEditor.rule._applyingModifications;
michael@0: editor.input.blur();
michael@0: yield onBlur;
michael@0: yield onModifications;
michael@0:
michael@0: is(textProp.value, "#XYZ", "Text prop should have been changed.");
michael@0: is(textProp.editor.isValid(), false, "#XYZ should not be a valid entry");
michael@0: }