From beca458e3e107f067a63fdacadc00d01ec33676d Mon Sep 17 00:00:00 2001 From: Matthew Noorenberghe Date: Sat, 13 Feb 2016 17:44:05 -0800 Subject: [PATCH] Bug 1248087 - screenshots: Add preferences and devtools scheduled runs. r=kitcambridge MozReview-Commit-ID: 708wpg9Reca --HG-- extra : rebase_source : e239feab74ee96c836cc78af641155f4b0662fff --- browser/tools/mozscreenshots/browser.ini | 1 - .../mozscreenshots/browser_screenshots.js | 11 ++---- .../tools/mozscreenshots/devtools/browser.ini | 6 +++ .../devtools/browser_devtools.js | 14 +++++++ browser/tools/mozscreenshots/head.js | 16 ++++++-- browser/tools/mozscreenshots/moz.build | 9 ++++- .../mozscreenshots/extension/TestRunner.jsm | 5 ++- .../extension/configurations/Preferences.jsm | 39 +++++++++++++------ .../mozscreenshots/preferences/browser.ini | 6 +++ .../preferences/browser_preferences.js | 14 +++++++ .../mozscreenshots/primaryUI/browser.ini | 6 +++ .../primaryUI/browser_primaryUI.js | 14 +++++++ 12 files changed, 115 insertions(+), 26 deletions(-) create mode 100644 browser/tools/mozscreenshots/devtools/browser.ini create mode 100644 browser/tools/mozscreenshots/devtools/browser_devtools.js create mode 100644 browser/tools/mozscreenshots/preferences/browser.ini create mode 100644 browser/tools/mozscreenshots/preferences/browser_preferences.js create mode 100644 browser/tools/mozscreenshots/primaryUI/browser.ini create mode 100644 browser/tools/mozscreenshots/primaryUI/browser_primaryUI.js diff --git a/browser/tools/mozscreenshots/browser.ini b/browser/tools/mozscreenshots/browser.ini index b0227f3f932f..0ca5820bdbaa 100644 --- a/browser/tools/mozscreenshots/browser.ini +++ b/browser/tools/mozscreenshots/browser.ini @@ -4,4 +4,3 @@ support-files = head.js [browser_screenshots.js] -tags = screenshots diff --git a/browser/tools/mozscreenshots/browser_screenshots.js b/browser/tools/mozscreenshots/browser_screenshots.js index f40c0867808a..502f90fec2c7 100644 --- a/browser/tools/mozscreenshots/browser_screenshots.js +++ b/browser/tools/mozscreenshots/browser_screenshots.js @@ -5,15 +5,12 @@ "use strict"; add_task(function* capture() { - if (!shouldCapture()) { + let setsEnv = env.get("MOZSCREENSHOTS_SETS"); + if (!setsEnv) { + ok(true, "MOZSCREENSHOTS_SETS wasn't specified so there's nothing to capture"); return; } - let { TestRunner } = Cu.import("chrome://mozscreenshots/content/TestRunner.jsm", {}); - let sets = ["TabsInTitlebar", "Tabs", "WindowSize", "Toolbars", "LightweightThemes"]; - let setsEnv = env.get("MOZSCREENSHOTS_SETS"); - if (setsEnv) { - sets = setsEnv.trim().split(","); - } + let sets = setsEnv.trim().split(","); yield TestRunner.start(sets); }); diff --git a/browser/tools/mozscreenshots/devtools/browser.ini b/browser/tools/mozscreenshots/devtools/browser.ini new file mode 100644 index 000000000000..e4fa0a988a96 --- /dev/null +++ b/browser/tools/mozscreenshots/devtools/browser.ini @@ -0,0 +1,6 @@ +[DEFAULT] +subsuite = screenshots +support-files = + ../head.js + +[browser_devtools.js] diff --git a/browser/tools/mozscreenshots/devtools/browser_devtools.js b/browser/tools/mozscreenshots/devtools/browser_devtools.js new file mode 100644 index 000000000000..07d3ef548b2f --- /dev/null +++ b/browser/tools/mozscreenshots/devtools/browser_devtools.js @@ -0,0 +1,14 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +"use strict"; + +add_task(function* capture() { + if (!shouldCapture()) { + return; + } + let sets = ["DevTools"]; + + yield TestRunner.start(sets); +}); diff --git a/browser/tools/mozscreenshots/head.js b/browser/tools/mozscreenshots/head.js index 940b82687260..122c9d4a974e 100644 --- a/browser/tools/mozscreenshots/head.js +++ b/browser/tools/mozscreenshots/head.js @@ -6,6 +6,7 @@ const {AddonWatcher} = Cu.import("resource://gre/modules/AddonWatcher.jsm", {}); const env = Cc["@mozilla.org/process/environment;1"].getService(Ci.nsIEnvironment); +let TestRunner; function setup() { requestLongerTimeout(20); @@ -15,18 +16,25 @@ function setup() { AddonManager.getAddonByID("mozscreenshots@mozilla.org", function(aAddon) { isnot(aAddon, null, "The mozscreenshots extension should be installed"); AddonWatcher.ignoreAddonPermanently(aAddon.id); + TestRunner = Cu.import("chrome://mozscreenshots/content/TestRunner.jsm", {}).TestRunner; resolve(); }); }); } function shouldCapture() { + // Try pushes only capture in browser_screenshots.js with MOZSCREENSHOTS_SETS. + if (env.get("MOZSCREENSHOTS_SETS")) { + ok(true, "MOZSCREENSHOTS_SETS was specified so only capture what was " + + "requested (in browser_screenshots.js)"); + return false; + } + // Automation isn't able to schedule test jobs to only run on nightlies so we handle it here - // (see also: bug 1116275). Try pushes and local builds should also capture. + // (see also: bug 1116275). let capture = AppConstants.MOZ_UPDATE_CHANNEL == "nightly" || - (AppConstants.SOURCE_REVISION_URL.includes("/try/rev/") && - env.get("MOZSCREENSHOTS_SETS")) || - AppConstants.SOURCE_REVISION_URL == ""; + AppConstants.SOURCE_REVISION_URL == "" || + AppConstants.SOURCE_REVISION_URL == "1"; // bug 1248027 if (!capture) { ok(true, "Capturing is disabled for this MOZ_UPDATE_CHANNEL or REPO"); } diff --git a/browser/tools/mozscreenshots/moz.build b/browser/tools/mozscreenshots/moz.build index 2c0347bbc8f7..65b107c10919 100644 --- a/browser/tools/mozscreenshots/moz.build +++ b/browser/tools/mozscreenshots/moz.build @@ -4,7 +4,14 @@ # License, v. 2.0. If a copy of the MPL was not distributed with this # file, You can obtain one at http://mozilla.org/MPL/2.0/. -BROWSER_CHROME_MANIFESTS += ['browser.ini'] +BROWSER_CHROME_MANIFESTS += [ + # Each test is in it's own directory so it gets run in a clean profile with + # run-by-dir. + 'browser.ini', + 'devtools/browser.ini', + 'preferences/browser.ini', + 'primaryUI/browser.ini', +] TEST_DIRS += [ 'mozscreenshots/extension', diff --git a/browser/tools/mozscreenshots/mozscreenshots/extension/TestRunner.jsm b/browser/tools/mozscreenshots/mozscreenshots/extension/TestRunner.jsm index 5a9bf7fd8819..991109ed2d6b 100644 --- a/browser/tools/mozscreenshots/mozscreenshots/extension/TestRunner.jsm +++ b/browser/tools/mozscreenshots/mozscreenshots/extension/TestRunner.jsm @@ -11,7 +11,6 @@ const defaultSetNames = ["TabsInTitlebar", "Tabs", "WindowSize", "Toolbars", "Li const env = Cc["@mozilla.org/process/environment;1"].getService(Ci.nsIEnvironment); const HOME_PAGE = "chrome://mozscreenshots/content/lib/mozscreenshots.html"; -Cu.import("resource://testing-common/BrowserTestUtils.jsm"); Cu.import("resource://gre/modules/FileUtils.jsm"); Cu.import("resource://gre/modules/Services.jsm"); Cu.import("resource://gre/modules/Task.jsm"); @@ -19,6 +18,9 @@ Cu.import("resource://gre/modules/Timer.jsm"); Cu.import("resource://gre/modules/XPCOMUtils.jsm"); Cu.import("resource://gre/modules/osfile.jsm"); +XPCOMUtils.defineLazyModuleGetter(this, "BrowserTestUtils", + "resource://testing-common/BrowserTestUtils.jsm"); + Cu.import("chrome://mozscreenshots/content/Screenshot.jsm"); // Create a new instance of the ConsoleAPI so we can control the maxLogLevel with a pref. @@ -42,6 +44,7 @@ this.TestRunner = { _libDir: null, init(extensionPath) { + log.info("init"); this._extensionPath = extensionPath; }, diff --git a/browser/tools/mozscreenshots/mozscreenshots/extension/configurations/Preferences.jsm b/browser/tools/mozscreenshots/mozscreenshots/extension/configurations/Preferences.jsm index c0f18787e647..add345168c9f 100644 --- a/browser/tools/mozscreenshots/mozscreenshots/extension/configurations/Preferences.jsm +++ b/browser/tools/mozscreenshots/mozscreenshots/extension/configurations/Preferences.jsm @@ -9,7 +9,9 @@ this.EXPORTED_SYMBOLS = ["Preferences"]; const {classes: Cc, interfaces: Ci, utils: Cu} = Components; Cu.import("resource://gre/modules/Services.jsm"); +Cu.import("resource://gre/modules/Task.jsm"); Cu.import("resource://gre/modules/Timer.jsm"); +Cu.import("resource://testing-common/TestUtils.jsm"); this.Preferences = { @@ -31,7 +33,7 @@ this.Preferences = { ["paneAdvanced", "encryptionTab"], ]; for (let [primary, advanced] of panes) { - let configName = primary + ("-" + advanced || ""); + let configName = primary.replace(/^pane/, "prefs") + (advanced ? "-" + advanced : ""); this.configurations[configName] = {}; this.configurations[configName].applyConfig = prefHelper.bind(null, primary, advanced); } @@ -40,14 +42,27 @@ this.Preferences = { configurations: {}, }; -function prefHelper(primary, advanced) { - return new Promise((resolve) => { - let browserWindow = Services.wm.getMostRecentWindow("navigator:browser"); - if (primary == "paneAdvanced") { - browserWindow.openAdvancedPreferences(advanced); - } else { - browserWindow.openPreferences(primary); - } - setTimeout(resolve, 50); - }); -} +let prefHelper = Task.async(function*(primary, advanced) { + let browserWindow = Services.wm.getMostRecentWindow("navigator:browser"); + let selectedBrowser = browserWindow.gBrowser; + let readyPromise = null; + if (selectedBrowser.currentURI.specIgnoringRef == "about:preferences") { + readyPromise = new Promise((resolve) => { + browserWindow.addEventListener("MozAfterPaint", function paneSwitch() { + browserWindow.removeEventListener("MozAfterPaint", paneSwitch); + resolve(); + }); + }); + + } else { + readyPromise = TestUtils.topicObserved("advanced-pane-loaded"); + } + + if (primary == "paneAdvanced") { + browserWindow.openAdvancedPreferences(advanced); + } else { + browserWindow.openPreferences(primary); + } + + yield readyPromise; +}); diff --git a/browser/tools/mozscreenshots/preferences/browser.ini b/browser/tools/mozscreenshots/preferences/browser.ini new file mode 100644 index 000000000000..975d91681507 --- /dev/null +++ b/browser/tools/mozscreenshots/preferences/browser.ini @@ -0,0 +1,6 @@ +[DEFAULT] +subsuite = screenshots +support-files = + ../head.js + +[browser_preferences.js] diff --git a/browser/tools/mozscreenshots/preferences/browser_preferences.js b/browser/tools/mozscreenshots/preferences/browser_preferences.js new file mode 100644 index 000000000000..c4e1b19f3d40 --- /dev/null +++ b/browser/tools/mozscreenshots/preferences/browser_preferences.js @@ -0,0 +1,14 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +"use strict"; + +add_task(function* capture() { + if (!shouldCapture()) { + return; + } + let sets = ["Preferences"]; + + yield TestRunner.start(sets); +}); diff --git a/browser/tools/mozscreenshots/primaryUI/browser.ini b/browser/tools/mozscreenshots/primaryUI/browser.ini new file mode 100644 index 000000000000..628520b23f54 --- /dev/null +++ b/browser/tools/mozscreenshots/primaryUI/browser.ini @@ -0,0 +1,6 @@ +[DEFAULT] +subsuite = screenshots +support-files = + ../head.js + +[browser_primaryUI.js] diff --git a/browser/tools/mozscreenshots/primaryUI/browser_primaryUI.js b/browser/tools/mozscreenshots/primaryUI/browser_primaryUI.js new file mode 100644 index 000000000000..b48c0139dc53 --- /dev/null +++ b/browser/tools/mozscreenshots/primaryUI/browser_primaryUI.js @@ -0,0 +1,14 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +"use strict"; + +add_task(function* capture() { + if (!shouldCapture()) { + return; + } + let sets = ["TabsInTitlebar", "Tabs", "WindowSize", "Toolbars", "LightweightThemes"]; + + yield TestRunner.start(sets); +});