author | Luca Greco <lgreco@mozilla.com> |
Mon, 18 May 2020 14:21:53 +0000 | |
changeset 530611 | 4329b5a4d83ef07f7abbca043019a40c6857cef8 |
parent 530610 | ace67deac3a4223554b0e65b06821982418988de |
child 530612 | c60c48d170e1722905c103f07e78a9871f31a89e |
push id | 37428 |
push user | nbeleuzu@mozilla.com |
push date | Mon, 18 May 2020 21:48:24 +0000 |
treeherder | mozilla-central@a3941f42e662 [default view] [failures only] |
perfherder | [talos] [build metrics] [platform microbench] (compared to previous push) |
reviewers | mixedpuppy |
bugs | 1638581 |
milestone | 78.0a1 |
first release with | nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
|
last release without | nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
|
--- a/toolkit/components/extensions/schemas/web_request.json +++ b/toolkit/components/extensions/schemas/web_request.json @@ -36,17 +36,16 @@ "main_frame", "sub_frame", "stylesheet", "script", "image", "object", "object_subrequest", "xmlhttprequest", - "xbl", "xslt", "ping", "beacon", "xml_dtd", "font", "media", "websocket", "csp_report", @@ -110,17 +109,17 @@ "description": "A list of URLs or URL patterns. Requests that cannot match any of the URLs will be filtered out.", "items": { "type": "string" }, "minItems": 1 }, "types": { "type": "array", "optional": true, "description": "A list of request types. Requests that cannot match any of the types will be filtered out.", - "items": { "$ref": "ResourceType" }, + "items": { "$ref": "ResourceType", "onError": "warn" }, "minItems": 1 }, "tabId": { "type": "integer", "optional": true }, "windowId": { "type": "integer", "optional": true }, "incognito": { "type": "boolean", "optional": true, "description": "If provided, requests that do not match the incognito state will be filtered out."} } }, {
new file mode 100644 --- /dev/null +++ b/toolkit/components/extensions/test/xpcshell/test_ext_webRequest_filterTypes.js @@ -0,0 +1,85 @@ +"use strict"; + +AddonTestUtils.init(this); + +AddonTestUtils.createAppInfo( + "xpcshell@tests.mozilla.org", + "XPCShell", + "1", + "42" +); + +const server = createHttpServer({ hosts: ["example.com"] }); +server.registerPathHandler("/", (request, response) => { + response.setHeader("Content-Tpe", "text/plain", false); + response.write("OK"); +}); + +add_task(async function test_all_webRequest_ResourceTypes() { + let extension = ExtensionTestUtils.loadExtension({ + manifest: { + permissions: ["webRequest", "webRequestBlocking", "*://example.com/*"], + }, + background() { + browser.test.onMessage.addListener(async msg => { + browser.webRequest[msg.event].addListener( + () => {}, + { urls: ["*://example.com/*"], ...msg.filter }, + ["blocking"] + ); + // Call an API method implemented in the parent process to + // be sure that the webRequest listener has been registered + // in the parent process as well. + await browser.runtime.getBrowserInfo(); + browser.test.sendMessage(`webRequest-listener-registered`); + }); + }, + }); + + await extension.startup(); + + const { Schemas } = ChromeUtils.import("resource://gre/modules/Schemas.jsm"); + const webRequestSchema = Schemas.privilegedSchemaJSON + .get("chrome://extensions/content/schemas/web_request.json") + .deserialize({}); + const ResourceType = webRequestSchema[1].types.filter( + type => type.id == "ResourceType" + )[0]; + ok( + ResourceType && ResourceType.enum, + "Found ResourceType in the web_request.json schema" + ); + info( + "Register webRequest.onBeforeRequest event listener for all supported ResourceType" + ); + + let { messages } = await promiseConsoleOutput(async () => { + ExtensionTestUtils.failOnSchemaWarnings(false); + extension.sendMessage({ + event: "onBeforeRequest", + filter: { + // Verify that the resourceType not supported is going to be ignored + // and all the ones supported does not trigger a ChannelWrapper.matches + // exception once the listener is being triggered. + types: [].concat(ResourceType.enum, "not-supported-resource-type"), + }, + }); + await extension.awaitMessage("webRequest-listener-registered"); + ExtensionTestUtils.failOnSchemaWarnings(); + + await ExtensionTestUtils.fetch( + "http://example.com/dummy", + "http://example.com" + ); + }); + + AddonTestUtils.checkMessages(messages, { + expected: [ + { message: /Warning processing types: .* "not-supported-resource-type"/ }, + ], + forbidden: [{ message: /JavaScript Error: "ChannelWrapper.matches/ }], + }); + info("No ChannelWrapper.matches errors have been logged"); + + await extension.unload(); +});
--- a/toolkit/components/extensions/test/xpcshell/xpcshell-common.ini +++ b/toolkit/components/extensions/test/xpcshell/xpcshell-common.ini @@ -178,16 +178,17 @@ skip-if = true # Too frequent intermitte [test_ext_userScripts_telemetry.js] [test_ext_webRequest_auth.js] skip-if = os == "android" && debug [test_ext_webRequest_cached.js] skip-if = os == "android" && processor != "x86_64" # Bug 1573511 [test_ext_webRequest_cancelWithReason.js] [test_ext_webRequest_filterResponseData.js] skip-if = os == "android" && debug +[test_ext_webRequest_filterTypes.js] [test_ext_webRequest_from_extension_page.js] [test_ext_webRequest_incognito.js] skip-if = os == "android" && debug [test_ext_webRequest_host.js] skip-if = os == "android" && debug [test_ext_webRequest_mergecsp.js] [test_ext_webRequest_permission.js] skip-if = os == "android" && debug