browser/devtools/responsivedesign/test/browser_responsive_devicewidth.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 test() {
michael@0 5 let instance;
michael@0 6 let mgr = ResponsiveUI.ResponsiveUIManager;
michael@0 7
michael@0 8 waitForExplicitFinish();
michael@0 9
michael@0 10 gBrowser.selectedTab = gBrowser.addTab();
michael@0 11 gBrowser.selectedBrowser.addEventListener("load", function onload() {
michael@0 12 gBrowser.selectedBrowser.removeEventListener("load", onload, true);
michael@0 13 waitForFocus(startTest, content);
michael@0 14 }, true);
michael@0 15
michael@0 16 content.location = "data:text/html,mop";
michael@0 17
michael@0 18 function startTest() {
michael@0 19 mgr.once("on", function() {executeSoon(onUIOpen)});
michael@0 20 document.getElementById("Tools:ResponsiveUI").doCommand();
michael@0 21 }
michael@0 22
michael@0 23 function onUIOpen() {
michael@0 24 instance = gBrowser.selectedTab.__responsiveUI;
michael@0 25 instance.stack.setAttribute("notransition", "true");
michael@0 26 ok(instance, "instance of the module is attached to the tab.");
michael@0 27
michael@0 28 instance.setSize(110, 500);
michael@0 29 ok(content.innerWidth, 110, "initial width is valid");
michael@0 30
michael@0 31 let mql = content.matchMedia("(max-device-width:100px)")
michael@0 32
michael@0 33 ok(!mql.matches, "media query doesn't match.");
michael@0 34
michael@0 35 mql.addListener(onMediaChange);
michael@0 36 instance.setSize(90, 500);
michael@0 37 }
michael@0 38
michael@0 39 function onMediaChange(mql) {
michael@0 40 mql.removeListener(onMediaChange);
michael@0 41 ok(mql.matches, "media query matches.");
michael@0 42 ok(window.screen.width != content.screen.width, "screen.width is not the size of the screen.");
michael@0 43 is(content.screen.width, 90, "screen.width is the width of the page.");
michael@0 44 is(content.screen.height, 500, "screen.height is the height of the page.");
michael@0 45
michael@0 46
michael@0 47 let docShell = content.QueryInterface(Ci.nsIInterfaceRequestor)
michael@0 48 .getInterface(Ci.nsIWebNavigation)
michael@0 49 .QueryInterface(Ci.nsIDocShell);
michael@0 50
michael@0 51 mql.addListener(onMediaChange2);
michael@0 52 docShell.deviceSizeIsPageSize = false;
michael@0 53 }
michael@0 54
michael@0 55 function onMediaChange2(mql) {
michael@0 56 mql.removeListener(onMediaChange);
michael@0 57 ok(!mql.matches, "media query has been re-evaluated.");
michael@0 58 ok(window.screen.width == content.screen.width, "screen.width is not the size of the screen.");
michael@0 59 instance.stack.removeAttribute("notransition");
michael@0 60 document.getElementById("Tools:ResponsiveUI").doCommand();
michael@0 61 gBrowser.removeCurrentTab();
michael@0 62 finish();
michael@0 63 }
michael@0 64 }

mercurial