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 testEditProperty(view, "border-color", "red");
michael@0: yield testEditProperty(view, "background-image", TEST_URL);
michael@0: });
michael@0:
michael@0: function* testEditProperty(view, name, value) {
michael@0: info("Test editing existing property name/value fields");
michael@0:
michael@0: let idRuleEditor = view.element.children[1]._ruleEditor;
michael@0: let propEditor = idRuleEditor.rule.textProps[0].editor;
michael@0:
michael@0: info("Focusing an existing property name in the rule-view");
michael@0: let editor = yield focusEditableField(propEditor.nameSpan, 32, 1);
michael@0:
michael@0: is(inplaceEditor(propEditor.nameSpan), editor, "The property name editor got focused");
michael@0: let input = editor.input;
michael@0:
michael@0: info("Entering a new property name, including : to commit and focus the value");
michael@0: let onValueFocus = once(idRuleEditor.element, "focus", true);
michael@0: let onModifications = idRuleEditor.rule._applyingModifications;
michael@0: for (let ch of name + ":") {
michael@0: EventUtils.sendChar(ch, view.doc.defaultView);
michael@0: }
michael@0: yield onValueFocus;
michael@0: yield onModifications;
michael@0:
michael@0: // Getting the value editor after focus
michael@0: editor = inplaceEditor(view.doc.activeElement);
michael@0: input = editor.input;
michael@0: is(inplaceEditor(propEditor.valueSpan), editor, "Focus moved to the value.");
michael@0:
michael@0: info("Entering a new value, including ; to commit and blur the value");
michael@0: let onBlur = once(input, "blur");
michael@0: let onModifications = idRuleEditor.rule._applyingModifications;
michael@0: for (let ch of value + ";") {
michael@0: EventUtils.sendChar(ch, view.doc.defaultView);
michael@0: }
michael@0: yield onBlur;
michael@0: yield onModifications;
michael@0:
michael@0: let propValue = idRuleEditor.rule.domRule._rawStyle().getPropertyValue(name);
michael@0: is(propValue, value, name + " should have been set.");
michael@0: is(propEditor.isValid(), true, value + " should be a valid entry");
michael@0: }