browser/devtools/layoutview/test/head.js

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

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 Cu.import("resource://gre/modules/Task.jsm");
michael@0 5
michael@0 6 let {devtools} = Cu.import("resource://gre/modules/devtools/Loader.jsm", {});
michael@0 7 const {Promise: promise} = Cu.import("resource://gre/modules/Promise.jsm", {});
michael@0 8 let TargetFactory = devtools.TargetFactory;
michael@0 9
michael@0 10 Services.prefs.setBoolPref("devtools.inspector.sidebarOpen", true);
michael@0 11 Services.prefs.setIntPref("devtools.toolbox.footer.height", 350);
michael@0 12 gDevTools.testing = true;
michael@0 13 SimpleTest.registerCleanupFunction(() => {
michael@0 14 Services.prefs.clearUserPref("devtools.inspector.sidebarOpen");
michael@0 15 Services.prefs.clearUserPref("devtools.toolbox.footer.height");
michael@0 16 gDevTools.testing = false;
michael@0 17 });
michael@0 18
michael@0 19 // All tests are async in general
michael@0 20 waitForExplicitFinish();
michael@0 21
michael@0 22 function loadTab(url) {
michael@0 23 let deferred = promise.defer();
michael@0 24
michael@0 25 gBrowser.selectedTab = gBrowser.addTab();
michael@0 26 gBrowser.selectedBrowser.addEventListener("load", function onload() {
michael@0 27 gBrowser.selectedBrowser.removeEventListener("load", onload, true);
michael@0 28 waitForFocus(function() {
michael@0 29 deferred.resolve(content);
michael@0 30 }, content);
michael@0 31 }, true);
michael@0 32
michael@0 33 content.location = url;
michael@0 34
michael@0 35 return deferred.promise;
michael@0 36 }
michael@0 37
michael@0 38 function selectNode(aNode) {
michael@0 39 info("selecting node");
michael@0 40 let onSelect = inspector.once("layoutview-updated");
michael@0 41 inspector.selection.setNode(aNode, "test");
michael@0 42 return onSelect.then(() => {
michael@0 43 let view = inspector.sidebar.getWindowForTab("layoutview");
michael@0 44 ok(!!view.layoutview, "LayoutView document is alive.");
michael@0 45
michael@0 46 return view;
michael@0 47 });
michael@0 48 }
michael@0 49
michael@0 50 function waitForUpdate() {
michael@0 51 return inspector.once("layoutview-updated");
michael@0 52 }
michael@0 53
michael@0 54 function asyncTest(testfunc) {
michael@0 55 return Task.async(function*() {
michael@0 56 let initialTab = gBrowser.selectedTab;
michael@0 57
michael@0 58 yield testfunc();
michael@0 59
michael@0 60 // Remove all tabs except for the initial tab. This is basically
michael@0 61 // gBrowser.removeAllTabsBut without the animation
michael@0 62 let tabs = gBrowser.visibleTabs;
michael@0 63 gBrowser.selectedTab = initialTab;
michael@0 64 for (let i = tabs.length - 1; i >= 0; i--) {
michael@0 65 if (tabs[i] != initialTab)
michael@0 66 gBrowser.removeTab(tabs[i]);
michael@0 67 }
michael@0 68
michael@0 69 // Reset the sidebar back to the default
michael@0 70 Services.prefs.setCharPref("devtools.inspector.activeSidebar", "ruleview");
michael@0 71
michael@0 72 finish();
michael@0 73 });
michael@0 74 }
michael@0 75
michael@0 76 var TESTS = [];
michael@0 77
michael@0 78 function addTest(message, func) {
michael@0 79 TESTS.push([message, Task.async(func)])
michael@0 80 }
michael@0 81
michael@0 82 var runTests = Task.async(function*() {
michael@0 83 for (let [message, test] of TESTS) {
michael@0 84 info(message);
michael@0 85 yield test();
michael@0 86 }
michael@0 87 });

mercurial