Bug 1241930: Part 6 - convert all assertion methods used inside content tasks to the Assert.* family in toolkit tests. r=mconley

This commit is contained in:
Mike de Boer 2016-03-04 14:32:34 +01:00
parent 86fc8c7fb0
commit 5d17ca0675
14 changed files with 64 additions and 78 deletions

View File

@ -13,7 +13,7 @@ function task(consts) {
let promise = new Promise(r => { resolve = r; });
function unexpectedContentEvent(evt) {
ok(false, "Received a " + evt.type + " event on content");
Assert.ok(false, "Received a " + evt.type + " event on content");
}
var gDoc = null;
@ -40,8 +40,8 @@ function task(consts) {
function test_inputAddHandler(evt) {
removeEventListener(evt.type, test_inputAddHandler, false);
is(evt.target.id, consts.INPUT_ID,
evt.type + " event targets correct input element (added password element)");
Assert.equal(evt.target.id, consts.INPUT_ID,
evt.type + " event targets correct input element (added password element)");
gDoc.defaultView.setTimeout(test_inputAddOutsideForm, 0);
}
@ -57,8 +57,8 @@ function task(consts) {
function test_inputAddOutsideFormHandler(evt) {
removeEventListener(evt.type, test_inputAddOutsideFormHandler, false);
is(evt.target.id, consts.BODY_INPUT_ID,
evt.type + " event targets correct input element (added password element outside form)");
Assert.equal(evt.target.id, consts.BODY_INPUT_ID,
evt.type + " event targets correct input element (added password element outside form)");
gDoc.defaultView.setTimeout(test_inputChangesType, 0);
}
@ -70,13 +70,13 @@ function task(consts) {
function test_inputChangesTypeHandler(evt) {
removeEventListener(evt.type, test_inputChangesTypeHandler, false);
is(evt.target.id, consts.CHANGE_INPUT_ID,
evt.type + " event targets correct input element (changed type)");
Assert.equal(evt.target.id, consts.CHANGE_INPUT_ID,
evt.type + " event targets correct input element (changed type)");
gDoc.defaultView.setTimeout(completeTest, 0);
}
function completeTest() {
ok(true, "Test completed");
Assert.ok(true, "Test completed");
gDoc.removeEventListener("DOMInputPasswordAdded", unexpectedContentEvent, false);
resolve();
}

View File

@ -67,18 +67,13 @@ add_task(function* test_fill() {
document.getElementById("login-fill-use").click();
yield promiseHidden;
let result = yield ContentTask.spawn(browser, null, function* () {
yield ContentTask.spawn(browser, null, function* () {
let doc = content.document;
return {
username: doc.getElementById("form-basic-username").value,
password: doc.getElementById("form-basic-password").value,
}
Assert.equal(doc.getElementById("form-basic-username").value, "username",
"result.username === \"username\"");
Assert.equal(doc.getElementById("form-basic-password").value, "password",
"result.password === \"password\"");
});
Assert.equal(result.username, "username",
'result.username === "username"');
Assert.equal(result.password, "password",
'result.password === "password"');
});
Services.logins.removeAllLogins();

View File

@ -34,20 +34,17 @@ add_task(function* () {
PlacesUtils.history.addObserver(observer, false);
});
let title = yield ContentTask.spawn(tab.linkedBrowser, {}, function* () {
yield ContentTask.spawn(tab.linkedBrowser, null, function* () {
let title = content.document.title;
content.history.pushState('', '', 'new_page');
return title;
Assert.ok(title, "Content window should initially have a title.");
});
ok(title, 'Content window should initially have a title.');
let newtitle = yield newTitlePromise;
title = yield ContentTask.spawn(tab.linkedBrowser, {}, function* () {
return content.document.title;
yield ContentTask.spawn(tab.linkedBrowser, { newtitle }, function* (args) {
Assert.equal(args.newtitle, content.document.title, "Title after pushstate.");
});
is(newtitle, title, 'Title after pushstate.');
yield PlacesTestUtils.clearHistory();
gBrowser.removeTab(tab);

View File

@ -45,13 +45,11 @@ function errorListener() {
// This is an error page.
ContentTask.spawn(ourTab.linkedBrowser, kUniqueURI.spec, function(uri) {
is(content.document.documentURI.substring(0, 27),
"about:neterror?e=netOffline",
"Document URI is the error page.");
Assert.equal(content.document.documentURI.substring(0, 27),
"about:neterror?e=netOffline", "Document URI is the error page.");
// But location bar should show the original request.
is(content.location.href, uri,
"Docshell URI is the original URI.");
Assert.equal(content.location.href, uri, "Docshell URI is the original URI.");
}).then(() => {
// Global history does not record URI of a failed request.
return PlacesTestUtils.promiseAsyncUpdates().then(() => {
@ -73,8 +71,8 @@ function errorAsyncListener(aURI, aIsVisited) {
.then(reloadListener);
ContentTask.spawn(ourTab.linkedBrowser, null, function() {
ok(content.document.getElementById("errorTryAgain"),
"The error page has got a #errorTryAgain element");
Assert.ok(content.document.getElementById("errorTryAgain"),
"The error page has got a #errorTryAgain element");
content.document.getElementById("errorTryAgain").click();
});
}
@ -89,8 +87,8 @@ function reloadListener() {
ContentTask.spawn(ourTab.linkedBrowser, kUniqueURI.spec, function(uri) {
// This is not an error page.
is(content.document.documentURI, uri,
"Document URI is not the offline-error page, but the original URI.");
Assert.equal(content.document.documentURI, uri,
"Document URI is not the offline-error page, but the original URI.");
}).then(() => {
// Check if global history remembers the successfully-requested URI.
PlacesTestUtils.promiseAsyncUpdates().then(() => {

View File

@ -6,18 +6,18 @@ const source = '<html xmlns="http://www.w3.org/1999/xhtml"><body><p>This is a pa
add_task(function *() {
let viewSourceTab = yield* openDocumentSelect("data:text/html," + source, "p");
let text = yield ContentTask.spawn(viewSourceTab.linkedBrowser, { }, function* () {
return content.document.body.textContent;
yield ContentTask.spawn(viewSourceTab.linkedBrowser, null, function* () {
Assert.equal(content.document.body.textContent, "<p>This is a paragraph.</p>",
"Correct source for text/html");
});
is(text, "<p>This is a paragraph.</p>", "Correct source for text/html");
gBrowser.removeTab(viewSourceTab);
viewSourceTab = yield* openDocumentSelect("data:application/xhtml+xml," + source, "p");
text = yield ContentTask.spawn(viewSourceTab.linkedBrowser, { }, function* () {
return content.document.body.textContent;
yield ContentTask.spawn(viewSourceTab.linkedBrowser, null, function* () {
Assert.equal(content.document.body.textContent,
'<p xmlns="http://www.w3.org/1999/xhtml">This is a paragraph.</p>',
"Correct source for application/xhtml+xml");
});
is(text, '<p xmlns="http://www.w3.org/1999/xhtml">This is a paragraph.</p>',
"Correct source for application/xhtml+xml");
gBrowser.removeTab(viewSourceTab);
});

View File

@ -64,14 +64,12 @@ function* onViewSourceWindowOpen(aWindow, aIsTab) {
gCopyEmailMenuItem = aWindow.document.getElementById(aIsTab ? "context-copyemail" : "context-copyEmail");
let browser = aIsTab ? gBrowser.selectedBrowser : gViewSourceWindow.gBrowser;
let items = yield ContentTask.spawn(browser, { }, function* (arg) {
yield ContentTask.spawn(browser, null, function* (arg) {
let tags = content.document.querySelectorAll("a[href]");
return [tags[0].href, tags[1].href];
Assert.equal(tags[0].href, "view-source:http://example.com/", "Link has correct href");
Assert.equal(tags[1].href, "mailto:abc@def.ghi", "Link has correct href");
});
is(items[0], "view-source:http://example.com/", "Link has correct href");
is(items[1], "mailto:abc@def.ghi", "Link has correct href");
expectedData.push(["a[href]", true, false, "http://example.com/"]);
expectedData.push(["a[href^=mailto]", false, true, "abc@def.ghi"]);
expectedData.push(["span", false, false, null]);

View File

@ -25,13 +25,11 @@ var checkViewSource = Task.async(function* (aWindow) {
for (let i = 1; i <= 3; i++) {
aWindow.viewSourceChrome.goToLine(i);
let result = yield ContentTask.spawn(aWindow.gBrowser, i, function*(i) {
yield ContentTask.spawn(aWindow.gBrowser, i, function*(i) {
let selection = content.getSelection();
return (selection.toString() == "line " + i);
Assert.equal(selection.toString(), "line " + i, "Correct text selected");
});
ok(result, "Correct text selected");
yield ContentTaskUtils.waitForCondition(() => {
return (statusPanel.getAttribute("label") == "Line " + i + ", Col 1");
}, "Correct status bar text");

View File

@ -155,11 +155,11 @@ add_task(function* ()
let scrollVert = test.expected & expectScrollVert;
let scrollHori = test.expected & expectScrollHori;
let checkScroll = yield ContentTask.spawn(gBrowser.selectedBrowser,
{ scrollVert : scrollVert,
scrollHori: scrollHori,
elemid : test.elem,
checkWindow: test.testwindow },
yield ContentTask.spawn(gBrowser.selectedBrowser,
{ scrollVert : scrollVert,
scrollHori: scrollHori,
elemid : test.elem,
checkWindow: test.testwindow },
function* (args) {
let msg = "";
if (args.checkWindow) {
@ -188,12 +188,10 @@ add_task(function* ()
msg += args.elemid + ' should' + (args.scrollHori ? '' : ' not') + ' have scrolled horizontally';
}
return msg;
Assert.ok(msg.indexOf("Failed") == -1, msg);
}
);
ok(checkScroll.indexOf("Failed") == -1, checkScroll)
// Before continuing the test, we need to ensure that the IPC
// message that stops autoscrolling has had time to arrive.
yield new Promise(resolve => executeSoon(resolve));

View File

@ -2,7 +2,7 @@ add_task(function* () {
let tab = yield BrowserTestUtils.openNewForegroundTab(gBrowser, "about:rights");
yield ContentTask.spawn(tab.linkedBrowser, null, function* () {
ok(content.document.getElementById("your-rights"), "about:rights content loaded");
Assert.ok(content.document.getElementById("your-rights"), "about:rights content loaded");
});
yield BrowserTestUtils.removeTab(tab);

View File

@ -14,9 +14,11 @@ add_task(function* test() {
return ContentTask.spawn(browser, crashes, function (crashes) {
let doc = content.document;
let crashlinks = doc.getElementById("tbody").getElementsByTagName("a");
is(crashlinks.length, crashes.length, "about:crashes lists correct number of crash reports");
for(let i = 0; i < crashes.length; i++) {
is(crashlinks[i].firstChild.textContent, crashes[i].id, i + ": crash ID is correct");
Assert.equal(crashlinks.length, crashes.length,
"about:crashes lists correct number of crash reports");
for (let i = 0; i < crashes.length; i++) {
Assert.equal(crashlinks[i].firstChild.textContent, crashes[i].id,
i + ": crash ID is correct");
}
});
});

View File

@ -17,15 +17,15 @@ function cleanup_and_finish() {
function check_crash_list(crashes) {
let doc = content.document;
let crashlinks = doc.getElementById("tbody").getElementsByTagName("a");
is(crashlinks.length, crashes.length,
Assert.equal(crashlinks.length, crashes.length,
"about:crashes lists correct number of crash reports");
// no point in checking this if the lists aren't the same length
if (crashlinks.length == crashes.length) {
for(let i=0; i<crashes.length; i++) {
is(crashlinks[i].id, crashes[i].id, i + ": crash ID is correct");
Assert.equal(crashlinks[i].id, crashes[i].id, i + ": crash ID is correct");
if (crashes[i].pending) {
// we set the breakpad.reportURL pref in test()
is(crashlinks[i].getAttribute("href"),
Assert.equal(crashlinks[i].getAttribute("href"),
"http://example.com/browser/toolkit/crashreporter/about/throttling",
"pending URL links to the correct static page");
}
@ -57,10 +57,10 @@ function check_submit_pending(tab, crashes) {
// check the JSON content vs. what we submitted
let result = JSON.parse(content.document.documentElement.textContent);
is(result.upload_file_minidump, "MDMP", "minidump file sent properly");
is(result.memory_report, "Let's pretend this is a memory report",
Assert.equal(result.upload_file_minidump, "MDMP", "minidump file sent properly");
Assert.equal(result.memory_report, "Let's pretend this is a memory report",
"memory report sent properly");
is(+result.Throttleable, 0, "correctly sent as non-throttleable");
Assert.equal(+result.Throttleable, 0, "correctly sent as non-throttleable");
// we checked these, they're set by the submission process,
// so they won't be in the "extra" data.
delete result.upload_file_minidump;
@ -102,11 +102,11 @@ function check_submit_pending(tab, crashes) {
BrowserTestUtils.browserLoaded(browser, false, (url) => url !== "about:crashes").then(csp_onload);
function csp_pageshow() {
ContentTask.spawn(browser, { CrashID, CrashURL }, function({ CrashID, CrashURL }) {
is(content.location.href, "about:crashes", "navigated back successfully");
Assert.equal(content.location.href, "about:crashes", "navigated back successfully");
let link = content.document.getElementById(CrashID);
isnot(link, null, "crash report link changed correctly");
Assert.notEqual(link, null, "crash report link changed correctly");
if (link)
is(link.href, CrashURL, "crash report link points to correct href");
Assert.equal(link.href, CrashURL, "crash report link points to correct href");
}).then(cleanup_and_finish);
}

View File

@ -9,8 +9,8 @@ function check_clear_visible(browser, aVisible) {
style.visibility == "visible")
visible = true;
}
is(visible, aVisible,
"clear reports button is " + (aVisible ? "visible" : "hidden"));
Assert.equal(visible, aVisible,
"clear reports button is " + (aVisible ? "visible" : "hidden"));
});
}

View File

@ -8,13 +8,13 @@ function clickClearReports(browser) {
let button = doc.getElementById("clear-reports");
if (!button) {
ok(false, "Button not found");
Assert.ok(false, "Button not found");
return Promise.resolve();
}
let style = doc.defaultView.getComputedStyle(button, "");
isnot(style.display, "none", "Clear reports button visible");
Assert.notEqual(style.display, "none", "Clear reports button visible");
let deferred = {};
deferred.promise = new Promise(resolve => deferred.resolve = resolve);
@ -23,7 +23,7 @@ function clickClearReports(browser) {
if (mutation.type == "attributes" &&
mutation.attributeName == "style") {
observer.disconnect();
is(style.display, "none", "Clear reports button hidden");
Assert.equal(style.display, "none", "Clear reports button hidden");
deferred.resolve();
}
}

View File

@ -41,7 +41,7 @@ add_task(function* () {
is(findResult.result, Ci.nsITypeAheadFind.FIND_FOUND, "should find link");
yield ContentTask.spawn(tab.linkedBrowser, {}, function* (arg) {
ok(!!content.document.getElementsByTagName("a")[0].style.outline, "outline set");
Assert.ok(!!content.document.getElementsByTagName("a")[0].style.outline, "outline set");
});
// Just a simple search for "test link".
@ -51,7 +51,7 @@ add_task(function* () {
is(findResult.result, Ci.nsITypeAheadFind.FIND_FOUND, "should find link again");
yield ContentTask.spawn(tab.linkedBrowser, {}, function* (arg) {
ok(!content.document.getElementsByTagName("a")[0].style.outline, "outline not set");
Assert.ok(!content.document.getElementsByTagName("a")[0].style.outline, "outline not set");
});
finder.removeResultListener(listener);