test code - Bug 1314476 - Fix numerous app update eslint errors. r=mhowell

This commit is contained in:
Robert Strong 2016-11-02 10:09:59 -07:00
Родитель ad19951578
Коммит 7c5525d83a
13 изменённых файлов: 796 добавлений и 814 удалений

Просмотреть файл

@ -51,7 +51,7 @@ function handleRequest(aRequest, aResponse) {
let statusReason = params.statusReason ? params.statusReason : "OK";
aResponse.setStatusLine(aRequest.httpVersion, statusCode, statusReason);
aResponse.setHeader("Cache-Control", "no-cache", false);
// When a mar download is started by the update service it can finish
// downloading before the ui has loaded. By specifying a serviceURL for the
// update patch that points to this file and has a slowDownloadMar param the

Просмотреть файл

@ -165,6 +165,56 @@ this.__defineGetter__("gCallback", function() {
: defaultCallback;
});
/**
* nsIObserver for receiving window open and close notifications.
*/
const gWindowObserver = {
observe: function WO_observe(aSubject, aTopic, aData) {
let win = aSubject.QueryInterface(Ci.nsIDOMEventTarget);
if (aTopic == "domwindowclosed") {
if (win.location != URI_UPDATE_PROMPT_DIALOG) {
debugDump("domwindowclosed event for window not being tested - " +
"location: " + win.location + "... returning early");
return;
}
// Allow tests the ability to provide their own function (it must be
// named finishTest) for finishing the test.
try {
finishTest();
}
catch (e) {
finishTestDefault();
}
return;
}
win.addEventListener("load", function WO_observe_onLoad() {
win.removeEventListener("load", WO_observe_onLoad, false);
// Ignore windows other than the update UI window.
if (win.location != URI_UPDATE_PROMPT_DIALOG) {
debugDump("load event for window not being tested - location: " +
win.location + "... returning early");
return;
}
// The first wizard page should always be the dummy page.
let pageid = win.document.documentElement.currentPage.pageid;
if (pageid != PAGEID_DUMMY) {
// This should never happen but if it does this will provide a clue
// for diagnosing the cause.
ok(false, "Unexpected load event - pageid got: " + pageid +
", expected: " + PAGEID_DUMMY + "... returning early");
return;
}
gWin = win;
gDocElem = gWin.document.documentElement;
gDocElem.addEventListener("pageshow", onPageShowDefault, false);
}, false);
}
};
/**
* Default test run function that can be used by most tests. This function uses
* protective measures to prevent the test from failing provided by
@ -507,29 +557,29 @@ function getExpectedButtonStates() {
switch (gTest.pageid) {
case PAGEID_CHECKING:
return { cancel: { disabled: false, hidden: false } };
return {cancel: {disabled: false, hidden: false}};
case PAGEID_FOUND_BASIC:
if (gTest.neverButton) {
return { extra1: { disabled: false, hidden: false },
extra2: { disabled: false, hidden: false },
next : { disabled: false, hidden: false } }
return {extra1: {disabled: false, hidden: false},
extra2: {disabled: false, hidden: false},
next: {disabled: false, hidden: false}}
}
return { extra1: { disabled: false, hidden: false },
next : { disabled: false, hidden: false } };
return {extra1: {disabled: false, hidden: false},
next: {disabled: false, hidden: false}};
case PAGEID_DOWNLOADING:
return { extra1: { disabled: false, hidden: false } };
return {extra1: {disabled: false, hidden: false}};
case PAGEID_NO_UPDATES_FOUND:
case PAGEID_MANUAL_UPDATE:
case PAGEID_UNSUPPORTED:
case PAGEID_ERRORS:
case PAGEID_ERROR_EXTRA:
return { finish: { disabled: false, hidden: false } };
return {finish: {disabled: false, hidden: false}};
case PAGEID_ERROR_PATCHING:
return { next : { disabled: false, hidden: false } };
return {next: { disabled: false, hidden: false}};
case PAGEID_FINISHED:
case PAGEID_FINISHED_BKGRD:
return { extra1: { disabled: false, hidden: false },
finish: { disabled: false, hidden: false } };
return {extra1: { disabled: false, hidden: false},
finish: { disabled: false, hidden: false}};
}
return null;
}
@ -966,53 +1016,3 @@ const errorsPrefObserver = {
}
}
};
/**
* nsIObserver for receiving window open and close notifications.
*/
const gWindowObserver = {
observe: function WO_observe(aSubject, aTopic, aData) {
let win = aSubject.QueryInterface(Ci.nsIDOMEventTarget);
if (aTopic == "domwindowclosed") {
if (win.location != URI_UPDATE_PROMPT_DIALOG) {
debugDump("domwindowclosed event for window not being tested - " +
"location: " + win.location + "... returning early");
return;
}
// Allow tests the ability to provide their own function (it must be
// named finishTest) for finishing the test.
try {
finishTest();
}
catch (e) {
finishTestDefault();
}
return;
}
win.addEventListener("load", function WO_observe_onLoad() {
win.removeEventListener("load", WO_observe_onLoad, false);
// Ignore windows other than the update UI window.
if (win.location != URI_UPDATE_PROMPT_DIALOG) {
debugDump("load event for window not being tested - location: " +
win.location + "... returning early");
return;
}
// The first wizard page should always be the dummy page.
let pageid = win.document.documentElement.currentPage.pageid;
if (pageid != PAGEID_DUMMY) {
// This should never happen but if it does this will provide a clue
// for diagnosing the cause.
ok(false, "Unexpected load event - pageid got: " + pageid +
", expected: " + PAGEID_DUMMY + "... returning early");
return;
}
gWin = win;
gDocElem = gWin.document.documentElement;
gDocElem.addEventListener("pageshow", onPageShowDefault, false);
}, false);
}
};

Просмотреть файл

@ -140,19 +140,6 @@ function reloadUpdateManagerData() {
observe(null, "um-reload-update-data", "");
}
/**
* Sets the app.update.channel preference.
*
* @param aChannel
* The update channel.
*/
function setUpdateChannel(aChannel) {
gChannel = aChannel;
debugDump("setting default pref " + PREF_APP_UPDATE_CHANNEL + " to " + gChannel);
gDefaultPrefBranch.setCharPref(PREF_APP_UPDATE_CHANNEL, gChannel);
gPrefRoot.addObserver(PREF_APP_UPDATE_CHANNEL, observer, false);
}
const observer = {
observe: function(aSubject, aTopic, aData) {
if (aTopic == "nsPref:changed" && aData == PREF_APP_UPDATE_CHANNEL) {
@ -166,6 +153,19 @@ const observer = {
QueryInterface: XPCOMUtils.generateQI([Ci.nsIObserver])
};
/**
* Sets the app.update.channel preference.
*
* @param aChannel
* The update channel.
*/
function setUpdateChannel(aChannel) {
gChannel = aChannel;
debugDump("setting default pref " + PREF_APP_UPDATE_CHANNEL + " to " + gChannel);
gDefaultPrefBranch.setCharPref(PREF_APP_UPDATE_CHANNEL, gChannel);
gPrefRoot.addObserver(PREF_APP_UPDATE_CHANNEL, observer, false);
}
/**
* Sets the app.update.url.override preference.
*
@ -483,8 +483,8 @@ function cleanUpdatesDir(aDir) {
try {
entry.remove(false);
} catch (e) {
logTestInfo("cleanUpdatesDir: unable to remove file. Path: " +
entry.path + ", Exception: " + e);
logTestInfo("cleanUpdatesDir: unable to remove file. Path: " +
entry.path + ", Exception: " + e);
throw (e);
}
}
@ -595,7 +595,7 @@ function getGREBinDir() {
*/
function logTestInfo(aText, aCaller) {
let caller = aCaller ? aCaller : Components.stack.caller;
let now = new Date;
let now = new Date();
let hh = now.getHours();
let mm = now.getMinutes();
let ss = now.getSeconds();

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -4,6 +4,29 @@
Components.utils.import("resource://testing-common/MockRegistrar.jsm");
const WindowWatcher = {
getNewPrompter: function WW_getNewPrompter(aParent) {
Assert.ok(!aParent,
"the aParent parameter should not be defined");
return {
alert: function WW_GNP_alert(aTitle, aText) {
let title = getString("updaterIOErrorTitle");
Assert.equal(aTitle, title,
"the ui string for title" + MSG_SHOULD_EQUAL);
let text = gUpdateBundle.formatStringFromName("updaterIOErrorMsg",
[Services.appinfo.name,
Services.appinfo.name], 2);
Assert.equal(aText, text,
"the ui string for message" + MSG_SHOULD_EQUAL);
doTestFinish();
}
};
},
QueryInterface: XPCOMUtils.generateQI([Ci.nsIWindowWatcher])
};
function run_test() {
setupTestCommon();
@ -41,26 +64,3 @@ function run_test() {
createInstance(Ci.nsIUpdatePrompt);
prompter.showUpdateError(update);
}
const WindowWatcher = {
getNewPrompter: function WW_getNewPrompter(aParent) {
Assert.ok(!aParent,
"the aParent parameter should not be defined");
return {
alert: function WW_GNP_alert(aTitle, aText) {
let title = getString("updaterIOErrorTitle");
Assert.equal(aTitle, title,
"the ui string for title" + MSG_SHOULD_EQUAL);
let text = gUpdateBundle.formatStringFromName("updaterIOErrorMsg",
[Services.appinfo.name,
Services.appinfo.name], 2);
Assert.equal(aText, text,
"the ui string for message" + MSG_SHOULD_EQUAL);
doTestFinish();
}
};
},
QueryInterface: XPCOMUtils.generateQI([Ci.nsIWindowWatcher])
};

Просмотреть файл

@ -104,40 +104,40 @@ IncrementalDownload.prototype = {
// Do the actual operation async to give a chance for observers
// to add themselves.
tm.mainThread.dispatch(function() {
this._observer = observer.QueryInterface(Ci.nsIRequestObserver);
this._ctxt = ctxt;
this._observer.onStartRequest(this, this._ctxt);
let mar = getTestDirFile(FILE_SIMPLE_MAR);
mar.copyTo(this._destination.parent, this._destination.leafName);
let status = Cr.NS_OK
switch (gIncrementalDownloadErrorType++) {
case 0:
status = Cr.NS_ERROR_NET_RESET;
break;
case 1:
status = Cr.NS_ERROR_CONNECTION_REFUSED;
break;
case 2:
status = Cr.NS_ERROR_NET_RESET;
break;
case 3:
status = Cr.NS_OK;
break;
case 4:
status = Cr.NS_ERROR_OFFLINE;
// After we report offline, we want to eventually show offline
// status being changed to online.
let tm = Cc["@mozilla.org/thread-manager;1"].
getService(Ci.nsIThreadManager);
tm.mainThread.dispatch(function() {
Services.obs.notifyObservers(gAUS,
"network:offline-status-changed",
"online");
}, Ci.nsIThread.DISPATCH_NORMAL);
break;
}
this._observer.onStopRequest(this, this._ctxt, status);
}.bind(this), Ci.nsIThread.DISPATCH_NORMAL);
this._observer = observer.QueryInterface(Ci.nsIRequestObserver);
this._ctxt = ctxt;
this._observer.onStartRequest(this, this._ctxt);
let mar = getTestDirFile(FILE_SIMPLE_MAR);
mar.copyTo(this._destination.parent, this._destination.leafName);
let status = Cr.NS_OK
switch (gIncrementalDownloadErrorType++) {
case 0:
status = Cr.NS_ERROR_NET_RESET;
break;
case 1:
status = Cr.NS_ERROR_CONNECTION_REFUSED;
break;
case 2:
status = Cr.NS_ERROR_NET_RESET;
break;
case 3:
status = Cr.NS_OK;
break;
case 4:
status = Cr.NS_ERROR_OFFLINE;
// After we report offline, we want to eventually show offline
// status being changed to online.
let tm2 = Cc["@mozilla.org/thread-manager;1"].
getService(Ci.nsIThreadManager);
tm2.mainThread.dispatch(function() {
Services.obs.notifyObservers(gAUS,
"network:offline-status-changed",
"online");
}, Ci.nsIThread.DISPATCH_NORMAL);
break;
}
this._observer.onStopRequest(this, this._ctxt, status);
}.bind(this), Ci.nsIThread.DISPATCH_NORMAL);
},
get URI() {

Просмотреть файл

@ -4,6 +4,23 @@
Components.utils.import("resource://testing-common/MockRegistrar.jsm");
const WindowWatcher = {
openWindow: function(aParent, aUrl, aName, aFeatures, aArgs) {
gCheckFunc();
},
QueryInterface: XPCOMUtils.generateQI([Ci.nsIWindowWatcher])
};
const WindowMediator = {
getMostRecentWindow: function(aWindowType) {
do_execute_soon(check_status);
return { getInterface: XPCOMUtils.generateQI([Ci.nsIDOMWindow]) };
},
QueryInterface: XPCOMUtils.generateQI([Ci.nsIWindowMediator])
};
function run_test() {
setupTestCommon();
// Calling do_get_profile prevents an error from being logged
@ -56,20 +73,3 @@ function check_status() {
function check_showUpdateAvailable() {
do_throw("showUpdateAvailable should not have called openWindow!");
}
const WindowWatcher = {
openWindow: function(aParent, aUrl, aName, aFeatures, aArgs) {
gCheckFunc();
},
QueryInterface: XPCOMUtils.generateQI([Ci.nsIWindowWatcher])
};
const WindowMediator = {
getMostRecentWindow: function(aWindowType) {
do_execute_soon(check_status);
return { getInterface: XPCOMUtils.generateQI([Ci.nsIDOMWindow]) };
},
QueryInterface: XPCOMUtils.generateQI([Ci.nsIWindowMediator])
};

Просмотреть файл

@ -9,6 +9,18 @@ Components.utils.import("resource://testing-common/MockRegistrar.jsm");
* showUpdateError when the app.update.silent preference is true.
*/
const WindowWatcher = {
openWindow: function(aParent, aUrl, aName, aFeatures, aArgs) {
gCheckFunc();
},
getNewPrompter: function(aParent) {
gCheckFunc();
},
QueryInterface: XPCOMUtils.generateQI([Ci.nsIWindowWatcher])
};
function run_test() {
setupTestCommon();
@ -62,15 +74,3 @@ function check_showUpdateAvailable() {
function check_showUpdateError() {
do_throw("showUpdateError should not have seen getNewPrompter!");
}
const WindowWatcher = {
openWindow: function(aParent, aUrl, aName, aFeatures, aArgs) {
gCheckFunc();
},
getNewPrompter: function(aParent) {
gCheckFunc();
},
QueryInterface: XPCOMUtils.generateQI([Ci.nsIWindowWatcher])
};

Просмотреть файл

@ -4,6 +4,22 @@
Cu.import("resource://testing-common/MockRegistrar.jsm");
const WindowWatcher = {
openWindow: function(aParent, aUrl, aName, aFeatures, aArgs) {
check_showUpdateAvailable();
},
QueryInterface: XPCOMUtils.generateQI([Ci.nsIWindowWatcher])
};
const WindowMediator = {
getMostRecentWindow: function(aWindowType) {
return null;
},
QueryInterface: XPCOMUtils.generateQI([Ci.nsIWindowMediator])
};
function run_test() {
setupTestCommon();
@ -56,19 +72,3 @@ function check_test() {
function check_showUpdateAvailable() {
do_throw("showUpdateAvailable should not have called openWindow!");
}
const WindowWatcher = {
openWindow: function(aParent, aUrl, aName, aFeatures, aArgs) {
check_showUpdateAvailable();
},
QueryInterface: XPCOMUtils.generateQI([Ci.nsIWindowWatcher])
};
const WindowMediator = {
getMostRecentWindow: function(aWindowType) {
return null;
},
QueryInterface: XPCOMUtils.generateQI([Ci.nsIWindowMediator])
};

Просмотреть файл

@ -179,7 +179,7 @@ function getServicePack() {
// http://msdn.microsoft.com/en-us/library/ms724833%28v=vs.85%29.aspx
const SZCSDVERSIONLENGTH = 128;
const OSVERSIONINFOEXW = new ctypes.StructType('OSVERSIONINFOEXW',
[
[
{dwOSVersionInfoSize: DWORD},
{dwMajorVersion: DWORD},
{dwMinorVersion: DWORD},
@ -191,7 +191,7 @@ function getServicePack() {
{wSuiteMask: WORD},
{wProductType: BYTE},
{wReserved: BYTE}
]);
]);
let kernel32 = ctypes.open("kernel32");
try {
@ -224,7 +224,7 @@ function getProcArchitecture() {
// This structure is described at:
// http://msdn.microsoft.com/en-us/library/ms724958%28v=vs.85%29.aspx
const SYSTEM_INFO = new ctypes.StructType('SYSTEM_INFO',
[
[
{wProcessorArchitecture: WORD},
{wReserved: WORD},
{dwPageSize: DWORD},
@ -236,7 +236,7 @@ function getProcArchitecture() {
{dwAllocationGranularity: DWORD},
{wProcessorLevel: WORD},
{wProcessorRevision: WORD}
]);
]);
let kernel32 = ctypes.open("kernel32");
try {
@ -293,8 +293,8 @@ function getSystemCapabilities() {
instructionSet = "MMX";
}
} catch (e) {
Cu.reportError("Error getting processor instruction set. " +
"Exception: " + e);
Cu.reportError("Error getting processor instruction set. " +
"Exception: " + e);
}
lib.close();

Просмотреть файл

@ -90,17 +90,17 @@ function setupSymLinks() {
createSymlink();
do_register_cleanup(removeSymlink);
gTestFiles.splice(gTestFiles.length - 3, 0,
{
description : "Readable symlink",
fileName : "link",
relPathDir : DIR_RESOURCES,
originalContents : "test",
compareContents : "test",
originalFile : null,
compareFile : null,
originalPerms : 0o666,
comparePerms : 0o666
});
{
description: "Readable symlink",
fileName: "link",
relPathDir: DIR_RESOURCES,
originalContents: "test",
compareContents: "test",
originalFile: null,
compareFile: null,
originalPerms: 0o666,
comparePerms: 0o666
});
}
}

Просмотреть файл

@ -107,17 +107,17 @@ function setupSymLinks() {
createSymlink();
do_register_cleanup(removeSymlink);
gTestFiles.splice(gTestFiles.length - 3, 0,
{
description : "Readable symlink",
fileName : "link",
relPathDir : DIR_RESOURCES,
originalContents : "test",
compareContents : "test",
originalFile : null,
compareFile : null,
originalPerms : 0o666,
comparePerms : 0o666
});
{
description: "Readable symlink",
fileName: "link",
relPathDir: DIR_RESOURCES,
originalContents: "test",
compareContents: "test",
originalFile: null,
compareFile: null,
originalPerms: 0o666,
comparePerms: 0o666
});
}
}

Просмотреть файл

@ -107,17 +107,17 @@ function setupSymLinks() {
createSymlink();
do_register_cleanup(removeSymlink);
gTestFiles.splice(gTestFiles.length - 3, 0,
{
description : "Readable symlink",
fileName : "link",
relPathDir : DIR_RESOURCES,
originalContents : "test",
compareContents : "test",
originalFile : null,
compareFile : null,
originalPerms : 0o666,
comparePerms : 0o666
});
{
description: "Readable symlink",
fileName: "link",
relPathDir: DIR_RESOURCES,
originalContents: "test",
compareContents: "test",
originalFile: null,
compareFile: null,
originalPerms: 0o666,
comparePerms: 0o666
});
}
}