From 2aa5137dc43fc55cee850b7ad600e63445908ff4 Mon Sep 17 00:00:00 2001 From: Alexandru Michis Date: Thu, 6 Jan 2022 02:55:58 +0200 Subject: [PATCH] Backed out changeset 4ae7738694e1 (bug 1748158) for causing xpcshell failures in test_ext_native_messaging_permissions.js CLOSED TREE --- ...rowser_ext_contentscript_nontab_connect.js | 5 +- .../test_ext_native_messaging_permissions.js | 2 +- .../components/extensions/ExtensionParent.jsm | 3 +- .../test/mochitest/mochitest-common.ini | 1 - .../mochitest/test_ext_runtime_connect.html | 1 - .../test_ext_runtime_connect_iframe.html | 136 ------------------ .../test_ext_contentscript_in_background.js | 24 +++- .../test_ext_contentscript_xorigin_frame.js | 29 +++- 8 files changed, 53 insertions(+), 148 deletions(-) delete mode 100644 toolkit/components/extensions/test/mochitest/test_ext_runtime_connect_iframe.html diff --git a/browser/components/extensions/test/browser/browser_ext_contentscript_nontab_connect.js b/browser/components/extensions/test/browser/browser_ext_contentscript_nontab_connect.js index 011f89c14ec2..edcb1c768574 100644 --- a/browser/components/extensions/test/browser/browser_ext_contentscript_nontab_connect.js +++ b/browser/components/extensions/test/browser/browser_ext_contentscript_nontab_connect.js @@ -11,9 +11,12 @@ function extensionScript() { browser.runtime.onConnect.addListener(port => { browser.test.assertEq(port.sender.tab, undefined, "Sender is not a tab"); - browser.test.assertEq(port.sender.frameId, undefined, "frameId unset"); browser.test.assertEq(port.sender.url, FRAME_URL, "Expected sender URL"); + let { frameId } = port.sender; + browser.test.assertEq(typeof frameId, "number", "frameId is a number"); + browser.test.assertTrue(frameId > 0, "frameId greater than 0"); + port.onMessage.addListener(msg => { browser.test.assertEq("pong", msg, "Reply from content script"); port.disconnect(); diff --git a/mobile/android/components/extensions/test/xpcshell/test_ext_native_messaging_permissions.js b/mobile/android/components/extensions/test/xpcshell/test_ext_native_messaging_permissions.js index 421080d7c6b9..50e1cc93cf4d 100644 --- a/mobile/android/components/extensions/test/xpcshell/test_ext_native_messaging_permissions.js +++ b/mobile/android/components/extensions/test/xpcshell/test_ext_native_messaging_permissions.js @@ -96,7 +96,7 @@ add_task(async function test_nativeMessaging_unprivileged() { add_task(async function test_geckoViewAddons_missing() { const ERROR_NATIVE_MESSAGE_FROM_BACKGROUND = "Native manifests are not supported on android"; - const ERROR_NATIVE_MESSAGE_FROM_CONTENT = /^Native messaging not allowed: \{.*"envType":"content_child","url":"http:\/\/example\.com\/dummy"\}$/; + const ERROR_NATIVE_MESSAGE_FROM_CONTENT = /^Native messaging not allowed: \{.*"envType":"content_child","frameId":0,"url":"http:\/\/example\.com\/dummy"\}$/; async function testBackground() { await browser.test.assertRejects( diff --git a/toolkit/components/extensions/ExtensionParent.jsm b/toolkit/components/extensions/ExtensionParent.jsm index b67ac00fb135..4934b6cea5cb 100644 --- a/toolkit/components/extensions/ExtensionParent.jsm +++ b/toolkit/components/extensions/ExtensionParent.jsm @@ -298,6 +298,7 @@ const ProxyMessenger = { contextId: source.id, id: source.extensionId, envType: source.envType, + frameId: source.frameId, url: source.url, }; @@ -307,8 +308,6 @@ const ProxyMessenger = { browser && apiManager.global.tabTracker.getBrowserData(browser); if (data?.tabId > 0) { sender.tab = extension.tabManager.get(data.tabId, null)?.convert(); - // frameId is documented to only be set if sender.tab is set. - sender.frameId = source.frameId; } } diff --git a/toolkit/components/extensions/test/mochitest/mochitest-common.ini b/toolkit/components/extensions/test/mochitest/mochitest-common.ini index a9c7625c284d..f109cc05d2e1 100644 --- a/toolkit/components/extensions/test/mochitest/mochitest-common.ini +++ b/toolkit/components/extensions/test/mochitest/mochitest-common.ini @@ -143,7 +143,6 @@ skip-if = os == 'win' && (debug || asan) # Bug 1563440 [test_ext_request_urlClassification.html] skip-if = os == 'android' # Bug 1615427 [test_ext_runtime_connect.html] -[test_ext_runtime_connect_iframe.html] [test_ext_runtime_connect_twoway.html] [test_ext_runtime_connect2.html] [test_ext_runtime_disconnect.html] diff --git a/toolkit/components/extensions/test/mochitest/test_ext_runtime_connect.html b/toolkit/components/extensions/test/mochitest/test_ext_runtime_connect.html index 85f98d503411..c4726092ecb4 100644 --- a/toolkit/components/extensions/test/mochitest/test_ext_runtime_connect.html +++ b/toolkit/components/extensions/test/mochitest/test_ext_runtime_connect.html @@ -17,7 +17,6 @@ function background() { browser.test.assertEq(port.name, "ernie", "port name correct"); browser.test.assertTrue(port.sender.url.endsWith("file_sample.html"), "URL correct"); browser.test.assertTrue(port.sender.tab.url.endsWith("file_sample.html"), "tab URL correct"); - browser.test.assertEq(port.sender.frameId, 0, "frameId of top frame"); let expected = "message 1"; port.onMessage.addListener(msg => { diff --git a/toolkit/components/extensions/test/mochitest/test_ext_runtime_connect_iframe.html b/toolkit/components/extensions/test/mochitest/test_ext_runtime_connect_iframe.html deleted file mode 100644 index 9c64635063f8..000000000000 --- a/toolkit/components/extensions/test/mochitest/test_ext_runtime_connect_iframe.html +++ /dev/null @@ -1,136 +0,0 @@ - - - - WebExtension test - - - - - - - - - - - diff --git a/toolkit/components/extensions/test/xpcshell/test_ext_contentscript_in_background.js b/toolkit/components/extensions/test/xpcshell/test_ext_contentscript_in_background.js index e813b46ca0cc..1a8aa6d7060d 100644 --- a/toolkit/components/extensions/test/xpcshell/test_ext_contentscript_in_background.js +++ b/toolkit/components/extensions/test/xpcshell/test_ext_contentscript_in_background.js @@ -9,9 +9,19 @@ server.registerPathHandler("/dummyFrame", (request, response) => { response.write(""); }); -add_task(async function content_script_in_background_frame() { +add_task(async function connect_from_background_frame() { async function background() { const FRAME_URL = "http://example.com:8888/dummyFrame"; + browser.runtime.onConnect.addListener(port => { + browser.test.assertEq(port.sender.tab, undefined, "Sender is not a tab"); + browser.test.assertEq(port.sender.url, FRAME_URL, "Expected sender URL"); + port.onMessage.addListener(msg => { + browser.test.assertEq("pong", msg, "Reply from content script"); + port.disconnect(); + }); + port.postMessage("ping"); + }); + await browser.contentScripts.register({ matches: ["http://example.com/dummyFrame"], js: [{ file: "contentscript.js" }], @@ -25,7 +35,15 @@ add_task(async function content_script_in_background_frame() { function contentScript() { browser.test.log(`Running content script at ${document.URL}`); - browser.test.sendMessage("done_in_content_script"); + + let port = browser.runtime.connect(); + port.onMessage.addListener(msg => { + browser.test.assertEq("ping", msg, "Expected message to content script"); + port.postMessage("pong"); + }); + port.onDisconnect.addListener(() => { + browser.test.sendMessage("disconnected_in_content_script"); + }); } let extension = ExtensionTestUtils.loadExtension({ @@ -38,6 +56,6 @@ add_task(async function content_script_in_background_frame() { background, }); await extension.startup(); - await extension.awaitMessage("done_in_content_script"); + await extension.awaitMessage("disconnected_in_content_script"); await extension.unload(); }); diff --git a/toolkit/components/extensions/test/xpcshell/test_ext_contentscript_xorigin_frame.js b/toolkit/components/extensions/test/xpcshell/test_ext_contentscript_xorigin_frame.js index 8a58b2475c68..cab508b04008 100644 --- a/toolkit/components/extensions/test/xpcshell/test_ext_contentscript_xorigin_frame.js +++ b/toolkit/components/extensions/test/xpcshell/test_ext_contentscript_xorigin_frame.js @@ -17,6 +17,23 @@ add_task(async function test_process_switch_cross_origin_frame() { ], }, + background() { + browser.runtime.onConnect.addListener(port => { + port.onMessage.addListener(async () => { + let { url, frameId } = port.sender; + + browser.test.assertTrue(frameId > 0, "sender frameId is ok"); + browser.test.assertTrue( + url.endsWith("file_iframe.html"), + "url is ok" + ); + + port.postMessage(frameId); + port.disconnect(); + }); + }); + }, + files: { "cs.js"() { browser.test.assertEq( @@ -25,9 +42,15 @@ add_task(async function test_process_switch_cross_origin_frame() { "url is ok" ); - // frameId is the BrowsingContext ID in practice. - let frameId = browser.runtime.getFrameId(window); - browser.test.sendMessage("content-script-loaded", frameId); + let frameId; + let port = browser.runtime.connect(); + port.onMessage.addListener(response => { + frameId = response; + }); + port.onDisconnect.addListener(() => { + browser.test.sendMessage("content-script-loaded", frameId); + }); + port.postMessage("hello"); }, }, });