1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/devtools/responsivedesign/test/browser_responsive_devicewidth.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,64 @@ 1.4 +/* Any copyright is dedicated to the Public Domain. 1.5 +http://creativecommons.org/publicdomain/zero/1.0/ */ 1.6 + 1.7 +function test() { 1.8 + let instance; 1.9 + let mgr = ResponsiveUI.ResponsiveUIManager; 1.10 + 1.11 + waitForExplicitFinish(); 1.12 + 1.13 + gBrowser.selectedTab = gBrowser.addTab(); 1.14 + gBrowser.selectedBrowser.addEventListener("load", function onload() { 1.15 + gBrowser.selectedBrowser.removeEventListener("load", onload, true); 1.16 + waitForFocus(startTest, content); 1.17 + }, true); 1.18 + 1.19 + content.location = "data:text/html,mop"; 1.20 + 1.21 + function startTest() { 1.22 + mgr.once("on", function() {executeSoon(onUIOpen)}); 1.23 + document.getElementById("Tools:ResponsiveUI").doCommand(); 1.24 + } 1.25 + 1.26 + function onUIOpen() { 1.27 + instance = gBrowser.selectedTab.__responsiveUI; 1.28 + instance.stack.setAttribute("notransition", "true"); 1.29 + ok(instance, "instance of the module is attached to the tab."); 1.30 + 1.31 + instance.setSize(110, 500); 1.32 + ok(content.innerWidth, 110, "initial width is valid"); 1.33 + 1.34 + let mql = content.matchMedia("(max-device-width:100px)") 1.35 + 1.36 + ok(!mql.matches, "media query doesn't match."); 1.37 + 1.38 + mql.addListener(onMediaChange); 1.39 + instance.setSize(90, 500); 1.40 + } 1.41 + 1.42 + function onMediaChange(mql) { 1.43 + mql.removeListener(onMediaChange); 1.44 + ok(mql.matches, "media query matches."); 1.45 + ok(window.screen.width != content.screen.width, "screen.width is not the size of the screen."); 1.46 + is(content.screen.width, 90, "screen.width is the width of the page."); 1.47 + is(content.screen.height, 500, "screen.height is the height of the page."); 1.48 + 1.49 + 1.50 + let docShell = content.QueryInterface(Ci.nsIInterfaceRequestor) 1.51 + .getInterface(Ci.nsIWebNavigation) 1.52 + .QueryInterface(Ci.nsIDocShell); 1.53 + 1.54 + mql.addListener(onMediaChange2); 1.55 + docShell.deviceSizeIsPageSize = false; 1.56 + } 1.57 + 1.58 + function onMediaChange2(mql) { 1.59 + mql.removeListener(onMediaChange); 1.60 + ok(!mql.matches, "media query has been re-evaluated."); 1.61 + ok(window.screen.width == content.screen.width, "screen.width is not the size of the screen."); 1.62 + instance.stack.removeAttribute("notransition"); 1.63 + document.getElementById("Tools:ResponsiveUI").doCommand(); 1.64 + gBrowser.removeCurrentTab(); 1.65 + finish(); 1.66 + } 1.67 +}