Commit fc6c8fea authored by Robert Strong's avatar Robert Strong
Browse files

Bug 1555610 - Add whats new page test for code in BrowserContentHandler.jsm. r=bytesized,jaws

Changes UpdateService.jsm so it is possible to have an alternate update directory for tests similar to how enterprise policies does it.
Removes BUG_COMPONENT in moz.build for browser_bug538331.js since that test is for BrowserContentHandler.jsm code.

Differential Revision: https://phabricator.services.mozilla.com/D33225

--HG--
extra : moz-landing-system : lando
parent 683a4bd6
......@@ -13,9 +13,6 @@ with Files("distribution.js"):
with Files("tests/**"):
BUG_COMPONENT = ("Firefox", "General")
with Files("tests/browser/browser_bug538331.js"):
BUG_COMPONENT = ("Toolkit", "Application Update")
with Files("tests/browser/browser_contentpermissionprompt.js"):
BUG_COMPONENT = ("Firefox", "Site Identity and Permission Panels")
......@@ -94,7 +91,8 @@ EXTRA_JS_MODULES += [
BROWSER_CHROME_MANIFESTS += [
'safebrowsing/content/test/browser.ini',
'tests/browser/browser.ini'
'tests/browser/browser.ini',
'tests/browser/whats_new_page/browser.ini'
]
XPCSHELL_TESTS_MANIFESTS += [
......
<?xml version="1.0"?><updates xmlns="http://www.mozilla.org/2005/app-update"><update xmlns="http://www.mozilla.org/2005/app-update" appVersion="99999999.0" buildID="20990101111111" channel="test" detailsURL="https://127.0.0.1/" displayVersion="1.0" installDate="1555716429454" isCompleteUpdate="true" name="What's New Page Test" previousAppVersion="60.0" serviceURL="https://127.0.0.1/update.xml" type="minor" platformVersion="99999999.0" actions="showURL" openURL="https://example.com/|https://example.com/"><patch size="1" type="complete" URL="https://127.0.0.1/complete.mar" selected="true" state="pending"/></update></updates>
[DEFAULT]
skip-if = verify
reason = This is a startup test. Verify runs tests multiple times after startup.
support-files =
active-update.xml
updates/0/update.status
prefs =
app.update.altUpdateDirPath='<test-root>/browser/components/tests/browser/whats_new_page'
app.update.disabledForTesting=false
browser.startup.homepage_override.mstone="60.0"
[browser_whats_new_page.js]
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
add_task(async function whats_new_page() {
// BrowserContentHandler.jsm should have cleared the app.update.postupdate
// preference.
ok(!Services.prefs.prefHasUserValue("app.update.postupdate"),
"The app.update.postupdate preference should not have a user value");
// The test harness will use the current tab and remove the tab's history.
// Since the page that is tested is opened prior to the test harness taking
// over the current tab the active-update.xml specifies two pages to open by
// having 'https://example.com/|https://example.com/' for the value of openURL
// and then uses the first tab for the test.
gBrowser.selectedTab = gBrowser.tabs[0];
// The test harness also changes the page to about:blank so go back to the
// page that was originally opened.
gBrowser.goBack();
// Wait for the page to go back to the original page.
await TestUtils.waitForCondition(() =>
(gBrowser.selectedBrowser && gBrowser.selectedBrowser.currentURI &&
gBrowser.selectedBrowser.currentURI.spec == "https://example.com/"),
"Waiting for the expected page to reopen");
is(gBrowser.selectedBrowser.currentURI.spec, "https://example.com/",
"The what's new page's url should equal https://example.com/");
gBrowser.removeTab(gBrowser.selectedTab);
// Leave no trace. Since this test modifies its support files put them back in
// their original state.
let alternatePath =
Services.prefs.getCharPref("app.update.altUpdateDirPath");
let testRoot = Services.prefs.getCharPref("mochitest.testRoot");
let relativePath = alternatePath.substring("<test-root>".length);
if (AppConstants.platform == "win") {
relativePath = relativePath.replace(/\//g, "\\");
}
alternatePath = testRoot + relativePath;
let updateDir = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsIFile);
updateDir.initWithPath(alternatePath);
let activeUpdateFile = updateDir.clone();
activeUpdateFile.append("active-update.xml");
await TestUtils.waitForCondition(() =>
(!activeUpdateFile.exists()),
"Waiting until the active-update.xml file does not exist");
let updatesFile = updateDir.clone();
updatesFile.append("updates.xml");
await TestUtils.waitForCondition(() =>
(updatesFile.exists()),
"Waiting until the updates.xml file exists");
let fos = Cc["@mozilla.org/network/file-output-stream;1"].
createInstance(Ci.nsIFileOutputStream);
let flags = FileUtils.MODE_WRONLY | FileUtils.MODE_CREATE |
FileUtils.MODE_TRUNCATE;
let stateSucceeded = "succeeded\n";
let updateStatusFile = updateDir.clone();
updateStatusFile.append("updates");
updateStatusFile.append("0");
updateStatusFile.append("update.status");
updateStatusFile.create(Ci.nsIFile.NORMAL_FILE_TYPE, FileUtils.PERMS_FILE);
fos.init(updateStatusFile, flags, FileUtils.PERMS_FILE, 0);
fos.write(stateSucceeded, stateSucceeded.length);
fos.close();
let xmlContents =
"<?xml version=\"1.0\"?><updates xmlns=\"http://www.mozilla.org/2005/" +
"app-update\"><update xmlns=\"http://www.mozilla.org/2005/app-update\" " +
"appVersion=\"99999999.0\" buildID=\"20990101111111\" channel=\"test\" " +
"detailsURL=\"https://127.0.0.1/\" displayVersion=\"1.0\" installDate=\"" +
"1555716429454\" isCompleteUpdate=\"true\" name=\"What's New Page Test\" " +
"previousAppVersion=\"60.0\" serviceURL=\"https://127.0.0.1/update.xml\" " +
"type=\"minor\" platformVersion=\"99999999.0\" actions=\"showURL\" " +
"openURL=\"https://example.com/|https://example.com/\"><patch size=\"1\" " +
"type=\"complete\" URL=\"https://127.0.0.1/complete.mar\" " +
"selected=\"true\" state=\"pending\"/></update></updates>\n";
activeUpdateFile.create(Ci.nsIFile.NORMAL_FILE_TYPE, FileUtils.PERMS_FILE);
fos.init(activeUpdateFile, flags, FileUtils.PERMS_FILE, 0);
fos.write(xmlContents, xmlContents.length);
fos.close();
updatesFile.remove(false);
});
......@@ -29,6 +29,7 @@ XPCOMUtils.defineLazyModuleGetters(this, {
const UPDATESERVICE_CID = Components.ID("{B3C290A6-3943-4B89-8BBE-C01EB7B3B311}");
const PREF_APP_UPDATE_ALTUPDATEDIRPATH = "app.update.altUpdateDirPath";
const PREF_APP_UPDATE_ALTWINDOWTYPE = "app.update.altwindowtype";
const PREF_APP_UPDATE_BACKGROUNDERRORS = "app.update.backgroundErrors";
const PREF_APP_UPDATE_BACKGROUNDMAXERRORS = "app.update.backgroundMaxErrors";
......@@ -37,6 +38,7 @@ const PREF_APP_UPDATE_BITS_INTRIALGROUP = "app.update.BITS.inTrialGroup";
const PREF_APP_UPDATE_CANCELATIONS = "app.update.cancelations";
const PREF_APP_UPDATE_CANCELATIONS_OSX = "app.update.cancelations.osx";
const PREF_APP_UPDATE_CANCELATIONS_OSX_MAX = "app.update.cancelations.osx.max";
const PREF_APP_UPDATE_DISABLEDFORTESTING = "app.update.disabledForTesting";
const PREF_APP_UPDATE_DOORHANGER = "app.update.doorhanger";
const PREF_APP_UPDATE_DOWNLOAD_ATTEMPTS = "app.update.download.attempts";
const PREF_APP_UPDATE_DOWNLOAD_MAXATTEMPTS = "app.update.download.maxAttempts";
......@@ -44,7 +46,6 @@ const PREF_APP_UPDATE_ELEVATE_NEVER = "app.update.elevate.never";
const PREF_APP_UPDATE_ELEVATE_VERSION = "app.update.elevate.version";
const PREF_APP_UPDATE_ELEVATE_ATTEMPTS = "app.update.elevate.attempts";
const PREF_APP_UPDATE_ELEVATE_MAXATTEMPTS = "app.update.elevate.maxAttempts";
const PREF_APP_UPDATE_DISABLEDFORTESTING = "app.update.disabledForTesting";
const PREF_APP_UPDATE_IDLETIME = "app.update.idletime";
const PREF_APP_UPDATE_LOG = "app.update.log";
const PREF_APP_UPDATE_LOG_FILE = "app.update.log.file";
......@@ -676,6 +677,29 @@ function LOG(string) {
* @return nsIFile object for the location specified.
*/
function getUpdateDirCreate(pathArray) {
if (Cu.isInAutomation) {
// This allows tests to use an alternate updates directory so they can test
// startup behavior.
const MAGIC_TEST_ROOT_PREFIX = "<test-root>";
const PREF_TEST_ROOT = "mochitest.testRoot";
let alternatePath =
Services.prefs.getCharPref(PREF_APP_UPDATE_ALTUPDATEDIRPATH, null);
if (alternatePath && alternatePath.startsWith(MAGIC_TEST_ROOT_PREFIX)) {
let testRoot = Services.prefs.getCharPref(PREF_TEST_ROOT);
let relativePath = alternatePath.substring(MAGIC_TEST_ROOT_PREFIX.length);
if (AppConstants.platform == "win") {
relativePath = relativePath.replace(/\//g, "\\");
}
alternatePath = testRoot + relativePath;
let updateDir = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsIFile);
updateDir.initWithPath(alternatePath);
for (let i = 0; i < pathArray.length; ++i) {
updateDir.append(pathArray[i]);
}
return updateDir;
}
}
return FileUtils.getDir(KEY_UPDROOT, pathArray, true);
}
......@@ -4033,7 +4057,7 @@ Downloader.prototype = {
this._bitsActiveNotifications = true;
}
let updateRootDir = FileUtils.getDir("UpdRootD", [], true);
let updateRootDir = FileUtils.getDir(KEY_UPDROOT, [], true);
let jobName = "MozillaUpdate " + updateRootDir.leafName;
let updatePath = updateDir.path;
if (!Bits.initialized) {
......
......@@ -25,6 +25,7 @@ const KEY_PROFILE_DIR = "ProfD";
// ensure that this is a per-installation pref (i.e. to ensure that migration
// happens for every install rather than once per profile)
const PREF_PREFIX_UPDATE_DIR_MIGRATED = "app.update.migrated.updateDir2.";
const PREF_APP_UPDATE_ALTUPDATEDIRPATH = "app.update.altUpdateDirPath";
const PREF_APP_UPDATE_LOG = "app.update.log";
const PREF_APP_UPDATE_FILE_LOGGING = "app.update.log.file";
......@@ -32,8 +33,34 @@ XPCOMUtils.defineLazyGetter(this, "gLogEnabled", function aus_gLogEnabled() {
return Services.prefs.getBoolPref(PREF_APP_UPDATE_LOG, false);
});
function getUpdateBaseDirNoCreate() {
if (Cu.isInAutomation) {
// This allows tests to use an alternate updates directory so they can test
// startup behavior.
const MAGIC_TEST_ROOT_PREFIX = "<test-root>";
const PREF_TEST_ROOT = "mochitest.testRoot";
let alternatePath =
Services.prefs.getCharPref(PREF_APP_UPDATE_ALTUPDATEDIRPATH, null);
if (alternatePath && alternatePath.startsWith(MAGIC_TEST_ROOT_PREFIX)) {
let testRoot = Services.prefs.getCharPref(PREF_TEST_ROOT);
let relativePath = alternatePath.substring(MAGIC_TEST_ROOT_PREFIX.length);
if (AppConstants.platform == "win") {
relativePath = relativePath.replace(/\//g, "\\");
}
alternatePath = testRoot + relativePath;
let updateDir = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsIFile);
updateDir.initWithPath(alternatePath);
LOG("getUpdateBaseDirNoCreate returning test directory, path: " +
updateDir.path);
return updateDir;
}
}
return FileUtils.getDir(KEY_UPDROOT, [], false);
}
function UpdateServiceStub() {
let updateDir = FileUtils.getDir(KEY_UPDROOT, [], false);
let updateDir = getUpdateBaseDirNoCreate();
let prefUpdateDirMigrated = PREF_PREFIX_UPDATE_DIR_MIGRATED
+ updateDir.leafName;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment