1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/devtools/layoutview/test/head.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,87 @@ 1.4 +/* Any copyright is dedicated to the Public Domain. 1.5 + http://creativecommons.org/publicdomain/zero/1.0/ */ 1.6 + 1.7 +Cu.import("resource://gre/modules/Task.jsm"); 1.8 + 1.9 +let {devtools} = Cu.import("resource://gre/modules/devtools/Loader.jsm", {}); 1.10 +const {Promise: promise} = Cu.import("resource://gre/modules/Promise.jsm", {}); 1.11 +let TargetFactory = devtools.TargetFactory; 1.12 + 1.13 +Services.prefs.setBoolPref("devtools.inspector.sidebarOpen", true); 1.14 +Services.prefs.setIntPref("devtools.toolbox.footer.height", 350); 1.15 +gDevTools.testing = true; 1.16 +SimpleTest.registerCleanupFunction(() => { 1.17 + Services.prefs.clearUserPref("devtools.inspector.sidebarOpen"); 1.18 + Services.prefs.clearUserPref("devtools.toolbox.footer.height"); 1.19 + gDevTools.testing = false; 1.20 +}); 1.21 + 1.22 +// All tests are async in general 1.23 +waitForExplicitFinish(); 1.24 + 1.25 +function loadTab(url) { 1.26 + let deferred = promise.defer(); 1.27 + 1.28 + gBrowser.selectedTab = gBrowser.addTab(); 1.29 + gBrowser.selectedBrowser.addEventListener("load", function onload() { 1.30 + gBrowser.selectedBrowser.removeEventListener("load", onload, true); 1.31 + waitForFocus(function() { 1.32 + deferred.resolve(content); 1.33 + }, content); 1.34 + }, true); 1.35 + 1.36 + content.location = url; 1.37 + 1.38 + return deferred.promise; 1.39 +} 1.40 + 1.41 +function selectNode(aNode) { 1.42 + info("selecting node"); 1.43 + let onSelect = inspector.once("layoutview-updated"); 1.44 + inspector.selection.setNode(aNode, "test"); 1.45 + return onSelect.then(() => { 1.46 + let view = inspector.sidebar.getWindowForTab("layoutview"); 1.47 + ok(!!view.layoutview, "LayoutView document is alive."); 1.48 + 1.49 + return view; 1.50 + }); 1.51 +} 1.52 + 1.53 +function waitForUpdate() { 1.54 + return inspector.once("layoutview-updated"); 1.55 +} 1.56 + 1.57 +function asyncTest(testfunc) { 1.58 + return Task.async(function*() { 1.59 + let initialTab = gBrowser.selectedTab; 1.60 + 1.61 + yield testfunc(); 1.62 + 1.63 + // Remove all tabs except for the initial tab. This is basically 1.64 + // gBrowser.removeAllTabsBut without the animation 1.65 + let tabs = gBrowser.visibleTabs; 1.66 + gBrowser.selectedTab = initialTab; 1.67 + for (let i = tabs.length - 1; i >= 0; i--) { 1.68 + if (tabs[i] != initialTab) 1.69 + gBrowser.removeTab(tabs[i]); 1.70 + } 1.71 + 1.72 + // Reset the sidebar back to the default 1.73 + Services.prefs.setCharPref("devtools.inspector.activeSidebar", "ruleview"); 1.74 + 1.75 + finish(); 1.76 + }); 1.77 +} 1.78 + 1.79 +var TESTS = []; 1.80 + 1.81 +function addTest(message, func) { 1.82 + TESTS.push([message, Task.async(func)]) 1.83 +} 1.84 + 1.85 +var runTests = Task.async(function*() { 1.86 + for (let [message, test] of TESTS) { 1.87 + info(message); 1.88 + yield test(); 1.89 + } 1.90 +});