browser/devtools/responsivedesign/test/browser_responsiveruleview.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 test() {
     5   let instance;
     7   let ruleView;
     8   let inspector;
     9   let mgr = ResponsiveUI.ResponsiveUIManager;
    11   waitForExplicitFinish();
    13   gBrowser.selectedTab = gBrowser.addTab();
    14   gBrowser.selectedBrowser.addEventListener("load", function onload() {
    15     gBrowser.selectedBrowser.removeEventListener("load", onload, true);
    16     waitForFocus(startTest, content);
    17   }, true);
    19   content.location = "data:text/html;charset=utf-8,<html><style>" +
    20     "div {" +
    21     "  width: 500px;" +
    22     "  height: 10px;" +
    23     "  background: purple;" +
    24     "} " +
    25     "@media screen and (max-width: 200px) {" +
    26     "  div { " +
    27     "    width: 100px;" +
    28     "  }" +
    29     "};" +
    30     "</style><div></div></html>"
    32   function numberOfRules() {
    33     return ruleView.element.querySelectorAll(".ruleview-code").length;
    34   }
    36   function startTest() {
    37     document.getElementById("Tools:ResponsiveUI").doCommand();
    38     executeSoon(onUIOpen);
    39   }
    41   function onUIOpen() {
    42     instance = gBrowser.selectedTab.__responsiveUI;
    43     ok(instance, "instance of the module is attached to the tab.");
    45     instance.stack.setAttribute("notransition", "true");
    46     registerCleanupFunction(function() {
    47       instance.stack.removeAttribute("notransition");
    48     });
    50     instance.setSize(500, 500);
    52     openRuleView().then(onInspectorUIOpen);
    53   }
    55   function onInspectorUIOpen(args) {
    56     inspector = args.inspector;
    57     ruleView = args.view;
    58     ok(inspector, "Got inspector instance");
    60     let div = content.document.getElementsByTagName("div")[0];
    61     inspector.selection.setNode(div);
    62     inspector.once("inspector-updated", testShrink);
    63   }
    65   function testShrink() {
    67     is(numberOfRules(), 2, "Should have two rules initially.");
    69     ruleView.element.addEventListener("CssRuleViewRefreshed", function refresh() {
    70       ruleView.element.removeEventListener("CssRuleViewRefreshed", refresh, false);
    71       is(numberOfRules(), 3, "Should have three rules after shrinking.");
    72       testGrow();
    73     }, false);
    75     instance.setSize(100, 100);
    76   }
    78   function testGrow() {
    79     ruleView.element.addEventListener("CssRuleViewRefreshed", function refresh() {
    80       ruleView.element.removeEventListener("CssRuleViewRefreshed", refresh, false);
    81       is(numberOfRules(), 2, "Should have two rules after growing.");
    82       testEscapeCloses();
    83     }, false);
    85     instance.setSize(500, 500);
    86   }
    88   function testEscapeCloses() {
    89     is(document.getElementById("Tools:ResponsiveUI").getAttribute("checked"), "true", "menu checked");
    90     ok(!inspector._toolbox._splitConsole, "Console is not split.");
    92     mgr.once("off", function() {executeSoon(finishUp)});
    93     EventUtils.synthesizeKey("VK_ESCAPE", {});
    94   }
    96   function finishUp() {
    97     ok(!inspector._toolbox._splitConsole, "Console is still not split after pressing escape.");
    99     // Menus are correctly updated?
   100     is(document.getElementById("Tools:ResponsiveUI").getAttribute("checked"), "false", "menu unchecked");
   102     gBrowser.removeCurrentTab();
   103     finish();
   104   }
   105 }

mercurial