From 9cab86f20d838219fe52d4270c8a1860b9a22bde Mon Sep 17 00:00:00 2001 From: Peter Van der Beken Date: Tue, 4 Jul 2017 18:03:18 +0200 Subject: [PATCH] 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 --- .../tests/test_ipc_messagemanager_blob.html | 8 ++++---- dom/indexedDB/test/head.js | 5 ++++- .../test/test_message_manager_ipc.html | 18 ++++++++--------- .../test_blob_sliced_from_child_process.html | 18 ++++++++--------- .../test_blob_sliced_from_parent_process.html | 8 ++++---- dom/ipc/tests/test_bug1086684.html | 3 ++- dom/ipc/tests/test_cpow_cookies.html | 3 ++- .../test_presentation_dc_receiver_oop.html | 4 ++-- dom/quota/test/head.js | 5 ++++- testing/marionette/proxy.js | 2 +- .../mochitest/test_remoteContentPrefs.html | 20 +++++++++---------- .../test/mochitest/test_bug687194.html | 4 ++-- 12 files changed, 53 insertions(+), 45 deletions(-) diff --git a/dom/file/tests/test_ipc_messagemanager_blob.html b/dom/file/tests/test_ipc_messagemanager_blob.html index cc202c6bf21c..e51ec3bcf305 100644 --- a/dom/file/tests/test_ipc_messagemanager_blob.html +++ b/dom/file/tests/test_ipc_messagemanager_blob.html @@ -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); diff --git a/dom/indexedDB/test/head.js b/dom/indexedDB/test/head.js index 8960728043fe..e0c7f9ddbc16 100644 --- a/dom/indexedDB/test/head.js +++ b/dom/indexedDB/test/head.js @@ -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 */ diff --git a/dom/indexedDB/test/test_message_manager_ipc.html b/dom/indexedDB/test/test_message_manager_ipc.html index 68263d991f43..d07faaac8a9d 100644 --- a/dom/indexedDB/test/test_message_manager_ipc.html +++ b/dom/indexedDB/test/test_message_manager_ipc.html @@ -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); diff --git a/dom/ipc/tests/test_blob_sliced_from_child_process.html b/dom/ipc/tests/test_blob_sliced_from_child_process.html index 94dcc7577a9a..5f0164b15c24 100644 --- a/dom/ipc/tests/test_blob_sliced_from_child_process.html +++ b/dom/ipc/tests/test_blob_sliced_from_child_process.html @@ -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); diff --git a/dom/ipc/tests/test_blob_sliced_from_parent_process.html b/dom/ipc/tests/test_blob_sliced_from_parent_process.html index 34f7a09a6f36..0ac26bf02395 100644 --- a/dom/ipc/tests/test_blob_sliced_from_parent_process.html +++ b/dom/ipc/tests/test_blob_sliced_from_parent_process.html @@ -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); diff --git a/dom/ipc/tests/test_bug1086684.html b/dom/ipc/tests/test_bug1086684.html index 3dd1560892a7..76d1fce42116 100644 --- a/dom/ipc/tests/test_bug1086684.html +++ b/dom/ipc/tests/test_bug1086684.html @@ -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" }); diff --git a/dom/ipc/tests/test_cpow_cookies.html b/dom/ipc/tests/test_cpow_cookies.html index b10938bcded5..daeea7e12dae 100644 --- a/dom/ipc/tests/test_cpow_cookies.html +++ b/dom/ipc/tests/test_cpow_cookies.html @@ -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; diff --git a/dom/presentation/tests/mochitest/test_presentation_dc_receiver_oop.html b/dom/presentation/tests/mochitest/test_presentation_dc_receiver_oop.html index edcc0365d2e3..9d88548073ad 100644 --- a/dom/presentation/tests/mochitest/test_presentation_dc_receiver_oop.html +++ b/dom/presentation/tests/mochitest/test_presentation_dc_receiver_oop.html @@ -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(); diff --git a/dom/quota/test/head.js b/dom/quota/test/head.js index 12d086eaa06c..a7d5f3e8bab6 100644 --- a/dom/quota/test/head.js +++ b/dom/quota/test/head.js @@ -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() + ")();"; diff --git a/testing/marionette/proxy.js b/testing/marionette/proxy.js index e259c0e58306..f7116e37ecf5 100644 --- a/testing/marionette/proxy.js +++ b/testing/marionette/proxy.js @@ -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); } diff --git a/toolkit/components/contentprefs/tests/mochitest/test_remoteContentPrefs.html b/toolkit/components/contentprefs/tests/mochitest/test_remoteContentPrefs.html index 6b41f2a7749a..64acb058e18b 100644 --- a/toolkit/components/contentprefs/tests/mochitest/test_remoteContentPrefs.html +++ b/toolkit/components/contentprefs/tests/mochitest/test_remoteContentPrefs.html @@ -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; diff --git a/toolkit/mozapps/extensions/test/mochitest/test_bug687194.html b/toolkit/mozapps/extensions/test/mochitest/test_bug687194.html index e0f68bbb47f6..9ba8e2acdf29 100644 --- a/toolkit/mozapps/extensions/test/mochitest/test_bug687194.html +++ b/toolkit/mozapps/extensions/test/mochitest/test_bug687194.html @@ -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" });