browser/devtools/styleinspector/test/browser_ruleview_edit-property_02.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* vim: set ft=javascript ts=2 et sw=2 tw=80: */
michael@0 2 /* Any copyright is dedicated to the Public Domain.
michael@0 3 http://creativecommons.org/publicdomain/zero/1.0/ */
michael@0 4
michael@0 5 "use strict";
michael@0 6
michael@0 7 // Test several types of rule-view property edition
michael@0 8
michael@0 9 let test = asyncTest(function*() {
michael@0 10 yield addTab("data:text/html;charset=utf-8,browser_ruleview_ui.js");
michael@0 11 let {toolbox, inspector, view} = yield openRuleView();
michael@0 12
michael@0 13 info("Creating the test document");
michael@0 14 let style = "" +
michael@0 15 "#testid {" +
michael@0 16 " background-color: blue;" +
michael@0 17 "}" +
michael@0 18 ".testclass, .unmatched {" +
michael@0 19 " background-color: green;" +
michael@0 20 "}";
michael@0 21 let styleNode = addStyle(content.document, style);
michael@0 22 content.document.body.innerHTML = "<div id='testid' class='testclass'>Styled Node</div>" +
michael@0 23 "<div id='testid2'>Styled Node</div>";
michael@0 24
michael@0 25 yield selectNode("#testid", inspector);
michael@0 26 yield testEditProperty(inspector, view);
michael@0 27 yield testDisableProperty(inspector, view);
michael@0 28 yield testPropertyStillMarkedDirty(inspector, view);
michael@0 29 });
michael@0 30
michael@0 31 function* testEditProperty(inspector, ruleView) {
michael@0 32 let idRuleEditor = ruleView.element.children[1]._ruleEditor;
michael@0 33 let propEditor = idRuleEditor.rule.textProps[0].editor;
michael@0 34
michael@0 35 let editor = yield focusEditableField(propEditor.nameSpan);
michael@0 36 let input = editor.input;
michael@0 37 is(inplaceEditor(propEditor.nameSpan), editor, "Next focused editor should be the name editor.");
michael@0 38
michael@0 39 ok(input.selectionStart === 0 && input.selectionEnd === input.value.length, "Editor contents are selected.");
michael@0 40
michael@0 41 // Try clicking on the editor's input again, shouldn't cause trouble (see bug 761665).
michael@0 42 EventUtils.synthesizeMouse(input, 1, 1, {}, ruleView.doc.defaultView);
michael@0 43 input.select();
michael@0 44
michael@0 45 info("Entering property name followed by a colon to focus the value");
michael@0 46 let onFocus = once(idRuleEditor.element, "focus", true);
michael@0 47 for (let ch of "border-color:") {
michael@0 48 EventUtils.sendChar(ch, ruleView.doc.defaultView);
michael@0 49 }
michael@0 50 yield onFocus;
michael@0 51 yield idRuleEditor.rule._applyingModifications;
michael@0 52
michael@0 53 info("Verifying that the focused field is the valueSpan");
michael@0 54 editor = inplaceEditor(ruleView.doc.activeElement);
michael@0 55 input = editor.input;
michael@0 56 is(inplaceEditor(propEditor.valueSpan), editor, "Focus should have moved to the value.");
michael@0 57 ok(input.selectionStart === 0 && input.selectionEnd === input.value.length, "Editor contents are selected.");
michael@0 58
michael@0 59 info("Entering a value following by a semi-colon to commit it");
michael@0 60 let onBlur = once(editor.input, "blur");
michael@0 61 for (let ch of "red;") {
michael@0 62 EventUtils.sendChar(ch, ruleView.doc.defaultView);
michael@0 63 is(propEditor.warning.hidden, true,
michael@0 64 "warning triangle is hidden or shown as appropriate");
michael@0 65 }
michael@0 66 yield onBlur;
michael@0 67 yield idRuleEditor.rule._applyingModifications;
michael@0 68
michael@0 69 is(idRuleEditor.rule.style._rawStyle().getPropertyValue("border-color"), "red",
michael@0 70 "border-color should have been set.");
michael@0 71
michael@0 72 let props = ruleView.element.querySelectorAll(".ruleview-property");
michael@0 73 for (let i = 0; i < props.length; i++) {
michael@0 74 is(props[i].hasAttribute("dirty"), i <= 0,
michael@0 75 "props[" + i + "] marked dirty as appropriate");
michael@0 76 }
michael@0 77 }
michael@0 78
michael@0 79 function* testDisableProperty(inspector, ruleView) {
michael@0 80 let idRuleEditor = ruleView.element.children[1]._ruleEditor;
michael@0 81 let propEditor = idRuleEditor.rule.textProps[0].editor;
michael@0 82
michael@0 83 info("Disabling a property");
michael@0 84 propEditor.enable.click();
michael@0 85 yield idRuleEditor.rule._applyingModifications;
michael@0 86 is(idRuleEditor.rule.style._rawStyle().getPropertyValue("border-color"), "",
michael@0 87 "Border-color should have been unset.");
michael@0 88
michael@0 89 info("Enabling the property again");
michael@0 90 propEditor.enable.click();
michael@0 91 yield idRuleEditor.rule._applyingModifications;
michael@0 92 is(idRuleEditor.rule.style._rawStyle().getPropertyValue("border-color"), "red",
michael@0 93 "Border-color should have been reset.");
michael@0 94 }
michael@0 95
michael@0 96 function* testPropertyStillMarkedDirty(inspector, ruleView) {
michael@0 97 // Select an unstyled node.
michael@0 98 yield selectNode("#testid2", inspector);
michael@0 99
michael@0 100 // Select the original node again.
michael@0 101 yield selectNode("#testid", inspector);
michael@0 102
michael@0 103 let props = ruleView.element.querySelectorAll(".ruleview-property");
michael@0 104 for (let i = 0; i < props.length; i++) {
michael@0 105 is(props[i].hasAttribute("dirty"), i <= 0,
michael@0 106 "props[" + i + "] marked dirty as appropriate");
michael@0 107 }
michael@0 108 }

mercurial