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: // Test all sorts of additions and updates of properties in the rule-view
michael@0: // FIXME: TO BE SPLIT IN *MANY* SMALLER TESTS
michael@0:
michael@0: let test = asyncTest(function*() {
michael@0: yield addTab("data:text/html;charset=utf-8,browser_ruleview_ui.js");
michael@0: let {toolbox, inspector, view} = yield openRuleView();
michael@0:
michael@0: info("Creating the test document");
michael@0: let style = "" +
michael@0: "#testid {" +
michael@0: " background-color: blue;" +
michael@0: "}" +
michael@0: ".testclass, .unmatched {" +
michael@0: " background-color: green;" +
michael@0: "}";
michael@0: let styleNode = addStyle(content.document, style);
michael@0: content.document.body.innerHTML = "
Styled Node
" +
michael@0: "Styled Node
";
michael@0:
michael@0: yield testCreateNew(inspector, view);
michael@0: yield inspector.once("inspector-updated");
michael@0: });
michael@0:
michael@0: function* testCreateNew(inspector, ruleView) {
michael@0: // Create a new property.
michael@0: let elementRuleEditor = ruleView.element.children[0]._ruleEditor;
michael@0: let editor = yield focusEditableField(elementRuleEditor.closeBrace);
michael@0:
michael@0: is(inplaceEditor(elementRuleEditor.newPropSpan), editor,
michael@0: "Next focused editor should be the new property editor.");
michael@0:
michael@0: let input = editor.input;
michael@0:
michael@0: ok(input.selectionStart === 0 && input.selectionEnd === input.value.length,
michael@0: "Editor contents are selected.");
michael@0:
michael@0: // Try clicking on the editor's input again, shouldn't cause trouble (see bug 761665).
michael@0: EventUtils.synthesizeMouse(input, 1, 1, {}, ruleView.doc.defaultView);
michael@0: input.select();
michael@0:
michael@0: info("Entering the property name");
michael@0: input.value = "background-color";
michael@0:
michael@0: info("Pressing RETURN and waiting for the value field focus");
michael@0: let onFocus = once(elementRuleEditor.element, "focus", true);
michael@0: EventUtils.sendKey("return", ruleView.doc.defaultView);
michael@0: yield onFocus;
michael@0: yield elementRuleEditor.rule._applyingModifications;
michael@0:
michael@0: editor = inplaceEditor(ruleView.doc.activeElement);
michael@0:
michael@0: is(elementRuleEditor.rule.textProps.length, 1, "Should have created a new text property.");
michael@0: is(elementRuleEditor.propertyList.children.length, 1, "Should have created a property editor.");
michael@0: let textProp = elementRuleEditor.rule.textProps[0];
michael@0: is(editor, inplaceEditor(textProp.editor.valueSpan), "Should be editing the value span now.");
michael@0:
michael@0: editor.input.value = "purple";
michael@0: let onBlur = once(editor.input, "blur");
michael@0: editor.input.blur();
michael@0: yield onBlur;
michael@0: yield elementRuleEditor.rule._applyingModifications;
michael@0:
michael@0: is(textProp.value, "purple", "Text prop should have been changed.");
michael@0: }