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.

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

mercurial