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

Unified Diff: chrome/test/data/extensions/platform_apps/web_view/shim/main.js

Issue 640603005: <webview>: Add additional WebRequest API test coverage. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix appshell test Created 6 years, 2 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/platform_apps/web_view/shim/main.js
diff --git a/chrome/test/data/extensions/platform_apps/web_view/shim/main.js b/chrome/test/data/extensions/platform_apps/web_view/shim/main.js
index 0b338108567ee50a744edd5aed43bd56fe5c7255..ffecb13159e13a7c309ef1e31c3d20db3f1d8311 100644
--- a/chrome/test/data/extensions/platform_apps/web_view/shim/main.js
+++ b/chrome/test/data/extensions/platform_apps/web_view/shim/main.js
@@ -24,6 +24,7 @@ embedder.setUp_ = function(config) {
'/extensions/platform_apps/web_view/shim/guest.html';
embedder.noReferrerGuestURL = embedder.baseGuestURL +
'/extensions/platform_apps/web_view/shim/guest_noreferrer.html';
+ embedder.detectUserAgentURL = embedder.baseGuestURL + '/detect-user-agent';
embedder.redirectGuestURL = embedder.baseGuestURL + '/server-redirect';
embedder.redirectGuestURLDest = embedder.baseGuestURL +
'/extensions/platform_apps/web_view/shim/guest_redirect.html';
@@ -1083,6 +1084,52 @@ function testWebRequestAPI() {
document.body.appendChild(webview);
}
+// This test verifies that the WebRequest API onBeforeSendHeaders event fires on
+// webview and supports headers. This tests verifies that we can modify HTTP
+// headers via the WebRequest API and those modified headers will be sent to the
+// HTTP server.
+function testWebRequestAPIWithHeaders() {
+ var webview = new WebView();
+ var requestFilter = {
+ urls: ['<all_urls>']
+ };
+ var extraInfoSpec = ['requestHeaders', 'blocking'];
+ webview.request.onBeforeSendHeaders.addListener(function(details) {
+ var headers = details.requestHeaders;
+ for( var i = 0, l = headers.length; i < l; ++i ) {
+ if (headers[i].name == 'User-Agent') {
+ headers[i].value = 'foobar';
+ break;
+ }
+ }
+ var blockingResponse = {};
+ blockingResponse.requestHeaders = headers;
+ return blockingResponse;
+ }, requestFilter, extraInfoSpec);
+
+ var loadstartCalled = false;
+ webview.addEventListener('loadstart', function(e) {
+ embedder.test.assertTrue(e.isTopLevel);
+ embedder.test.assertEq(embedder.detectUserAgentURL, e.url);
+ loadstartCalled = true;
+ });
+
+ webview.addEventListener('loadredirect', function(e) {
+ embedder.test.assertTrue(e.isTopLevel);
+ embedder.test.assertEq(embedder.detectUserAgentURL,
+ e.oldUrl.replace('127.0.0.1', 'localhost'));
+ embedder.test.assertEq(embedder.redirectGuestURLDest,
+ e.newUrl.replace('127.0.0.1', 'localhost'));
+ if (loadstartCalled) {
+ embedder.test.succeed();
+ } else {
+ embedder.test.fail();
+ }
+ });
+ webview.src = embedder.detectUserAgentURL;
+ document.body.appendChild(webview);
+}
+
// This test verifies that the basic use cases of the declarative WebRequest API
// work as expected. This test demonstrates that rules can be added prior to
// navigation and attachment.
@@ -1976,6 +2023,7 @@ embedder.test.testList = {
'testDeclarativeWebRequestAPISendMessage':
testDeclarativeWebRequestAPISendMessage,
'testWebRequestAPI': testWebRequestAPI,
+ 'testWebRequestAPIWithHeaders': testWebRequestAPIWithHeaders,
'testWebRequestAPIGoogleProperty': testWebRequestAPIGoogleProperty,
'testWebRequestListenerSurvivesReparenting':
testWebRequestListenerSurvivesReparenting,
« no previous file with comments | « chrome/browser/apps/web_view_browsertest.cc ('k') | extensions/browser/guest_view/web_view/web_view_apitest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698