Bug 1571656 - Use Assert.jsm numeric comparison functions in tests r=mixedpuppy,MattN

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

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Moritz Birghan 2019-08-19 07:17:12 +00:00
Родитель 421c27f643
Коммит 240771fa29
30 изменённых файлов: 83 добавлений и 63 удалений

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

@ -45,6 +45,6 @@ add_task(async function test_IE_history() {
let entry = await PlacesUtils.history.fetch(url, { includeVisits: true });
Assert.equal(entry.url, url, "Should have the correct URL");
Assert.equal(entry.title, title, "Should have the correct title");
Assert.ok(entry.visits.length > 0, "Should have some visits");
Assert.greater(entry.visits.length, 0, "Should have some visits");
}
});

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

@ -38,7 +38,7 @@ add_task(async function() {
},
dialog => {
let savedItemId = dialog.gEditItemOverlay.itemId;
Assert.ok(savedItemId > 0, "Found the itemId");
Assert.greater(savedItemId, 0, "Found the itemId");
return PlacesTestUtils.waitForNotification(
"onItemRemoved",
id => id === savedItemId

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

@ -145,7 +145,7 @@ add_task(async function test_query_on_toolbar() {
});
// Get first child and check it is the just inserted query.
Assert.ok(toolbarNode.childCount > 0, "Toolbar node has children");
Assert.greater(toolbarNode.childCount, 0, "Toolbar node has children");
let queryNode = toolbarNode.getChild(0);
Assert.equal(
queryNode.title,

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

@ -132,7 +132,7 @@ add_task(async function test_separator_first() {
await promiseReady;
let children = gToolbarContent.children;
Assert.ok(children.length > 2, "Multiple elements are visible");
Assert.greater(children.length, 2, "Multiple elements are visible");
Assert.equal(
children[1]._placesNode.uri,
"http://test.places.0/",

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

@ -80,7 +80,7 @@ async function setupBackgroundTabs(testFn) {
* background state.
*/
async function crashBackgroundTabs(tabs) {
Assert.ok(tabs.length > 0, "Need to crash at least one tab.");
Assert.greater(tabs.length, 0, "Need to crash at least one tab.");
for (let tab of tabs) {
Assert.ok(tab.linkedBrowser.isRemoteBrowser, "tab is remote");
}

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

@ -21,7 +21,7 @@ add_task(async function test() {
);
let resultCount = UrlbarTestUtils.getResultCount(window);
Assert.ok(resultCount > 0, "At least one result");
Assert.greater(resultCount, 0, "At least one result");
for (let i = 0; i < resultCount; i++) {
EventUtils.synthesizeKey("KEY_ArrowDown");

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

@ -62,7 +62,11 @@ add_task(async function test() {
var viewBookmark = content.document.querySelector("a#viewBookmark");
viewBookmark.click();
Assert.ok(viewBookmark.href.length > 0, "viewBookmark button has href");
Assert.greater(
viewBookmark.href.length,
0,
"viewBookmark button has href"
);
var viewer = content.wrappedJSObject.PDFViewerApplication;
await viewer.close();

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

@ -310,7 +310,11 @@ add_task(async function simple() {
// unregister
PageActions._actionsByID.delete(action.id);
let index = PageActions._nonBuiltInActions.findIndex(a => a.id == action.id);
Assert.ok(index >= 0, "Action should be in _nonBuiltInActions to begin with");
Assert.greaterEqual(
index,
0,
"Action should be in _nonBuiltInActions to begin with"
);
PageActions._nonBuiltInActions.splice(index, 1);
// register again

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

@ -575,7 +575,7 @@ add_task(async function test_dont_decrement_chances_on_same_day() {
let initChances = UnsubmittedCrashHandler.prefs.getIntPref(
"chancesUntilSuppress"
);
Assert.ok(initChances > 1, "We should start with at least 1 chance.");
Assert.greater(initChances, 1, "We should start with at least 1 chance.");
await createPendingCrashReports(1);
let notification = await UnsubmittedCrashHandler.checkForUnsubmittedCrashReports();
@ -625,7 +625,7 @@ add_task(async function test_decrement_chances_on_other_day() {
let initChances = UnsubmittedCrashHandler.prefs.getIntPref(
"chancesUntilSuppress"
);
Assert.ok(initChances > 1, "We should start with at least 1 chance.");
Assert.greater(initChances, 1, "We should start with at least 1 chance.");
await createPendingCrashReports(1);
let notification = await UnsubmittedCrashHandler.checkForUnsubmittedCrashReports();

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

@ -148,14 +148,14 @@ add_task(async function test() {
let results = await ChromeUtils.requestPerformanceMetrics();
exploreResults(results);
Assert.ok(workerDuration > 0, "Worker duration should be positive");
Assert.ok(workerTotal > 0, "Worker count should be positive");
Assert.ok(duration > 0, "Duration should be positive");
Assert.ok(total > 0, "Should get a positive count");
Assert.greater(workerDuration, 0, "Worker duration should be positive");
Assert.greater(workerTotal, 0, "Worker count should be positive");
Assert.greater(duration, 0, "Duration should be positive");
Assert.greater(total, 0, "Should get a positive count");
Assert.ok(parentProcessEvent, "parent process sent back some events");
Assert.ok(isTopLevel, "example.com as a top level window");
Assert.ok(aboutMemoryFound, "about:memory");
Assert.ok(heapUsage > 0, "got some memory value reported");
Assert.greater(heapUsage, 0, "got some memory value reported");
Assert.ok(sharedWorker, "We got some info from a shared worker");
let numCounters = counterIds.length;
Assert.ok(
@ -185,8 +185,8 @@ add_task(async function test() {
workerTotal > previousWorkerTotal,
"Worker count should be positive"
);
Assert.ok(duration > previousDuration, "Duration should be positive");
Assert.ok(total > previousTotal, "Should get a positive count");
Assert.greater(duration, previousDuration, "Duration should be positive");
Assert.greater(total, previousTotal, "Should get a positive count");
// load a tab with a setInterval, we should get counters on TaskCategory::Timer
await BrowserTestUtils.withNewTab(
@ -196,7 +196,7 @@ add_task(async function test() {
let previousTimerCalls = timerCalls;
results = await ChromeUtils.requestPerformanceMetrics();
exploreResults(results, tabId);
Assert.ok(timerCalls > previousTimerCalls, "Got timer calls");
Assert.greater(timerCalls, previousTimerCalls, "Got timer calls");
}
);
@ -208,7 +208,7 @@ add_task(async function test() {
let previousTimerCalls = timerCalls;
results = await ChromeUtils.requestPerformanceMetrics();
exploreResults(results, tabId);
Assert.ok(timerCalls > previousTimerCalls, "Got timer calls");
Assert.greater(timerCalls, previousTimerCalls, "Got timer calls");
}
);
@ -219,7 +219,7 @@ add_task(async function test() {
let tabId = gBrowser.selectedBrowser.outerWindowID;
results = await ChromeUtils.requestPerformanceMetrics();
exploreResults(results, tabId);
Assert.ok(mediaMemory > 0, "Got some memory used for media");
Assert.greater(mediaMemory, 0, "Got some memory used for media");
}
);
}

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

@ -244,7 +244,11 @@ function run_test() {
numMigrated += 1;
}
// check we found at least 1 record that was migrated.
Assert.ok(numMigrated > 0, "we found at least 1 record that was migrated");
Assert.greater(
numMigrated,
0,
"we found at least 1 record that was migrated"
);
// This permission should always be there.
let ssm = Cc["@mozilla.org/scriptsecuritymanager;1"].getService(

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

@ -33,7 +33,7 @@ function run_test()
const pattern = osprefs.getDateTimePattern(...test);
if (test[0] !== osprefs.dateTimeFormatStyleNone &&
test[1] !== osprefs.dateTImeFormatStyleNone) {
Assert.ok(pattern.length > 0, "pattern is not empty.");
Assert.greater(pattern.length, 0, "pattern is not empty.");
}
}

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

@ -15,8 +15,8 @@ async function testBody() {
do_log_info("now: " + now / 1000000);
do_log_info("startHibernation: " + startHibernation / 1000000);
do_log_info("stopHibernation: " + stopHibernation / 1000000);
Assert.ok(startHibernation < now, "startHibernation ok");
Assert.ok(stopHibernation < now, "stopHibernation ok");
Assert.less(startHibernation, now, "startHibernation ok");
Assert.less(stopHibernation, now, "stopHibernation ok");
// When the watchdog runs, it hibernates if there's been no activity for the
// last 2 seconds, otherwise it sleeps for 1 second. As such, given perfect
@ -42,8 +42,8 @@ async function testBody() {
// making sure this behavior is roughly as expected on the macro scale,
// so we add a 1 second fuzz factor here.
const FUZZ_FACTOR = 1 * 1000 * 1000;
Assert.ok(stateChange > now + 10*1000*1000 - FUZZ_FACTOR, "stateChange ok");
Assert.ok(startHibernation > now + 2*1000*1000 - FUZZ_FACTOR, "startHibernation ok");
Assert.ok(startHibernation < now + 5*1000*1000 + FUZZ_FACTOR, "startHibernation ok");
Assert.ok(stopHibernation > now + 10*1000*1000 - FUZZ_FACTOR, "stopHibernation ok");
Assert.greater(stateChange, now + 10*1000*1000 - FUZZ_FACTOR, "stateChange ok");
Assert.greater(startHibernation, now + 2*1000*1000 - FUZZ_FACTOR, "startHibernation ok");
Assert.less(startHibernation, now + 5*1000*1000 + FUZZ_FACTOR, "startHibernation ok");
Assert.greater(stopHibernation, now + 10*1000*1000 - FUZZ_FACTOR, "stopHibernation ok");
}

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

@ -1001,7 +1001,7 @@ function CustomPipe(name) {
"])"
);
Assert.ok(increments.length > 0, "bad increments");
Assert.greater(increments.length, 0, "bad increments");
Assert.ok(
increments.every(function(v) {
return v > 0;

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

@ -611,7 +611,7 @@ add_task(async function test_ignore_system() {
let addon = reconciler.getAddonStateFromSyncGUID(guid);
Assert.notEqual(addon.id, SYSTEM_ADDON_ID);
}
Assert.ok(num > 1, "should have seen at least one.");
Assert.greater(num, 1, "should have seen at least one.");
});
add_task(async function test_incoming_system() {

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

@ -114,7 +114,7 @@ async function test_addCrashBase(crashId, allThreads) {
}
let frames = stackTraces.threads[0].frames;
Assert.ok(frames && frames.length > 0, "The stack trace is present.\n");
Assert.greater(frames && frames.length, 0, "The stack trace is present.\n");
} catch (e) {
Assert.ok(false, "StackTraces does not contain valid JSON.");
}

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

@ -382,7 +382,7 @@ add_task(async function create_bookmark_frecency() {
checkBookmarkObject(bm);
await PlacesTestUtils.promiseAsyncUpdates();
Assert.ok(frecencyForUrl(bm.url) > 0, "Check frecency has been updated");
Assert.greater(frecencyForUrl(bm.url), 0, "Check frecency has been updated");
});
add_task(async function create_bookmark_without_type() {

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

@ -308,7 +308,7 @@ add_task(async function update_url() {
checkBookmarkObject(bm);
let lastModified = bm.lastModified;
let frecency = frecencyForUrl(bm.url);
Assert.ok(frecency > 0, "Check frecency has been updated");
Assert.greater(frecency, 0, "Check frecency has been updated");
bm = await PlacesUtils.bookmarks.update({
guid: bm.guid,

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

@ -32,7 +32,7 @@ add_task(async function() {
event.index == 0 || event.index == lastIndex + 1,
"Consecutive indices"
);
Assert.ok(event.dateAdded >= now, "Found a valid dateAdded");
Assert.greaterEqual(event.dateAdded, now, "Found a valid dateAdded");
Assert.ok(PlacesUtils.isValidGuid(event.guid), "guid is valid");
}
},

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

@ -906,9 +906,9 @@ async function compareFavicons(icon1, icon2, msg) {
}
let data1 = await getIconData(icon1);
Assert.ok(data1.length > 0, "Should fetch icon data");
Assert.greater(data1.length, 0, "Should fetch icon data");
let data2 = await getIconData(icon2);
Assert.ok(data2.length > 0, "Should fetch icon data");
Assert.greater(data2.length, 0, "Should fetch icon data");
Assert.deepEqual(data1, data2, msg);
}

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

@ -13,7 +13,7 @@ add_task(async function setup() {
}
version--;
}
Assert.ok(version > 0, "Found a valid database version");
Assert.greater(version, 0, "Found a valid database version");
await setupPlacesDatabase(`places_v${version}.sqlite`);
// Downgrade the schema version to the first supported one.
let path = OS.Path.join(OS.Constants.Path.profileDir, DB_FILENAME);

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

@ -33,7 +33,7 @@ add_task(async function test_eraseEverything() {
Assert.equal(root.childCount, 4, "The folder should have 4 children");
for (let i = 0; i < root.childCount; ++i) {
let node = root.getChild(i);
Assert.ok(node.itemId > 0, "The node should have an itemId");
Assert.greater(node.itemId, 0, "The node should have an itemId");
}
Assert.equal(root.getChild(0).title, "title 1");
Assert.equal(root.getChild(1).title, "title 2");

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

@ -259,15 +259,15 @@ add_task(async function groupByHost() {
let httpFrec = frecencyForUrl("http://example.com/");
let httpsFrec = frecencyForUrl("https://example.com/");
let otherFrec = frecencyForUrl("https://mozilla.org/");
Assert.ok(httpFrec < httpsFrec, "Sanity check");
Assert.ok(httpsFrec < otherFrec, "Sanity check");
Assert.less(httpFrec, httpsFrec, "Sanity check");
Assert.less(httpsFrec, otherFrec, "Sanity check");
// Make sure the frecencies of the three origins are as expected in relation
// to the threshold.
let threshold = await getOriginAutofillThreshold();
Assert.ok(httpFrec < threshold, "http origin should be < threshold");
Assert.ok(httpsFrec < threshold, "https origin should be < threshold");
Assert.ok(threshold <= otherFrec, "Other origin should cross threshold");
Assert.less(httpFrec, threshold, "http origin should be < threshold");
Assert.less(httpsFrec, threshold, "https origin should be < threshold");
Assert.lessEqual(threshold, otherFrec, "Other origin should cross threshold");
Assert.ok(
threshold <= httpFrec + httpsFrec,
@ -328,15 +328,15 @@ add_task(async function groupByHostNonDefaultStddevMultiplier() {
let httpFrec = frecencyForUrl("http://example.com/");
let httpsFrec = frecencyForUrl("https://example.com/");
let otherFrec = frecencyForUrl("https://mozilla.org/");
Assert.ok(httpFrec < httpsFrec, "Sanity check");
Assert.ok(httpsFrec < otherFrec, "Sanity check");
Assert.less(httpFrec, httpsFrec, "Sanity check");
Assert.less(httpsFrec, otherFrec, "Sanity check");
// Make sure the frecencies of the three origins are as expected in relation
// to the threshold.
let threshold = await getOriginAutofillThreshold();
Assert.ok(httpFrec < threshold, "http origin should be < threshold");
Assert.ok(httpsFrec < threshold, "https origin should be < threshold");
Assert.ok(threshold <= otherFrec, "Other origin should cross threshold");
Assert.less(httpFrec, threshold, "http origin should be < threshold");
Assert.less(httpsFrec, threshold, "https origin should be < threshold");
Assert.lessEqual(threshold, otherFrec, "Other origin should cross threshold");
Assert.ok(
threshold <= httpFrec + httpsFrec,

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

@ -756,7 +756,11 @@ function checkSystemSection(data) {
Assert.ok(Array.isArray(gfxData.monitors));
if (gIsWindows || gIsMac || gIsLinux) {
Assert.ok(gfxData.monitors.length >= 1, "There is at least one monitor.");
Assert.greaterEqual(
gfxData.monitors.length,
1,
"There is at least one monitor."
);
Assert.equal(typeof gfxData.monitors[0].screenWidth, "number");
Assert.equal(typeof gfxData.monitors[0].screenHeight, "number");
if (gIsWindows) {

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

@ -69,7 +69,7 @@ add_task(async function test_record() {
Assert.ok(PHASE0 in data, "The file contains the expected key");
let duration = data[PHASE0];
Assert.equal(typeof duration, "number");
Assert.ok(duration >= 0, "Duration is a non-negative number");
Assert.greaterEqual(duration, 0, "Duration is a non-negative number");
Assert.ok(
duration <= Math.ceil((t1 - t0) / 1000) + 1,
"Duration is reasonable"

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

@ -1053,7 +1053,7 @@ add_task(async function getTopFrencentSites_maxLimit() {
links.length < MANY_LINKS,
"query default limited to less than many"
);
Assert.ok(links.length > 6, "query default to more than visible count");
Assert.greater(links.length, 6, "query default to more than visible count");
});
add_task(async function getTopFrencentSites_allowedProtocols() {

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

@ -14,7 +14,7 @@ add_task(async function test_setTimeout() {
100
);
Assert.equal(typeof timeout1, "number", "setTimeout returns a number");
Assert.ok(timeout1 > 0, "setTimeout returns a positive number");
Assert.greater(timeout1, 0, "setTimeout returns a positive number");
imported.clearTimeout(timeout1);
@ -32,7 +32,7 @@ add_task(async function test_setTimeout() {
);
Assert.equal(typeof timeout2, "number", "setTimeout returns a number");
Assert.ok(timeout2 > 0, "setTimeout returns a positive number");
Assert.greater(timeout2, 0, "setTimeout returns a positive number");
Assert.notEqual(
timeout1,
timeout2,
@ -49,7 +49,7 @@ add_task(async function test_setTimeoutWithTarget() {
target
);
Assert.equal(typeof timeout1, "number", "setTimeout returns a number");
Assert.ok(timeout1 > 0, "setTimeout returns a positive number");
Assert.greater(timeout1, 0, "setTimeout returns a positive number");
imported.clearTimeout(timeout1);
@ -68,7 +68,7 @@ add_task(async function test_setTimeoutWithTarget() {
);
Assert.equal(typeof timeout2, "number", "setTimeout returns a number");
Assert.ok(timeout2 > 0, "setTimeout returns a positive number");
Assert.greater(timeout2, 0, "setTimeout returns a positive number");
Assert.notEqual(
timeout1,
timeout2,
@ -83,7 +83,7 @@ add_task(async function test_setInterval() {
100
);
Assert.equal(typeof interval1, "number", "setInterval returns a number");
Assert.ok(interval1 > 0, "setTimeout returns a positive number");
Assert.greater(interval1, 0, "setTimeout returns a positive number");
imported.clearInterval(interval1);
@ -117,7 +117,7 @@ add_task(async function test_setIntervalWithTarget() {
target
);
Assert.equal(typeof interval1, "number", "setInterval returns a number");
Assert.ok(interval1 > 0, "setTimeout returns a positive number");
Assert.greater(interval1, 0, "setTimeout returns a positive number");
imported.clearInterval(interval1);
@ -177,7 +177,7 @@ add_task(async function test_requestIdleCallback() {
"number",
"requestIdleCallback returns a number"
);
Assert.ok(request1 > 0, "setTimeout returns a positive number");
Assert.greater(request1, 0, "setTimeout returns a positive number");
imported.cancelIdleCallback(request1);
@ -205,7 +205,11 @@ add_task(async function test_requestIdleCallback() {
"number",
"requestIdleCallback returns a number"
);
Assert.ok(request2 > 0, "requestIdleCallback returns a positive number");
Assert.greater(
request2,
0,
"requestIdleCallback returns a positive number"
);
Assert.notEqual(
request1,
request2,

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

@ -8,7 +8,7 @@ add_task(async function test_long_id() {
createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1");
await promiseStartupManager();
Assert.ok(ID.length > 64, "ID is > 64 characters");
Assert.greater(ID.length, 64, "ID is > 64 characters");
await promiseInstallFile(do_get_file("data/signing_checks/long.xpi"));
let addon = await promiseAddonByID(ID);

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

@ -34,9 +34,9 @@ add_task(async function test_proc_info() {
}
// see https://bugzilla.mozilla.org/show_bug.cgi?id=1529023
if (!MAC) {
Assert.ok(cpuThreads > 0, "Got some cpu time in the threads");
Assert.greater(cpuThreads, 0, "Got some cpu time in the threads");
}
Assert.ok(cpuUser > 0, "Got some cpu time");
Assert.greater(cpuUser, 0, "Got some cpu time");
}
);
});

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

@ -10,7 +10,7 @@ function test_getSharingProviders() {
Ci.nsIMacSharingService
);
let providers = sharingService.getSharingProviders("http://example.org");
Assert.ok(providers.length > 1, "There are providers returned");
Assert.greater(providers.length, 1, "There are providers returned");
providers.forEach(provider => {
Assert.ok("name" in provider, "Provider has name");
Assert.ok("menuItemTitle" in provider, "Provider has menuItemTitle");