browser/devtools/responsivedesign/test/browser_responsive_devicewidth.js

Wed, 31 Dec 2014 06:55:46 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:55:46 +0100
changeset 1
ca08bd8f51b2
permissions
-rw-r--r--

Added tag TORBROWSER_REPLICA for changeset 6474c204b198

     1 /* Any copyright is dedicated to the Public Domain.
     2 http://creativecommons.org/publicdomain/zero/1.0/ */
     4 function test() {
     5   let instance;
     6   let mgr = ResponsiveUI.ResponsiveUIManager;
     8   waitForExplicitFinish();
    10   gBrowser.selectedTab = gBrowser.addTab();
    11   gBrowser.selectedBrowser.addEventListener("load", function onload() {
    12     gBrowser.selectedBrowser.removeEventListener("load", onload, true);
    13     waitForFocus(startTest, content);
    14   }, true);
    16   content.location = "data:text/html,mop";
    18   function startTest() {
    19     mgr.once("on", function() {executeSoon(onUIOpen)});
    20     document.getElementById("Tools:ResponsiveUI").doCommand();
    21   }
    23   function onUIOpen() {
    24     instance = gBrowser.selectedTab.__responsiveUI;
    25     instance.stack.setAttribute("notransition", "true");
    26     ok(instance, "instance of the module is attached to the tab.");
    28     instance.setSize(110, 500);
    29     ok(content.innerWidth, 110, "initial width is valid");
    31     let mql = content.matchMedia("(max-device-width:100px)")
    33     ok(!mql.matches, "media query doesn't match.");
    35     mql.addListener(onMediaChange);
    36     instance.setSize(90, 500);
    37   }
    39   function onMediaChange(mql) {
    40     mql.removeListener(onMediaChange);
    41     ok(mql.matches, "media query matches.");
    42     ok(window.screen.width != content.screen.width, "screen.width is not the size of the screen.");
    43     is(content.screen.width, 90, "screen.width is the width of the page.");
    44     is(content.screen.height, 500, "screen.height is the height of the page.");
    47     let docShell = content.QueryInterface(Ci.nsIInterfaceRequestor)
    48                           .getInterface(Ci.nsIWebNavigation)
    49                           .QueryInterface(Ci.nsIDocShell);
    51     mql.addListener(onMediaChange2);
    52     docShell.deviceSizeIsPageSize = false;
    53   }
    55   function onMediaChange2(mql) {
    56     mql.removeListener(onMediaChange);
    57     ok(!mql.matches, "media query has been re-evaluated.");
    58     ok(window.screen.width == content.screen.width, "screen.width is not the size of the screen.");
    59     instance.stack.removeAttribute("notransition");
    60     document.getElementById("Tools:ResponsiveUI").doCommand();
    61     gBrowser.removeCurrentTab();
    62     finish();
    63   }
    64 }

mercurial