Bug 1800606 - Stop using nsSyncStreamListener in tests. r=darktrojan
Differential Revision: https://phabricator.services.mozilla.com/D162107 --HG-- extra : amend_source : 45bfb0bc983efa2162e0c28ed91592481ec83b10
This commit is contained in:
Родитель
438031f158
Коммит
6dc4dec7f7
|
@ -132,7 +132,7 @@ add_task(async function test_paste_file_urls() {
|
|||
|
||||
be_in_folder(gOutboxFolder);
|
||||
let outMsg = select_click_row(0);
|
||||
let outMsgContent = get_msg_source(outMsg);
|
||||
let outMsgContent = await get_msg_source(outMsg);
|
||||
|
||||
Assert.ok(
|
||||
outMsgContent.includes("file://foo/non-existent"),
|
||||
|
|
|
@ -49,7 +49,7 @@ add_task(async function test_customHeaders() {
|
|||
|
||||
be_in_folder(draftsFolder);
|
||||
let draftMsg = select_click_row(0);
|
||||
let draftMsgLines = get_msg_source(draftMsg).split("\n");
|
||||
let draftMsgLines = (await get_msg_source(draftMsg)).split("\n");
|
||||
|
||||
// Check header values are set and encoded correctly.
|
||||
Assert.ok(
|
||||
|
|
|
@ -239,7 +239,7 @@ add_task(async function test_content_language_header() {
|
|||
|
||||
be_in_folder(draftsFolder);
|
||||
let draftMsg = select_click_row(0);
|
||||
let draftMsgContent = get_msg_source(draftMsg);
|
||||
let draftMsgContent = await get_msg_source(draftMsg);
|
||||
|
||||
// Check for a single line that contains our header.
|
||||
if (
|
||||
|
@ -280,7 +280,7 @@ add_task(async function test_content_language_header_suppression() {
|
|||
|
||||
be_in_folder(draftsFolder);
|
||||
let draftMsg = select_click_row(0);
|
||||
let draftMsgContent = get_msg_source(draftMsg);
|
||||
let draftMsgContent = await get_msg_source(draftMsg);
|
||||
|
||||
// Check no line contains our Content-Language.
|
||||
Assert.ok(
|
||||
|
|
|
@ -52,7 +52,7 @@ async function forwardDirect(aFilePath, aExpectedText) {
|
|||
be_in_folder(gDrafts);
|
||||
let draftMsg = select_click_row(0);
|
||||
|
||||
let draftMsgContent = get_msg_source(draftMsg);
|
||||
let draftMsgContent = await get_msg_source(draftMsg);
|
||||
|
||||
Assert.ok(
|
||||
draftMsgContent.includes(aExpectedText),
|
||||
|
|
|
@ -99,7 +99,7 @@ add_task(async function test_send_inline_image() {
|
|||
let msgLoaded = BrowserTestUtils.waitForEvent(window, "MsgLoaded");
|
||||
let outMsg = select_click_row(0);
|
||||
await msgLoaded;
|
||||
let outMsgContent = get_msg_source(outMsg);
|
||||
let outMsgContent = await get_msg_source(outMsg);
|
||||
|
||||
ok(
|
||||
outMsgContent.includes('id="inline-img" src="cid:'),
|
||||
|
|
|
@ -52,7 +52,7 @@ add_task(async function test_invalid_data_uri() {
|
|||
let msgLoaded = BrowserTestUtils.waitForEvent(window, "MsgLoaded");
|
||||
let outMsg = select_click_row(0);
|
||||
await msgLoaded;
|
||||
let outMsgContent = get_msg_source(outMsg);
|
||||
let outMsgContent = await get_msg_source(outMsg);
|
||||
|
||||
ok(
|
||||
outMsgContent.includes("invalid data uri"),
|
||||
|
@ -91,7 +91,7 @@ add_task(async function test_freeTextLink() {
|
|||
let msgLoaded = BrowserTestUtils.waitForEvent(window, "MsgLoaded");
|
||||
let outMsg = select_click_row(0);
|
||||
await msgLoaded;
|
||||
let outMsgContent = get_msg_source(outMsg);
|
||||
let outMsgContent = await get_msg_source(outMsg);
|
||||
|
||||
Assert.equal(
|
||||
getMessageBody(outMsgContent),
|
||||
|
|
|
@ -63,7 +63,7 @@ async function subtest_reply_format_flowed(aFlowed) {
|
|||
let msgLoaded = BrowserTestUtils.waitForEvent(window, "MsgLoaded");
|
||||
let message = select_click_row(0);
|
||||
await msgLoaded;
|
||||
let messageContent = get_msg_source(message);
|
||||
let messageContent = await get_msg_source(message);
|
||||
|
||||
// Check for a single line that contains text and make sure there is a
|
||||
// space at the end for a flowed reply.
|
||||
|
|
|
@ -792,26 +792,37 @@ function assert_previous_text(aStart, aText) {
|
|||
*
|
||||
* @return String with the message source.
|
||||
*/
|
||||
function get_msg_source(aMsgHdr, aCharset = "") {
|
||||
async function get_msg_source(aMsgHdr, aCharset = "") {
|
||||
let msgUri = aMsgHdr.folder.getUriForMsg(aMsgHdr);
|
||||
|
||||
let messenger = Cc["@mozilla.org/messenger;1"].createInstance(
|
||||
Ci.nsIMessenger
|
||||
);
|
||||
let streamListener = Cc[
|
||||
"@mozilla.org/network/sync-stream-listener;1"
|
||||
].createInstance(Ci.nsISyncStreamListener);
|
||||
messenger
|
||||
.messageServiceFromURI(msgUri)
|
||||
.streamMessage(msgUri, streamListener, null, null, false, "", false);
|
||||
|
||||
let sis = Cc["@mozilla.org/scriptableinputstream;1"].createInstance(
|
||||
Ci.nsIScriptableInputStream
|
||||
);
|
||||
sis.init(streamListener.inputStream);
|
||||
const MAX_MESSAGE_LENGTH = 65536;
|
||||
let content = sis.read(MAX_MESSAGE_LENGTH);
|
||||
sis.close();
|
||||
let content = await new Promise((resolve, reject) => {
|
||||
let streamListener = {
|
||||
QueryInterface: ChromeUtils.generateQI(["nsIStreamListener"]),
|
||||
sis: Cc["@mozilla.org/scriptableinputstream;1"].createInstance(
|
||||
Ci.nsIScriptableInputStream
|
||||
),
|
||||
content: "",
|
||||
onDataAvailable(request, inputStream, offset, count) {
|
||||
this.sis.init(inputStream);
|
||||
this.content += this.sis.read(count);
|
||||
},
|
||||
onStartRequest(request) {},
|
||||
onStopRequest(request, statusCode) {
|
||||
this.sis.close();
|
||||
if (Components.isSuccessCode(statusCode)) {
|
||||
resolve(this.content);
|
||||
} else {
|
||||
reject(new Error(statusCode));
|
||||
}
|
||||
},
|
||||
};
|
||||
messenger
|
||||
.messageServiceFromURI(msgUri)
|
||||
.streamMessage(msgUri, streamListener, null, null, false, "", false);
|
||||
});
|
||||
|
||||
if (!aCharset) {
|
||||
return content;
|
||||
|
|
|
@ -79,7 +79,7 @@ add_task(async function test_multipart_alternative() {
|
|||
// Now check the message content in the drafts folder.
|
||||
be_in_folder(gDrafts);
|
||||
let message = select_click_row(0);
|
||||
let messageContent = get_msg_source(message);
|
||||
let messageContent = await get_msg_source(message);
|
||||
|
||||
// Check for a single line that contains text and make sure there is a
|
||||
// space at the end for a flowed reply.
|
||||
|
|
|
@ -111,35 +111,46 @@ add_task(async function testDetach() {
|
|||
// Get the message header
|
||||
let msgHdr = mailTestUtils.firstMsgHdr(localAccountUtils.inboxFolder);
|
||||
|
||||
let messageContent = getContentFromMessage(msgHdr);
|
||||
let messageContent = await getContentFromMessage(msgHdr);
|
||||
Assert.ok(messageContent.includes("AttachmentDetached"));
|
||||
});
|
||||
|
||||
/*
|
||||
/**
|
||||
* Get the full message content.
|
||||
*
|
||||
* aMsgHdr: nsIMsgDBHdr object whose text body will be read
|
||||
* returns: string with full message contents
|
||||
* @param aMsgHdr - nsIMsgDBHdr object whose text body will be read.
|
||||
* @returns {Promise<string>} full message contents.
|
||||
*/
|
||||
function getContentFromMessage(aMsgHdr) {
|
||||
const MAX_MESSAGE_LENGTH = 65536;
|
||||
let msgFolder = aMsgHdr.folder;
|
||||
let msgUri = msgFolder.getUriForMsg(aMsgHdr);
|
||||
|
||||
let messenger = Cc["@mozilla.org/messenger;1"].createInstance(
|
||||
Ci.nsIMessenger
|
||||
);
|
||||
let streamListener = Cc[
|
||||
"@mozilla.org/network/sync-stream-listener;1"
|
||||
].createInstance(Ci.nsISyncStreamListener);
|
||||
messenger
|
||||
.messageServiceFromURI(msgUri)
|
||||
.streamMessage(msgUri, streamListener, null, null, false, "", false);
|
||||
let sis = Cc["@mozilla.org/scriptableinputstream;1"].createInstance(
|
||||
Ci.nsIScriptableInputStream
|
||||
);
|
||||
sis.init(streamListener.inputStream);
|
||||
let content = sis.read(MAX_MESSAGE_LENGTH);
|
||||
sis.close();
|
||||
return content;
|
||||
return new Promise((resolve, reject) => {
|
||||
let streamListener = {
|
||||
QueryInterface: ChromeUtils.generateQI(["nsIStreamListener"]),
|
||||
sis: Cc["@mozilla.org/scriptableinputstream;1"].createInstance(
|
||||
Ci.nsIScriptableInputStream
|
||||
),
|
||||
content: "",
|
||||
onDataAvailable(request, inputStream, offset, count) {
|
||||
this.sis.init(inputStream);
|
||||
this.content += this.sis.read(count);
|
||||
},
|
||||
onStartRequest(request) {},
|
||||
onStopRequest(request, statusCode) {
|
||||
this.sis.close();
|
||||
if (Components.isSuccessCode(statusCode)) {
|
||||
resolve(this.content);
|
||||
} else {
|
||||
reject(new Error(statusCode));
|
||||
}
|
||||
},
|
||||
};
|
||||
messenger
|
||||
.messageServiceFromURI(msgUri)
|
||||
.streamMessage(msgUri, streamListener, null, null, false, "", false);
|
||||
});
|
||||
}
|
||||
|
|
|
@ -96,7 +96,7 @@ add_task(async function startDetach() {
|
|||
});
|
||||
|
||||
// test that the detachment was successful
|
||||
add_task(function testDetach() {
|
||||
add_task(async function testDetach() {
|
||||
// The message contained a file "head_update.txt" which should
|
||||
// now exist in the profile directory.
|
||||
let checkFile = do_get_profile().clone();
|
||||
|
@ -110,37 +110,48 @@ add_task(function testDetach() {
|
|||
// Get the message header
|
||||
let msgHdr = mailTestUtils.firstMsgHdr(localAccountUtils.inboxFolder);
|
||||
|
||||
let messageContent = getContentFromMessage(msgHdr);
|
||||
let messageContent = await getContentFromMessage(msgHdr);
|
||||
Assert.ok(messageContent.includes("AttachmentDetached"));
|
||||
// Make sure the body survived the detach.
|
||||
Assert.ok(messageContent.includes("body hello"));
|
||||
});
|
||||
|
||||
/*
|
||||
/**
|
||||
* Get the full message content.
|
||||
*
|
||||
* aMsgHdr: nsIMsgDBHdr object whose text body will be read
|
||||
* returns: string with full message contents
|
||||
* @param aMsgHdr - nsIMsgDBHdr object whose text body will be read.
|
||||
* @returns {Promise<string>} full message contents.
|
||||
*/
|
||||
function getContentFromMessage(aMsgHdr) {
|
||||
const MAX_MESSAGE_LENGTH = 65536;
|
||||
let msgFolder = aMsgHdr.folder;
|
||||
let msgUri = msgFolder.getUriForMsg(aMsgHdr);
|
||||
|
||||
let messenger = Cc["@mozilla.org/messenger;1"].createInstance(
|
||||
Ci.nsIMessenger
|
||||
);
|
||||
let streamListener = Cc[
|
||||
"@mozilla.org/network/sync-stream-listener;1"
|
||||
].createInstance(Ci.nsISyncStreamListener);
|
||||
messenger
|
||||
.messageServiceFromURI(msgUri)
|
||||
.streamMessage(msgUri, streamListener, null, null, false, "", false);
|
||||
let sis = Cc["@mozilla.org/scriptableinputstream;1"].createInstance(
|
||||
Ci.nsIScriptableInputStream
|
||||
);
|
||||
sis.init(streamListener.inputStream);
|
||||
let content = sis.read(MAX_MESSAGE_LENGTH);
|
||||
sis.close();
|
||||
return content;
|
||||
return new Promise((resolve, reject) => {
|
||||
let streamListener = {
|
||||
QueryInterface: ChromeUtils.generateQI(["nsIStreamListener"]),
|
||||
sis: Cc["@mozilla.org/scriptableinputstream;1"].createInstance(
|
||||
Ci.nsIScriptableInputStream
|
||||
),
|
||||
content: "",
|
||||
onDataAvailable(request, inputStream, offset, count) {
|
||||
this.sis.init(inputStream);
|
||||
this.content += this.sis.read(count);
|
||||
},
|
||||
onStartRequest(request) {},
|
||||
onStopRequest(request, statusCode) {
|
||||
this.sis.close();
|
||||
if (Components.isSuccessCode(statusCode)) {
|
||||
resolve(this.content);
|
||||
} else {
|
||||
reject(new Error(statusCode));
|
||||
}
|
||||
},
|
||||
};
|
||||
messenger
|
||||
.messageServiceFromURI(msgUri)
|
||||
.streamMessage(msgUri, streamListener, null, null, false, "", false);
|
||||
});
|
||||
}
|
||||
|
|
|
@ -132,7 +132,7 @@ add_task(async function startDetach() {
|
|||
});
|
||||
|
||||
// test that the detachment was successful
|
||||
add_task(function testDetach() {
|
||||
add_task(async function testDetach() {
|
||||
// Check that the file attached to the message now exists in the profile
|
||||
// directory.
|
||||
let checkFile = do_get_profile().clone();
|
||||
|
@ -145,7 +145,7 @@ add_task(function testDetach() {
|
|||
// Get the message header - detached copy has UID 2.
|
||||
let msgHdr = IMAPPump.inbox.GetMessageHeader(2);
|
||||
Assert.ok(msgHdr !== null);
|
||||
let messageContent = getContentFromMessage(msgHdr);
|
||||
let messageContent = await getContentFromMessage(msgHdr);
|
||||
Assert.ok(messageContent.includes("AttachmentDetached"));
|
||||
});
|
||||
|
||||
|
@ -154,32 +154,43 @@ add_task(function endTest() {
|
|||
teardownIMAPPump();
|
||||
});
|
||||
|
||||
/*
|
||||
/**
|
||||
* Get the full message content.
|
||||
*
|
||||
* aMsgHdr: nsIMsgDBHdr object whose text body will be read
|
||||
* returns: string with full message contents
|
||||
* @param aMsgHdr - nsIMsgDBHdr object whose text body will be read.
|
||||
* @returns {Promise<string>} full message contents.
|
||||
*/
|
||||
function getContentFromMessage(aMsgHdr) {
|
||||
const MAX_MESSAGE_LENGTH = 65536;
|
||||
let msgFolder = aMsgHdr.folder;
|
||||
let msgUri = msgFolder.getUriForMsg(aMsgHdr);
|
||||
|
||||
let messenger = Cc["@mozilla.org/messenger;1"].createInstance(
|
||||
Ci.nsIMessenger
|
||||
);
|
||||
let streamListener = Cc[
|
||||
"@mozilla.org/network/sync-stream-listener;1"
|
||||
].createInstance(Ci.nsISyncStreamListener);
|
||||
// Pass true for aLocalOnly since message should be in offline store.
|
||||
messenger
|
||||
.messageServiceFromURI(msgUri)
|
||||
.streamMessage(msgUri, streamListener, null, null, false, "", true);
|
||||
let sis = Cc["@mozilla.org/scriptableinputstream;1"].createInstance(
|
||||
Ci.nsIScriptableInputStream
|
||||
);
|
||||
sis.init(streamListener.inputStream);
|
||||
let content = sis.read(MAX_MESSAGE_LENGTH);
|
||||
sis.close();
|
||||
return content;
|
||||
return new Promise((resolve, reject) => {
|
||||
let streamListener = {
|
||||
QueryInterface: ChromeUtils.generateQI(["nsIStreamListener"]),
|
||||
sis: Cc["@mozilla.org/scriptableinputstream;1"].createInstance(
|
||||
Ci.nsIScriptableInputStream
|
||||
),
|
||||
content: "",
|
||||
onDataAvailable(request, inputStream, offset, count) {
|
||||
this.sis.init(inputStream);
|
||||
this.content += this.sis.read(count);
|
||||
},
|
||||
onStartRequest(request) {},
|
||||
onStopRequest(request, statusCode) {
|
||||
this.sis.close();
|
||||
if (Components.isSuccessCode(statusCode)) {
|
||||
resolve(this.content);
|
||||
} else {
|
||||
reject(new Error(statusCode));
|
||||
}
|
||||
},
|
||||
};
|
||||
// Pass true for aLocalOnly since message should be in offline store.
|
||||
messenger
|
||||
.messageServiceFromURI(msgUri)
|
||||
.streamMessage(msgUri, streamListener, null, null, false, "", true);
|
||||
});
|
||||
}
|
||||
|
|
|
@ -49,7 +49,7 @@ var gTestArray = [
|
|||
let promise2 = gPOP3Pump.run();
|
||||
await Promise.all([promise1, promise2]);
|
||||
},
|
||||
function verifyFolders1() {
|
||||
async function verifyFolders1() {
|
||||
Assert.equal(folderCount(gMoveFolder), 2);
|
||||
// the local inbox folder should now be empty, since the second
|
||||
// operation was a move
|
||||
|
@ -59,11 +59,11 @@ var gTestArray = [
|
|||
let firstMsgHdr = msgs[0];
|
||||
let secondMsgHdr = msgs[1];
|
||||
// Check that the messages have content
|
||||
let messageContent = getContentFromMessage(firstMsgHdr);
|
||||
let messageContent = await getContentFromMessage(firstMsgHdr);
|
||||
Assert.ok(
|
||||
messageContent.includes("Some User <bugmail@example.org> changed")
|
||||
);
|
||||
messageContent = getContentFromMessage(secondMsgHdr);
|
||||
messageContent = await getContentFromMessage(secondMsgHdr);
|
||||
Assert.ok(
|
||||
messageContent.includes(
|
||||
"https://bugzilla.mozilla.org/show_bug.cgi?id=436880"
|
||||
|
@ -90,18 +90,18 @@ var gTestArray = [
|
|||
);
|
||||
await Promise.all([promiseCopyListener.promise, promiseMoveMsg]);
|
||||
},
|
||||
function verifyFolders2() {
|
||||
async function verifyFolders2() {
|
||||
Assert.equal(folderCount(gMoveFolder2), 2);
|
||||
|
||||
let msgs = [...gMoveFolder2.msgDatabase.enumerateMessages()];
|
||||
let firstMsgHdr = msgs[0];
|
||||
let secondMsgHdr = msgs[1];
|
||||
// Check that the messages have content
|
||||
let messageContent = getContentFromMessage(firstMsgHdr);
|
||||
let messageContent = await getContentFromMessage(firstMsgHdr);
|
||||
Assert.ok(
|
||||
messageContent.includes("Some User <bugmail@example.org> changed")
|
||||
);
|
||||
messageContent = getContentFromMessage(secondMsgHdr);
|
||||
messageContent = await getContentFromMessage(secondMsgHdr);
|
||||
Assert.ok(
|
||||
messageContent.includes(
|
||||
"https://bugzilla.mozilla.org/show_bug.cgi?id=436880"
|
||||
|
@ -138,31 +138,42 @@ function run_test() {
|
|||
run_next_test();
|
||||
}
|
||||
|
||||
/*
|
||||
/**
|
||||
* Get the full message content.
|
||||
*
|
||||
* aMsgHdr: nsIMsgDBHdr object whose text body will be read
|
||||
* returns: string with full message contents
|
||||
* @param aMsgHdr - nsIMsgDBHdr object whose text body will be read.
|
||||
* @returns {Promise<string>} full message contents.
|
||||
*/
|
||||
function getContentFromMessage(aMsgHdr) {
|
||||
const MAX_MESSAGE_LENGTH = 65536;
|
||||
let msgFolder = aMsgHdr.folder;
|
||||
let msgUri = msgFolder.getUriForMsg(aMsgHdr);
|
||||
|
||||
let messenger = Cc["@mozilla.org/messenger;1"].createInstance(
|
||||
Ci.nsIMessenger
|
||||
);
|
||||
let streamListener = Cc[
|
||||
"@mozilla.org/network/sync-stream-listener;1"
|
||||
].createInstance(Ci.nsISyncStreamListener);
|
||||
messenger
|
||||
.messageServiceFromURI(msgUri)
|
||||
.streamMessage(msgUri, streamListener, null, null, false, "", false);
|
||||
let sis = Cc["@mozilla.org/scriptableinputstream;1"].createInstance(
|
||||
Ci.nsIScriptableInputStream
|
||||
);
|
||||
sis.init(streamListener.inputStream);
|
||||
let content = sis.read(MAX_MESSAGE_LENGTH);
|
||||
sis.close();
|
||||
return content;
|
||||
return new Promise((resolve, reject) => {
|
||||
let streamListener = {
|
||||
QueryInterface: ChromeUtils.generateQI(["nsIStreamListener"]),
|
||||
sis: Cc["@mozilla.org/scriptableinputstream;1"].createInstance(
|
||||
Ci.nsIScriptableInputStream
|
||||
),
|
||||
content: "",
|
||||
onDataAvailable(request, inputStream, offset, count) {
|
||||
this.sis.init(inputStream);
|
||||
this.content += this.sis.read(count);
|
||||
},
|
||||
onStartRequest(request) {},
|
||||
onStopRequest(request, statusCode) {
|
||||
this.sis.close();
|
||||
if (Components.isSuccessCode(statusCode)) {
|
||||
resolve(this.content);
|
||||
} else {
|
||||
reject(new Error(statusCode));
|
||||
}
|
||||
},
|
||||
};
|
||||
messenger
|
||||
.messageServiceFromURI(msgUri)
|
||||
.streamMessage(msgUri, streamListener, null, null, false, "", false);
|
||||
});
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче