browser/devtools/layoutview/test/browser_editablemodel_stylerules.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 /* Any copyright is dedicated to the Public Domain.
michael@0 2 http://creativecommons.org/publicdomain/zero/1.0/ */
michael@0 3
michael@0 4 function getStyle(node, property) {
michael@0 5 return node.style.getPropertyValue(property);
michael@0 6 }
michael@0 7
michael@0 8 let doc;
michael@0 9 let inspector;
michael@0 10
michael@0 11 let test = asyncTest(function*() {
michael@0 12 let style = "div { margin: 10px; padding: 3px } #div1 { margin-top: 5px } #div2 { border-bottom: 1em solid black; } #div3 { padding: 2em; }";
michael@0 13 let html = "<style>" + style + "</style><div id='div1'></div><div id='div2'></div><div id='div3'></div>"
michael@0 14
michael@0 15 let content = yield loadTab("data:text/html," + encodeURIComponent(html));
michael@0 16 doc = content.document;
michael@0 17
michael@0 18 let target = TargetFactory.forTab(gBrowser.selectedTab);
michael@0 19 let toolbox = yield gDevTools.showToolbox(target, "inspector");
michael@0 20 inspector = toolbox.getCurrentPanel();
michael@0 21
michael@0 22 inspector.sidebar.select("layoutview");
michael@0 23 yield inspector.sidebar.once("layoutview-ready");
michael@0 24 yield runTests();
michael@0 25 // TODO: Closing the toolbox in this test leaks - bug 994314
michael@0 26 // yield gDevTools.closeToolbox(target);
michael@0 27 });
michael@0 28
michael@0 29 addTest("Test that entering units works",
michael@0 30 function*() {
michael@0 31 let node = doc.getElementById("div1");
michael@0 32 is(getStyle(node, "padding-top"), "", "Should have the right padding");
michael@0 33 let view = yield selectNode(node);
michael@0 34
michael@0 35 let span = view.document.querySelector(".padding.top > span");
michael@0 36 is(span.textContent, 3, "Should have the right value in the box model.");
michael@0 37
michael@0 38 EventUtils.synthesizeMouseAtCenter(span, {}, view);
michael@0 39 let editor = view.document.querySelector(".styleinspector-propertyeditor");
michael@0 40 ok(editor, "Should have opened the editor.");
michael@0 41 is(editor.value, "3px", "Should have the right value in the editor.");
michael@0 42
michael@0 43 EventUtils.synthesizeKey("1", {}, view);
michael@0 44 yield waitForUpdate();
michael@0 45 EventUtils.synthesizeKey("e", {}, view);
michael@0 46 yield waitForUpdate();
michael@0 47
michael@0 48 is(getStyle(node, "padding-top"), "", "An invalid value is handled cleanly");
michael@0 49
michael@0 50 EventUtils.synthesizeKey("m", {}, view);
michael@0 51 yield waitForUpdate();
michael@0 52
michael@0 53 is(editor.value, "1em", "Should have the right value in the editor.");
michael@0 54 is(getStyle(node, "padding-top"), "1em", "Should have updated the padding.");
michael@0 55
michael@0 56 EventUtils.synthesizeKey("VK_RETURN", {}, view);
michael@0 57 yield waitForUpdate();
michael@0 58
michael@0 59 is(getStyle(node, "padding-top"), "1em", "Should be the right padding.")
michael@0 60 is(span.textContent, 16, "Should have the right value in the box model.");
michael@0 61 });
michael@0 62
michael@0 63 addTest("Test that we pick up the value from a higher style rule",
michael@0 64 function*() {
michael@0 65 let node = doc.getElementById("div2");
michael@0 66 is(getStyle(node, "border-bottom-width"), "", "Should have the right border-bottom-width");
michael@0 67 let view = yield selectNode(node);
michael@0 68
michael@0 69 let span = view.document.querySelector(".border.bottom > span");
michael@0 70 is(span.textContent, 16, "Should have the right value in the box model.");
michael@0 71
michael@0 72 EventUtils.synthesizeMouseAtCenter(span, {}, view);
michael@0 73 let editor = view.document.querySelector(".styleinspector-propertyeditor");
michael@0 74 ok(editor, "Should have opened the editor.");
michael@0 75 is(editor.value, "1em", "Should have the right value in the editor.");
michael@0 76
michael@0 77 EventUtils.synthesizeKey("0", {}, view);
michael@0 78 yield waitForUpdate();
michael@0 79
michael@0 80 is(editor.value, "0", "Should have the right value in the editor.");
michael@0 81 is(getStyle(node, "border-bottom-width"), "0px", "Should have updated the border.");
michael@0 82
michael@0 83 EventUtils.synthesizeKey("VK_RETURN", {}, view);
michael@0 84 yield waitForUpdate();
michael@0 85
michael@0 86 is(getStyle(node, "border-bottom-width"), "0px", "Should be the right border-bottom-width.")
michael@0 87 is(span.textContent, 0, "Should have the right value in the box model.");
michael@0 88 });
michael@0 89
michael@0 90 addTest("Test that shorthand properties are parsed correctly",
michael@0 91 function*() {
michael@0 92 let node = doc.getElementById("div3");
michael@0 93 is(getStyle(node, "padding-right"), "", "Should have the right padding");
michael@0 94 let view = yield selectNode(node);
michael@0 95
michael@0 96 let span = view.document.querySelector(".padding.right > span");
michael@0 97 is(span.textContent, 32, "Should have the right value in the box model.");
michael@0 98
michael@0 99 EventUtils.synthesizeMouseAtCenter(span, {}, view);
michael@0 100 let editor = view.document.querySelector(".styleinspector-propertyeditor");
michael@0 101 ok(editor, "Should have opened the editor.");
michael@0 102 is(editor.value, "2em", "Should have the right value in the editor.");
michael@0 103
michael@0 104 EventUtils.synthesizeKey("VK_RETURN", {}, view);
michael@0 105 yield waitForUpdate();
michael@0 106
michael@0 107 is(getStyle(node, "padding-right"), "", "Should be the right padding.")
michael@0 108 is(span.textContent, 32, "Should have the right value in the box model.");
michael@0 109 });

mercurial