Bug 888600 - Move ContentFrameMessageManager to WebIDL. Part 2: Various test fixes to prepare for using WebIDL bindings for MessageManager classes. r=bz.

--HG--
extra : rebase_source : cbf2c71a956a0c57e7d57a1c1c132bb57bc48c37
This commit is contained in:
Peter Van der Beken 2017-07-04 18:03:18 +02:00
parent f406b29197
commit 9cab86f20d
12 changed files with 53 additions and 45 deletions

View File

@ -72,10 +72,10 @@
let receivedMessageIndex = 0;
let mm = SpecialPowers.getBrowserFrameMessageManager(iframe);
mm.addMessageListener("test:ipcClonedMessage", function(message) {
mm.addMessageListener("test:ipcClonedMessage", SpecialPowers.wrapCallback(function(message) {
let data = message.json;
if (data instanceof Blob) {
if (SpecialPowers.call_Instanceof(data, Blob)) {
is(receivedMessageIndex, messages.length - 1, "Blob is last");
is (data.size,
messages[receivedMessageIndex].size,
@ -104,7 +104,7 @@
}
};
reader1.readAsText(data);
SpecialPowers.wrap(reader1).readAsText(data);
reader2.readAsText(messages[receivedMessageIndex]);
return;
}
@ -112,7 +112,7 @@
is(message.json,
messages[receivedMessageIndex++],
"Got correct round-tripped response");
});
}));
mm.loadFrameScript("data:,(" + childFrameScript.toString() + ")();",
false);

View File

@ -80,11 +80,14 @@ function waitForMessage(aMessage, browser)
{
return new Promise((resolve, reject) => {
/* eslint-disable no-undef */
// When contentScript runs, "this" is a ContentFrameMessageManager (so that's where
// addEventListener will add the listener), but the non-bubbling "message" event is
// sent to the Window involved, so we need a capturing listener.
function contentScript() {
addEventListener("message", function(event) {
sendAsyncMessage("testLocal:message",
{message: event.data});
}, {once: true}, true);
}, {once: true, capture: true}, true);
}
/* eslint-enable no-undef */

View File

@ -214,16 +214,16 @@ function parentFrameScript(mm) {
function* testSteps() {
let result = yield undefined;
is(Array.isArray(result), true, "Child delivered an array of results");
is(SpecialPowers.Cu.getClassName(result, true), "Array", "Child delivered an array of results");
is(result.length, 2, "Child delivered two results");
let blob = result[0];
is(blob instanceof Blob, true, "Child delivered a blob");
is(SpecialPowers.call_Instanceof(blob, Blob), true, "Child delivered a blob");
is(blob.size, blobText.length, "Blob has correct size");
is(blob.type, blobType, "Blob has correct type");
let slice = result[1];
is(slice instanceof Blob, true, "Child delivered a slice");
is(SpecialPowers.call_Instanceof(slice, Blob), true, "Child delivered a slice");
is(slice.size, blobData[0].length, "Slice has correct size");
is(slice.type, blobType, "Slice has correct type");
@ -231,7 +231,7 @@ function parentFrameScript(mm) {
let reader = new FileReader();
reader.onload = grabAndContinue;
reader.readAsText(blob);
SpecialPowers.wrap(reader).readAsText(blob);
yield undefined;
is(reader.result, blobText, "Blob has correct data");
@ -240,14 +240,14 @@ function parentFrameScript(mm) {
reader = new FileReader();
reader.onload = grabAndContinue;
reader.readAsText(slice);
SpecialPowers.wrap(reader).readAsText(slice);
yield undefined;
is(reader.result, blobData[0], "Slice has correct data");
slice = blob.slice(0, blobData[0].length, blobType);
is(slice instanceof Blob, true, "Made a new slice from blob");
is(SpecialPowers.call_Instanceof(slice, Blob), true, "Child delivered a slice");
is(slice.size, blobData[0].length, "Second slice has correct size");
is(slice.type, blobType, "Second slice has correct type");
@ -255,7 +255,7 @@ function parentFrameScript(mm) {
reader = new FileReader();
reader.onload = grabAndContinue;
reader.readAsText(slice);
SpecialPowers.wrap(reader).readAsText(slice);
yield undefined;
is(reader.result, blobData[0], "Second slice has correct data");
@ -266,7 +266,7 @@ function parentFrameScript(mm) {
let testGenerator = testSteps();
testGenerator.next();
mm.addMessageListener(messageName, function(message) {
mm.addMessageListener(messageName, SpecialPowers.wrapCallback(function(message) {
let data = message.data;
switch (data.op) {
case "info": {
@ -289,7 +289,7 @@ function parentFrameScript(mm) {
SimpleTest.finish();
}
}
});
}));
mm.loadFrameScript("data:,(" + childFrameScript.toString() + ")();",
false);

View File

@ -53,7 +53,7 @@ function parentFrameScript(mm) {
let finishedTestingBlob = false;
let finishedTestingSlice = false;
mm.addMessageListener(messageName, function(message) {
mm.addMessageListener(messageName, SpecialPowers.wrapCallback(function(message) {
if ("blob" in message.data) {
is(receivedBlob, false, "Have not yet received Blob");
is(receivedSlice, false, "Have not yet received Slice");
@ -64,7 +64,7 @@ function parentFrameScript(mm) {
let blob = message.data.blob;
ok(blob instanceof Blob, "Received a Blob");
ok(SpecialPowers.call_Instanceof(blob, Blob), "Received a Blob");
is(blob.size, blobText.length, "Blob has correct size");
is(blob.type, blobType, "Blob has correct type");
@ -73,7 +73,7 @@ function parentFrameScript(mm) {
blob.size,
blobType);
ok(slice instanceof Blob, "Slice returned a Blob");
ok(SpecialPowers.call_Instanceof(slice, Blob), "Slice returned a Blob");
is(slice.size,
blobData[blobData.length - 1].length,
"Slice has correct size");
@ -91,7 +91,7 @@ function parentFrameScript(mm) {
SimpleTest.finish();
}
};
reader.readAsText(slice);
SpecialPowers.wrap(reader).readAsText(slice);
return;
}
@ -105,7 +105,7 @@ function parentFrameScript(mm) {
let slice = message.data.slice;
ok(slice instanceof Blob, "Received a Blob for slice");
ok(SpecialPowers.call_Instanceof(slice, Blob), "Received a Blob for slice");
is(slice.size, sliceText.length, "Slice has correct size");
is(slice.type, blobType, "Slice has correct type");
@ -115,7 +115,7 @@ function parentFrameScript(mm) {
let slice2 = slice.slice(1, 2, blobType);
ok(slice2 instanceof Blob, "Slice returned a Blob");
ok(SpecialPowers.call_Instanceof(slice2, Blob), "Slice returned a Blob");
is(slice2.size, 1, "Slice has correct size");
is(slice2.type, blobType, "Slice has correct type");
@ -129,15 +129,15 @@ function parentFrameScript(mm) {
SimpleTest.finish();
}
};
reader2.readAsText(slice2);
SpecialPowers.wrap(reader2).readAsText(slice2);
};
reader.readAsText(slice);
SpecialPowers.wrap(reader).readAsText(slice);
return;
}
ok(false, "Received a bad message: " + JSON.stringify(message.data));
});
}));
mm.loadFrameScript("data:,(" + childFrameScript.toString() + ")();",
false);

View File

@ -117,13 +117,13 @@ function parentFrameScript(mm) {
function* testSteps() {
let slice = yield undefined;
ok(slice instanceof Blob, "Received a Blob");
ok(SpecialPowers.call_Instanceof(slice, Blob), "Received a Blob");
is(slice.size, sliceText.length, "Slice has correct size");
is(slice.type, blobType, "Slice has correct type");
let reader = new FileReader();
reader.onload = grabAndContinue;
reader.readAsText(slice);
SpecialPowers.wrap(reader).readAsText(slice);
yield undefined;
is(reader.result, sliceText, "Slice has correct data");
@ -133,7 +133,7 @@ function parentFrameScript(mm) {
let testGenerator = testSteps();
testGenerator.next();
mm.addMessageListener(messageName, function(message) {
mm.addMessageListener(messageName, SpecialPowers.wrapCallback(function(message) {
let data = message.data;
switch (data.op) {
case "info": {
@ -156,7 +156,7 @@ function parentFrameScript(mm) {
SimpleTest.finish();
}
}
});
}));
mm.loadFrameScript("data:,(" + childFrameScript.toString() + ")();",
false);

View File

@ -52,7 +52,8 @@
test.next(msg.data.value);
}
mm.addMessageListener("testBug1086684:childDone", testDone);
mm.addMessageListener("testBug1086684:childDone",
SpecialPowers.wrapCallback(testDone));
let blob = new Blob([]);
let file = new File([blob], "helloworld.txt", { type: "text/plain" });

View File

@ -40,7 +40,8 @@
test.next(msg.data);
}
mm.addMessageListener("testCPOWCookies:test1Finished", testDone);
mm.addMessageListener("testCPOWCookies:test1Finished",
SpecialPowers.wrapCallback(testDone));
mm.sendAsyncMessage("testCPOWCookies:test1", {});
lastResult = yield;

View File

@ -130,7 +130,7 @@ function setup() {
var mm = SpecialPowers.getBrowserFrameMessageManager(receiverIframe);
mm.addMessageListener('check-navigator', function checknavigatorHandler(aSuccess) {
mm.removeMessageListener('check-navigator', checknavigatorHandler);
ok(aSuccess.data.data, "buildDataChannel get correct window object");
ok(SpecialPowers.wrap(aSuccess).data.data, "buildDataChannel get correct window object");
});
mm.addMessageListener('data-transport-notification-enabled', function dataTransportNotificationEnabledHandler() {
@ -140,7 +140,7 @@ function setup() {
mm.addMessageListener('data-transport-closed', function dataTransportClosedHandler(aReason) {
mm.removeMessageListener('data-transport-closed', dataTransportClosedHandler);
is(aReason.data.data, SpecialPowers.Cr.NS_OK, "The data transport should be closed normally.");
is(SpecialPowers.wrap(aReason).data.data, SpecialPowers.Cr.NS_OK, "The data transport should be closed normally.");
});
aResolve();

View File

@ -80,11 +80,14 @@ function dismissNotification(popup, win)
function waitForMessage(aMessage, browser)
{
return new Promise((resolve, reject) => {
// When contentScript runs, "this" is a ContentFrameMessageManager (so that's where
// addEventListener will add the listener), but the non-bubbling "message" event is
// sent to the Window involved, so we need a capturing listener.
function contentScript() {
addEventListener("message", function(event) {
sendAsyncMessage("testLocal:persisted",
{persisted: event.data});
}, {once: true}, true);
}, {once: true, capture: true}, true);
}
let script = "data:,(" + contentScript.toString() + ")();";

View File

@ -299,7 +299,7 @@ proxy.AsyncMessageChannel = class {
}
let l = this.listeners_.get(path);
globalMessageManager.removeMessageListener(path, l[1]);
globalMessageManager.removeMessageListener(path, l);
return this.listeners_.delete(path);
}

View File

@ -237,28 +237,28 @@
async function testStructure(mm, isPrivate) {
var curTest;
function testDone(msg) {
var testDone = SpecialPowers.wrapCallback(function testDone(msg) {
info(`in testDone ${msg.name}`);
curTest.resolve();
}
});
mm.addMessageListener("testRemoteContentPrefs:test1Finished", testDone);
mm.addMessageListener("testRemoteContentPrefs:test2Finished", testDone);
mm.addMessageListener("testRemoteContentPrefs:test3Finished", testDone);
mm.addMessageListener("testRemoteContentPrefs:test4Finished", testDone);
mm.addMessageListener("testRemoteContentPrefs:fail", function(msg) {
mm.addMessageListener("testRemoteContentPrefs:fail", SpecialPowers.wrapCallback(function(msg) {
ok(false, msg.data.reason);
SimpleTest.finish();
});
}));
mm.addMessageListener("testRemoteContentPrefs:ok", (msg) => {
mm.addMessageListener("testRemoteContentPrefs:ok", SpecialPowers.wrapCallback((msg) => {
let test = msg.data.test;
ok(...test);
});
mm.addMessageListener("testRemoteContentPrefs:info", (msg) => {
}));
mm.addMessageListener("testRemoteContentPrefs:info", SpecialPowers.wrapCallback((msg) => {
info(msg.data.note);
});
}));
curTest = Defer();
mm.sendAsyncMessage("testRemoteContentPrefs:test1", {});
@ -283,7 +283,7 @@
await curTest.promise;
curTest = Defer();
mm.addMessageListener("testRemoteContentPrefs:getPref", function(msg) {
mm.addMessageListener("testRemoteContentPrefs:getPref", SpecialPowers.wrapCallback(function(msg) {
let results = [];
cps.getByDomainAndName(msg.data.group, msg.data.name, null, {
handleResult(pref) {
@ -299,7 +299,7 @@
curTest.reject("got unexpected error");
}
});
});
}));
mm.sendAsyncMessage("testRemoteContentPrefs:test4", {});
await curTest.promise;

View File

@ -47,9 +47,9 @@
function* testStructure(mm) {
let lastResult;
mm.addMessageListener("test687194:resolveChromeURI:Answer", function(msg) {
mm.addMessageListener("test687194:resolveChromeURI:Answer", SpecialPowers.wrapCallback(function(msg) {
test.next(msg.data);
});
}));
mm.sendAsyncMessage("test687194:resolveChromeURI",
{ URI: "chrome://bug687194/content/e10sbug.js" });