Wed, 31 Dec 2014 06:09:35 +0100
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 | |
michael@0 | 7 | let computedView; |
michael@0 | 8 | let inspector; |
michael@0 | 9 | |
michael@0 | 10 | waitForExplicitFinish(); |
michael@0 | 11 | |
michael@0 | 12 | gBrowser.selectedTab = gBrowser.addTab(); |
michael@0 | 13 | gBrowser.selectedBrowser.addEventListener("load", function onload() { |
michael@0 | 14 | gBrowser.selectedBrowser.removeEventListener("load", onload, true); |
michael@0 | 15 | waitForFocus(startTest, content); |
michael@0 | 16 | }, true); |
michael@0 | 17 | |
michael@0 | 18 | content.location = "data:text/html;charset=utf-8,<html><style>" + |
michael@0 | 19 | "div {" + |
michael@0 | 20 | " width: 500px;" + |
michael@0 | 21 | " height: 10px;" + |
michael@0 | 22 | " background: purple;" + |
michael@0 | 23 | "} " + |
michael@0 | 24 | "@media screen and (max-width: 200px) {" + |
michael@0 | 25 | " div { " + |
michael@0 | 26 | " width: 100px;" + |
michael@0 | 27 | " }" + |
michael@0 | 28 | "};" + |
michael@0 | 29 | "</style><div></div></html>" |
michael@0 | 30 | |
michael@0 | 31 | function computedWidth() { |
michael@0 | 32 | for (let prop of computedView.propertyViews) { |
michael@0 | 33 | if (prop.name === "width") { |
michael@0 | 34 | return prop.valueNode.textContent; |
michael@0 | 35 | } |
michael@0 | 36 | } |
michael@0 | 37 | return null; |
michael@0 | 38 | } |
michael@0 | 39 | |
michael@0 | 40 | function startTest() { |
michael@0 | 41 | document.getElementById("Tools:ResponsiveUI").doCommand(); |
michael@0 | 42 | executeSoon(onUIOpen); |
michael@0 | 43 | } |
michael@0 | 44 | |
michael@0 | 45 | function onUIOpen() { |
michael@0 | 46 | instance = gBrowser.selectedTab.__responsiveUI; |
michael@0 | 47 | ok(instance, "instance of the module is attached to the tab."); |
michael@0 | 48 | |
michael@0 | 49 | instance.stack.setAttribute("notransition", "true"); |
michael@0 | 50 | registerCleanupFunction(function() { |
michael@0 | 51 | instance.stack.removeAttribute("notransition"); |
michael@0 | 52 | }); |
michael@0 | 53 | |
michael@0 | 54 | instance.setSize(500, 500); |
michael@0 | 55 | |
michael@0 | 56 | openComputedView().then(onInspectorUIOpen); |
michael@0 | 57 | } |
michael@0 | 58 | |
michael@0 | 59 | function onInspectorUIOpen(args) { |
michael@0 | 60 | inspector = args.inspector; |
michael@0 | 61 | computedView = args.view; |
michael@0 | 62 | ok(inspector, "Got inspector instance"); |
michael@0 | 63 | |
michael@0 | 64 | let div = content.document.getElementsByTagName("div")[0]; |
michael@0 | 65 | |
michael@0 | 66 | inspector.selection.setNode(div); |
michael@0 | 67 | inspector.once("inspector-updated", testShrink); |
michael@0 | 68 | } |
michael@0 | 69 | |
michael@0 | 70 | function testShrink() { |
michael@0 | 71 | is(computedWidth(), "500px", "Should show 500px initially."); |
michael@0 | 72 | |
michael@0 | 73 | inspector.once("computed-view-refreshed", function onShrink() { |
michael@0 | 74 | is(computedWidth(), "100px", "div should be 100px after shrinking."); |
michael@0 | 75 | testGrow(); |
michael@0 | 76 | }); |
michael@0 | 77 | |
michael@0 | 78 | instance.setSize(100, 100); |
michael@0 | 79 | } |
michael@0 | 80 | |
michael@0 | 81 | function testGrow() { |
michael@0 | 82 | inspector.once("computed-view-refreshed", function onGrow() { |
michael@0 | 83 | is(computedWidth(), "500px", "Should be 500px after growing."); |
michael@0 | 84 | finishUp(); |
michael@0 | 85 | }); |
michael@0 | 86 | |
michael@0 | 87 | instance.setSize(500, 500); |
michael@0 | 88 | } |
michael@0 | 89 | |
michael@0 | 90 | function finishUp() { |
michael@0 | 91 | document.getElementById("Tools:ResponsiveUI").doCommand(); |
michael@0 | 92 | |
michael@0 | 93 | // Menus are correctly updated? |
michael@0 | 94 | is(document.getElementById("Tools:ResponsiveUI").getAttribute("checked"), "false", "menu unchecked"); |
michael@0 | 95 | |
michael@0 | 96 | gBrowser.removeCurrentTab(); |
michael@0 | 97 | finish(); |
michael@0 | 98 | } |
michael@0 | 99 | } |