browser/devtools/responsivedesign/test/browser_responsive_devicewidth.js

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:c807f1c7765b
1 /* Any copyright is dedicated to the Public Domain.
2 http://creativecommons.org/publicdomain/zero/1.0/ */
3
4 function test() {
5 let instance;
6 let mgr = ResponsiveUI.ResponsiveUIManager;
7
8 waitForExplicitFinish();
9
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);
15
16 content.location = "data:text/html,mop";
17
18 function startTest() {
19 mgr.once("on", function() {executeSoon(onUIOpen)});
20 document.getElementById("Tools:ResponsiveUI").doCommand();
21 }
22
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.");
27
28 instance.setSize(110, 500);
29 ok(content.innerWidth, 110, "initial width is valid");
30
31 let mql = content.matchMedia("(max-device-width:100px)")
32
33 ok(!mql.matches, "media query doesn't match.");
34
35 mql.addListener(onMediaChange);
36 instance.setSize(90, 500);
37 }
38
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.");
45
46
47 let docShell = content.QueryInterface(Ci.nsIInterfaceRequestor)
48 .getInterface(Ci.nsIWebNavigation)
49 .QueryInterface(Ci.nsIDocShell);
50
51 mql.addListener(onMediaChange2);
52 docShell.deviceSizeIsPageSize = false;
53 }
54
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