browser/devtools/styleinspector/test/browser_ruleview_user-property-reset.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 that user set style properties can be changed from the markup-view and
michael@0 8 // don't survive page reload
michael@0 9
michael@0 10 let TEST_PAGE = [
michael@0 11 "data:text/html,",
michael@0 12 "<p id='id1' style='width:200px;'>element 1</p>",
michael@0 13 "<p id='id2' style='width:100px;'>element 2</p>"
michael@0 14 ].join("");
michael@0 15
michael@0 16 let test = asyncTest(function*() {
michael@0 17 yield addTab(TEST_PAGE);
michael@0 18 let {toolbox, inspector, view} = yield openRuleView();
michael@0 19
michael@0 20 yield selectNode("#id1", inspector);
michael@0 21 yield modifyRuleViewWidth("300px", view, inspector);
michael@0 22 assertRuleAndMarkupViewWidth("id1", "300px", view, inspector);
michael@0 23
michael@0 24 yield selectNode("#id2", inspector);
michael@0 25 assertRuleAndMarkupViewWidth("id2", "100px", view, inspector);
michael@0 26 yield modifyRuleViewWidth("50px", view, inspector);
michael@0 27 assertRuleAndMarkupViewWidth("id2", "50px", view, inspector);
michael@0 28
michael@0 29 yield reloadPage(inspector);
michael@0 30
michael@0 31 yield selectNode("#id1", inspector);
michael@0 32 assertRuleAndMarkupViewWidth("id1", "200px", view, inspector);
michael@0 33 yield selectNode("#id2", inspector);
michael@0 34 assertRuleAndMarkupViewWidth("id2", "100px", view, inspector);
michael@0 35 });
michael@0 36
michael@0 37 function getStyleRule(ruleView) {
michael@0 38 return ruleView.doc.querySelector(".ruleview-rule");
michael@0 39 }
michael@0 40
michael@0 41 function* modifyRuleViewWidth(value, ruleView, inspector) {
michael@0 42 info("Getting the property value element");
michael@0 43 let valueSpan = getStyleRule(ruleView).querySelector(".ruleview-propertyvalue");
michael@0 44
michael@0 45 info("Focusing the property value to set it to edit mode");
michael@0 46 let editor = yield focusEditableField(valueSpan.parentNode);
michael@0 47
michael@0 48 ok(editor.input, "The inplace-editor field is ready");
michael@0 49 info("Setting the new value");
michael@0 50 editor.input.value = value;
michael@0 51
michael@0 52 info("Pressing return and waiting for the field to blur and for the markup-view to show the mutation");
michael@0 53 let onBlur = once(editor.input, "blur", true);
michael@0 54 let onMutation = inspector.once("markupmutation");
michael@0 55 EventUtils.sendKey("return");
michael@0 56 yield onBlur;
michael@0 57 yield onMutation;
michael@0 58
michael@0 59 info("Escaping out of the new property field that has been created after the value was edited");
michael@0 60 let onNewFieldBlur = once(ruleView.doc.activeElement, "blur", true);
michael@0 61 EventUtils.sendKey("escape");
michael@0 62 yield onNewFieldBlur;
michael@0 63 }
michael@0 64
michael@0 65 function getContainerStyleAttrValue(id, {markup}) {
michael@0 66 let front = markup.walker.frontForRawNode(content.document.getElementById(id));
michael@0 67 let container = markup.getContainer(front);
michael@0 68
michael@0 69 let attrIndex = 0;
michael@0 70 for (let attrName of container.elt.querySelectorAll(".attr-name")) {
michael@0 71 if (attrName.textContent === "style") {
michael@0 72 return container.elt.querySelectorAll(".attr-value")[attrIndex];
michael@0 73 }
michael@0 74 attrIndex ++;
michael@0 75 }
michael@0 76 }
michael@0 77
michael@0 78 function assertRuleAndMarkupViewWidth(id, value, ruleView, inspector) {
michael@0 79 let valueSpan = getStyleRule(ruleView).querySelector(".ruleview-propertyvalue");
michael@0 80 is(valueSpan.textContent, value, "Rule-view style width is " + value + " as expected");
michael@0 81
michael@0 82 let attr = getContainerStyleAttrValue(id, inspector);
michael@0 83 is(attr.textContent.replace(/\s/g, ""), "width:" + value + ";", "Markup-view style attribute width is " + value);
michael@0 84 }
michael@0 85
michael@0 86 function reloadPage(inspector) {
michael@0 87 let onNewRoot = inspector.once("new-root");
michael@0 88 content.location.reload();
michael@0 89 return onNewRoot.then(inspector.markup._waitForChildren);
michael@0 90 }

mercurial