michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: function test() { michael@0: let instance; michael@0: let mgr = ResponsiveUI.ResponsiveUIManager; michael@0: michael@0: waitForExplicitFinish(); michael@0: michael@0: gBrowser.selectedTab = gBrowser.addTab(); michael@0: gBrowser.selectedBrowser.addEventListener("load", function onload() { michael@0: gBrowser.selectedBrowser.removeEventListener("load", onload, true); michael@0: waitForFocus(startTest, content); michael@0: }, true); michael@0: michael@0: content.location = "data:text/html,mop"; michael@0: michael@0: function startTest() { michael@0: mgr.once("on", function() {executeSoon(onUIOpen)}); michael@0: document.getElementById("Tools:ResponsiveUI").doCommand(); michael@0: } michael@0: michael@0: function onUIOpen() { michael@0: instance = gBrowser.selectedTab.__responsiveUI; michael@0: instance.stack.setAttribute("notransition", "true"); michael@0: ok(instance, "instance of the module is attached to the tab."); michael@0: michael@0: instance.setSize(110, 500); michael@0: ok(content.innerWidth, 110, "initial width is valid"); michael@0: michael@0: let mql = content.matchMedia("(max-device-width:100px)") michael@0: michael@0: ok(!mql.matches, "media query doesn't match."); michael@0: michael@0: mql.addListener(onMediaChange); michael@0: instance.setSize(90, 500); michael@0: } michael@0: michael@0: function onMediaChange(mql) { michael@0: mql.removeListener(onMediaChange); michael@0: ok(mql.matches, "media query matches."); michael@0: ok(window.screen.width != content.screen.width, "screen.width is not the size of the screen."); michael@0: is(content.screen.width, 90, "screen.width is the width of the page."); michael@0: is(content.screen.height, 500, "screen.height is the height of the page."); michael@0: michael@0: michael@0: let docShell = content.QueryInterface(Ci.nsIInterfaceRequestor) michael@0: .getInterface(Ci.nsIWebNavigation) michael@0: .QueryInterface(Ci.nsIDocShell); michael@0: michael@0: mql.addListener(onMediaChange2); michael@0: docShell.deviceSizeIsPageSize = false; michael@0: } michael@0: michael@0: function onMediaChange2(mql) { michael@0: mql.removeListener(onMediaChange); michael@0: ok(!mql.matches, "media query has been re-evaluated."); michael@0: ok(window.screen.width == content.screen.width, "screen.width is not the size of the screen."); michael@0: instance.stack.removeAttribute("notransition"); michael@0: document.getElementById("Tools:ResponsiveUI").doCommand(); michael@0: gBrowser.removeCurrentTab(); michael@0: finish(); michael@0: } michael@0: }