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: michael@0: let computedView; michael@0: let inspector; 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;charset=utf-8,
" michael@0: michael@0: function computedWidth() { michael@0: for (let prop of computedView.propertyViews) { michael@0: if (prop.name === "width") { michael@0: return prop.valueNode.textContent; michael@0: } michael@0: } michael@0: return null; michael@0: } michael@0: michael@0: function startTest() { michael@0: document.getElementById("Tools:ResponsiveUI").doCommand(); michael@0: executeSoon(onUIOpen); michael@0: } michael@0: michael@0: function onUIOpen() { michael@0: instance = gBrowser.selectedTab.__responsiveUI; michael@0: ok(instance, "instance of the module is attached to the tab."); michael@0: michael@0: instance.stack.setAttribute("notransition", "true"); michael@0: registerCleanupFunction(function() { michael@0: instance.stack.removeAttribute("notransition"); michael@0: }); michael@0: michael@0: instance.setSize(500, 500); michael@0: michael@0: openComputedView().then(onInspectorUIOpen); michael@0: } michael@0: michael@0: function onInspectorUIOpen(args) { michael@0: inspector = args.inspector; michael@0: computedView = args.view; michael@0: ok(inspector, "Got inspector instance"); michael@0: michael@0: let div = content.document.getElementsByTagName("div")[0]; michael@0: michael@0: inspector.selection.setNode(div); michael@0: inspector.once("inspector-updated", testShrink); michael@0: } michael@0: michael@0: function testShrink() { michael@0: is(computedWidth(), "500px", "Should show 500px initially."); michael@0: michael@0: inspector.once("computed-view-refreshed", function onShrink() { michael@0: is(computedWidth(), "100px", "div should be 100px after shrinking."); michael@0: testGrow(); michael@0: }); michael@0: michael@0: instance.setSize(100, 100); michael@0: } michael@0: michael@0: function testGrow() { michael@0: inspector.once("computed-view-refreshed", function onGrow() { michael@0: is(computedWidth(), "500px", "Should be 500px after growing."); michael@0: finishUp(); michael@0: }); michael@0: michael@0: instance.setSize(500, 500); michael@0: } michael@0: michael@0: function finishUp() { michael@0: document.getElementById("Tools:ResponsiveUI").doCommand(); michael@0: michael@0: // Menus are correctly updated? michael@0: is(document.getElementById("Tools:ResponsiveUI").getAttribute("checked"), "false", "menu unchecked"); michael@0: michael@0: gBrowser.removeCurrentTab(); michael@0: finish(); michael@0: } michael@0: }