Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4723)

Unified Diff: chrome/test/data/extensions/api_test/webrequest/test_types.js

Issue 1865303006: Map webRequest filter type to multiple internal ResourceTypes if needed (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2661
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/test/data/extensions/api_test/webrequest/test_types.js
diff --git a/chrome/test/data/extensions/api_test/webrequest/test_types.js b/chrome/test/data/extensions/api_test/webrequest/test_types.js
index 3ec81835850a7482a1abecb005ad71c95167b321..6fccbc0e3bf5be0800493711a2d4dbaea3196516 100644
--- a/chrome/test/data/extensions/api_test/webrequest/test_types.js
+++ b/chrome/test/data/extensions/api_test/webrequest/test_types.js
@@ -8,6 +8,11 @@ function getStyleURL() {
return getServerURL('empty.html?as-style');
}
+function getScriptURL() {
+ // The file is empty, so JS errors will not be generated upon execution.
+ return getServerURL('empty.html?as-script');
+}
+
function getFontURL() {
// Not a font, but will be loaded as a font.
return getServerURL('empty.html?as-font');
@@ -27,6 +32,16 @@ function getBeaconURL() {
return getServerURL('empty.html?as-beacon');
}
+function getScriptFilter() {
+ // Scripts and worker scripts are internally represented by a different
+ // ResourceType, but they still map to the same public "script" type.
+ // We have plenty of tests that confirm that requests are visible when no
+ // filter is applied. We also need to check whether the requests are still
+ // visible even after applying a "script" filter.
+ // This is part of the regression test for crbug.com/591988.
+ return {urls: ['<all_urls>'], types: ['script']};
+}
+
runTests([
function typeStylesheet() {
expect([
@@ -100,6 +115,98 @@ runTests([
document.body.appendChild(style);
},
+ function typeScript() {
+ expect([
+ { label: 'onBeforeRequest',
+ event: 'onBeforeRequest',
+ details: {
+ type: 'script',
+ url: getScriptURL(),
+ // Unknown because data:-URLs are invisible to the webRequest API,
+ // and the script is loaded via a data:-URL document in a frame.
+ frameUrl: 'unknown frame URL',
+ frameId: 1,
+ parentFrameId: 0,
+ // tabId 0 = tab opened by test runner;
+ // tabId 1 = this tab.
+ tabId: 1,
+ }
+ },
+ { label: 'onBeforeSendHeaders',
+ event: 'onBeforeSendHeaders',
+ details: {
+ type: 'script',
+ url: getScriptURL(),
+ frameId: 1,
+ parentFrameId: 0,
+ tabId: 1,
+ },
+ },
+ { label: 'onSendHeaders',
+ event: 'onSendHeaders',
+ details: {
+ type: 'script',
+ url: getScriptURL(),
+ frameId: 1,
+ parentFrameId: 0,
+ tabId: 1,
+ },
+ },
+ { label: 'onHeadersReceived',
+ event: 'onHeadersReceived',
+ details: {
+ type: 'script',
+ url: getScriptURL(),
+ frameId: 1,
+ parentFrameId: 0,
+ tabId: 1,
+ statusLine: 'HTTP/1.1 200 OK',
+ statusCode: 200,
+ },
+ },
+ { label: 'onResponseStarted',
+ event: 'onResponseStarted',
+ details: {
+ type: 'script',
+ url: getScriptURL(),
+ frameId: 1,
+ parentFrameId: 0,
+ tabId: 1,
+ ip: '127.0.0.1',
+ fromCache: false,
+ statusLine: 'HTTP/1.1 200 OK',
+ statusCode: 200,
+ },
+ },
+ { label: 'onCompleted',
+ event: 'onCompleted',
+ details: {
+ type: 'script',
+ url: getScriptURL(),
+ frameId: 1,
+ parentFrameId: 0,
+ tabId: 1,
+ ip: '127.0.0.1',
+ fromCache: false,
+ statusLine: 'HTTP/1.1 200 OK',
+ statusCode: 200,
+ },
+ }],
+ [['onBeforeRequest', 'onBeforeSendHeaders', 'onSendHeaders',
+ 'onHeadersReceived', 'onResponseStarted', 'onCompleted']],
+ getScriptFilter());
+
+ // This tab is an extension, and the default Content Security Policy forbids
+ // injecting external scripts in the page. So we just load the script in a
+ // frame via a data:-URL (which is not subject to the extension's CSP).
+ //
+ // data-URLs are not visible to the webRequest API, so we don't have to
+ // include the frame in the expectations - this is a nice side effect.
+ var frame = document.createElement('iframe');
+ frame.src = 'data:text/html,<script src="' + getScriptURL() + '"></script>';
+ document.body.appendChild(frame);
+ },
+
function typeFont() {
expect([
{ label: 'onBeforeRequest',
@@ -233,7 +340,8 @@ runTests([
},
}],
[['onBeforeRequest', 'onBeforeSendHeaders', 'onSendHeaders',
- 'onHeadersReceived', 'onResponseStarted', 'onCompleted']]);
+ 'onHeadersReceived', 'onResponseStarted', 'onCompleted']],
+ getScriptFilter());
new Worker(getWorkerURL());

Powered by Google App Engine
This is Rietveld 408576698