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 ruleView; michael@0: let inspector; 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;charset=utf-8,
" michael@0: michael@0: function numberOfRules() { michael@0: return ruleView.element.querySelectorAll(".ruleview-code").length; 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: openRuleView().then(onInspectorUIOpen); michael@0: } michael@0: michael@0: function onInspectorUIOpen(args) { michael@0: inspector = args.inspector; michael@0: ruleView = args.view; michael@0: ok(inspector, "Got inspector instance"); michael@0: michael@0: let div = content.document.getElementsByTagName("div")[0]; michael@0: inspector.selection.setNode(div); michael@0: inspector.once("inspector-updated", testShrink); michael@0: } michael@0: michael@0: function testShrink() { michael@0: michael@0: is(numberOfRules(), 2, "Should have two rules initially."); michael@0: michael@0: ruleView.element.addEventListener("CssRuleViewRefreshed", function refresh() { michael@0: ruleView.element.removeEventListener("CssRuleViewRefreshed", refresh, false); michael@0: is(numberOfRules(), 3, "Should have three rules after shrinking."); michael@0: testGrow(); michael@0: }, false); michael@0: michael@0: instance.setSize(100, 100); michael@0: } michael@0: michael@0: function testGrow() { michael@0: ruleView.element.addEventListener("CssRuleViewRefreshed", function refresh() { michael@0: ruleView.element.removeEventListener("CssRuleViewRefreshed", refresh, false); michael@0: is(numberOfRules(), 2, "Should have two rules after growing."); michael@0: testEscapeCloses(); michael@0: }, false); michael@0: michael@0: instance.setSize(500, 500); michael@0: } michael@0: michael@0: function testEscapeCloses() { michael@0: is(document.getElementById("Tools:ResponsiveUI").getAttribute("checked"), "true", "menu checked"); michael@0: ok(!inspector._toolbox._splitConsole, "Console is not split."); michael@0: michael@0: mgr.once("off", function() {executeSoon(finishUp)}); michael@0: EventUtils.synthesizeKey("VK_ESCAPE", {}); michael@0: } michael@0: michael@0: function finishUp() { michael@0: ok(!inspector._toolbox._splitConsole, "Console is still not split after pressing escape."); 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: }