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 several types of rule-view property edition
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 selectNode("#testid", inspector);
michael@0: yield testEditProperty(inspector, view);
michael@0: yield testDisableProperty(inspector, view);
michael@0: yield testPropertyStillMarkedDirty(inspector, view);
michael@0: });
michael@0:
michael@0: function* testEditProperty(inspector, ruleView) {
michael@0: let idRuleEditor = ruleView.element.children[1]._ruleEditor;
michael@0: let propEditor = idRuleEditor.rule.textProps[0].editor;
michael@0:
michael@0: let editor = yield focusEditableField(propEditor.nameSpan);
michael@0: let input = editor.input;
michael@0: is(inplaceEditor(propEditor.nameSpan), editor, "Next focused editor should be the name editor.");
michael@0:
michael@0: ok(input.selectionStart === 0 && input.selectionEnd === input.value.length, "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 property name followed by a colon to focus the value");
michael@0: let onFocus = once(idRuleEditor.element, "focus", true);
michael@0: for (let ch of "border-color:") {
michael@0: EventUtils.sendChar(ch, ruleView.doc.defaultView);
michael@0: }
michael@0: yield onFocus;
michael@0: yield idRuleEditor.rule._applyingModifications;
michael@0:
michael@0: info("Verifying that the focused field is the valueSpan");
michael@0: editor = inplaceEditor(ruleView.doc.activeElement);
michael@0: input = editor.input;
michael@0: is(inplaceEditor(propEditor.valueSpan), editor, "Focus should have moved to the value.");
michael@0: ok(input.selectionStart === 0 && input.selectionEnd === input.value.length, "Editor contents are selected.");
michael@0:
michael@0: info("Entering a value following by a semi-colon to commit it");
michael@0: let onBlur = once(editor.input, "blur");
michael@0: for (let ch of "red;") {
michael@0: EventUtils.sendChar(ch, ruleView.doc.defaultView);
michael@0: is(propEditor.warning.hidden, true,
michael@0: "warning triangle is hidden or shown as appropriate");
michael@0: }
michael@0: yield onBlur;
michael@0: yield idRuleEditor.rule._applyingModifications;
michael@0:
michael@0: is(idRuleEditor.rule.style._rawStyle().getPropertyValue("border-color"), "red",
michael@0: "border-color should have been set.");
michael@0:
michael@0: let props = ruleView.element.querySelectorAll(".ruleview-property");
michael@0: for (let i = 0; i < props.length; i++) {
michael@0: is(props[i].hasAttribute("dirty"), i <= 0,
michael@0: "props[" + i + "] marked dirty as appropriate");
michael@0: }
michael@0: }
michael@0:
michael@0: function* testDisableProperty(inspector, ruleView) {
michael@0: let idRuleEditor = ruleView.element.children[1]._ruleEditor;
michael@0: let propEditor = idRuleEditor.rule.textProps[0].editor;
michael@0:
michael@0: info("Disabling a property");
michael@0: propEditor.enable.click();
michael@0: yield idRuleEditor.rule._applyingModifications;
michael@0: is(idRuleEditor.rule.style._rawStyle().getPropertyValue("border-color"), "",
michael@0: "Border-color should have been unset.");
michael@0:
michael@0: info("Enabling the property again");
michael@0: propEditor.enable.click();
michael@0: yield idRuleEditor.rule._applyingModifications;
michael@0: is(idRuleEditor.rule.style._rawStyle().getPropertyValue("border-color"), "red",
michael@0: "Border-color should have been reset.");
michael@0: }
michael@0:
michael@0: function* testPropertyStillMarkedDirty(inspector, ruleView) {
michael@0: // Select an unstyled node.
michael@0: yield selectNode("#testid2", inspector);
michael@0:
michael@0: // Select the original node again.
michael@0: yield selectNode("#testid", inspector);
michael@0:
michael@0: let props = ruleView.element.querySelectorAll(".ruleview-property");
michael@0: for (let i = 0; i < props.length; i++) {
michael@0: is(props[i].hasAttribute("dirty"), i <= 0,
michael@0: "props[" + i + "] marked dirty as appropriate");
michael@0: }
michael@0: }