browser/devtools/responsivedesign/test/browser_responsiveruleview.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

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 ruleView;
michael@0 8 let inspector;
michael@0 9 let mgr = ResponsiveUI.ResponsiveUIManager;
michael@0 10
michael@0 11 waitForExplicitFinish();
michael@0 12
michael@0 13 gBrowser.selectedTab = gBrowser.addTab();
michael@0 14 gBrowser.selectedBrowser.addEventListener("load", function onload() {
michael@0 15 gBrowser.selectedBrowser.removeEventListener("load", onload, true);
michael@0 16 waitForFocus(startTest, content);
michael@0 17 }, true);
michael@0 18
michael@0 19 content.location = "data:text/html;charset=utf-8,<html><style>" +
michael@0 20 "div {" +
michael@0 21 " width: 500px;" +
michael@0 22 " height: 10px;" +
michael@0 23 " background: purple;" +
michael@0 24 "} " +
michael@0 25 "@media screen and (max-width: 200px) {" +
michael@0 26 " div { " +
michael@0 27 " width: 100px;" +
michael@0 28 " }" +
michael@0 29 "};" +
michael@0 30 "</style><div></div></html>"
michael@0 31
michael@0 32 function numberOfRules() {
michael@0 33 return ruleView.element.querySelectorAll(".ruleview-code").length;
michael@0 34 }
michael@0 35
michael@0 36 function startTest() {
michael@0 37 document.getElementById("Tools:ResponsiveUI").doCommand();
michael@0 38 executeSoon(onUIOpen);
michael@0 39 }
michael@0 40
michael@0 41 function onUIOpen() {
michael@0 42 instance = gBrowser.selectedTab.__responsiveUI;
michael@0 43 ok(instance, "instance of the module is attached to the tab.");
michael@0 44
michael@0 45 instance.stack.setAttribute("notransition", "true");
michael@0 46 registerCleanupFunction(function() {
michael@0 47 instance.stack.removeAttribute("notransition");
michael@0 48 });
michael@0 49
michael@0 50 instance.setSize(500, 500);
michael@0 51
michael@0 52 openRuleView().then(onInspectorUIOpen);
michael@0 53 }
michael@0 54
michael@0 55 function onInspectorUIOpen(args) {
michael@0 56 inspector = args.inspector;
michael@0 57 ruleView = args.view;
michael@0 58 ok(inspector, "Got inspector instance");
michael@0 59
michael@0 60 let div = content.document.getElementsByTagName("div")[0];
michael@0 61 inspector.selection.setNode(div);
michael@0 62 inspector.once("inspector-updated", testShrink);
michael@0 63 }
michael@0 64
michael@0 65 function testShrink() {
michael@0 66
michael@0 67 is(numberOfRules(), 2, "Should have two rules initially.");
michael@0 68
michael@0 69 ruleView.element.addEventListener("CssRuleViewRefreshed", function refresh() {
michael@0 70 ruleView.element.removeEventListener("CssRuleViewRefreshed", refresh, false);
michael@0 71 is(numberOfRules(), 3, "Should have three rules after shrinking.");
michael@0 72 testGrow();
michael@0 73 }, false);
michael@0 74
michael@0 75 instance.setSize(100, 100);
michael@0 76 }
michael@0 77
michael@0 78 function testGrow() {
michael@0 79 ruleView.element.addEventListener("CssRuleViewRefreshed", function refresh() {
michael@0 80 ruleView.element.removeEventListener("CssRuleViewRefreshed", refresh, false);
michael@0 81 is(numberOfRules(), 2, "Should have two rules after growing.");
michael@0 82 testEscapeCloses();
michael@0 83 }, false);
michael@0 84
michael@0 85 instance.setSize(500, 500);
michael@0 86 }
michael@0 87
michael@0 88 function testEscapeCloses() {
michael@0 89 is(document.getElementById("Tools:ResponsiveUI").getAttribute("checked"), "true", "menu checked");
michael@0 90 ok(!inspector._toolbox._splitConsole, "Console is not split.");
michael@0 91
michael@0 92 mgr.once("off", function() {executeSoon(finishUp)});
michael@0 93 EventUtils.synthesizeKey("VK_ESCAPE", {});
michael@0 94 }
michael@0 95
michael@0 96 function finishUp() {
michael@0 97 ok(!inspector._toolbox._splitConsole, "Console is still not split after pressing escape.");
michael@0 98
michael@0 99 // Menus are correctly updated?
michael@0 100 is(document.getElementById("Tools:ResponsiveUI").getAttribute("checked"), "false", "menu unchecked");
michael@0 101
michael@0 102 gBrowser.removeCurrentTab();
michael@0 103 finish();
michael@0 104 }
michael@0 105 }

mercurial