diff --git a/chrome/browser/extensions/api/web_request/web_request_apitest.cc b/chrome/browser/extensions/api/web_request/web_request_apitest.cc index 088ae5e7c94d..f651b404e88e 100644 --- a/chrome/browser/extensions/api/web_request/web_request_apitest.cc +++ b/chrome/browser/extensions/api/web_request/web_request_apitest.cc @@ -556,14 +556,6 @@ IN_PROC_BROWSER_TEST_F(ExtensionWebRequestApiTest, WebRequestRedirects) { << message_; } -IN_PROC_BROWSER_TEST_F(ExtensionWebRequestApiTest, - WebRequestRedirectsWithExtraHeaders) { - ASSERT_TRUE(StartEmbeddedTestServer()); - ASSERT_TRUE(RunExtensionSubtestWithArg("webrequest", "test_redirects.html", - "useExtraHeaders")) - << message_; -} - // Tests that redirects from secure to insecure don't send the referrer header. IN_PROC_BROWSER_TEST_F(ExtensionWebRequestApiTest, WebRequestRedirectsToInsecure) { @@ -596,14 +588,6 @@ IN_PROC_BROWSER_TEST_F(ExtensionWebRequestApiTest, << message_; } -IN_PROC_BROWSER_TEST_F(ExtensionWebRequestApiTest, - WebRequestSubresourceRedirectsWithExtraHeaders) { - ASSERT_TRUE(StartEmbeddedTestServer()); - ASSERT_TRUE(RunExtensionSubtestWithArg( - "webrequest", "test_subresource_redirects.html", "useExtraHeaders")) - << message_; -} - // Fails often on Windows dbg bots. http://crbug.com/177163 #if defined(OS_WIN) #define MAYBE_WebRequestNewTab DISABLED_WebRequestNewTab diff --git a/chrome/test/data/extensions/api_test/webrequest/test_redirects.js b/chrome/test/data/extensions/api_test/webrequest/test_redirects.js index 93e222328b43..d4c197794bba 100644 --- a/chrome/test/data/extensions/api_test/webrequest/test_redirects.js +++ b/chrome/test/data/extensions/api_test/webrequest/test_redirects.js @@ -27,211 +27,203 @@ function assertRedirectFails(url) { }); } -chrome.test.getConfig(function(config) { - var onHeadersReceivedExtraInfoSpec = ['blocking']; - if (config.customArg === 'useExtraHeaders') - onHeadersReceivedExtraInfoSpec.push('extraHeaders'); - - runTests([ - function redirectToDataUrlOnHeadersReceived() { - var url = getServerURL('echo'); - var listener = function(details) { - return {redirectUrl: dataURL}; - }; - chrome.webRequest.onHeadersReceived.addListener(listener, - {urls: [url]}, onHeadersReceivedExtraInfoSpec); - - assertRedirectSucceeds(url, dataURL, function() { - chrome.webRequest.onHeadersReceived.removeListener(listener); - }); - }, - - function redirectToAboutUrlOnHeadersReceived() { - var url = getServerURL('echo'); - var listener = function(details) { - return {redirectUrl: aboutURL}; - }; - chrome.webRequest.onHeadersReceived.addListener(listener, - {urls: [url]}, onHeadersReceivedExtraInfoSpec); - - assertRedirectSucceeds(url, aboutURL, function() { - chrome.webRequest.onHeadersReceived.removeListener(listener); - }); - }, - - function redirectToNonWebAccessibleUrlOnHeadersReceived() { - var url = getServerURL('echo'); - var listener = function(details) { - return {redirectUrl: getURLNonWebAccessible()}; - }; - chrome.webRequest.onHeadersReceived.addListener(listener, - {urls: [url]}, onHeadersReceivedExtraInfoSpec); - - assertRedirectSucceeds(url, getURLNonWebAccessible(), function() { - chrome.webRequest.onHeadersReceived.removeListener(listener); - }); - }, - - function redirectToServerRedirectOnHeadersReceived() { - var url = getServerURL('echo'); - var redirectURL = getServerURL('server-redirect?' + - getURLWebAccessible()); - var listener = function(details) { - return {redirectUrl: redirectURL}; - }; - chrome.webRequest.onHeadersReceived.addListener(listener, - {urls: [url]}, onHeadersReceivedExtraInfoSpec); - - assertRedirectSucceeds(url, getURLWebAccessible(), function() { - chrome.webRequest.onHeadersReceived.removeListener(listener); - }); - }, - - function serverRedirectThenExtensionRedirectOnHeadersReceived() { - var url_1 = getServerURL('echo'); - var url_2 = getURLWebAccessible(); - var serverRedirect = getServerURL('server-redirect?' + url_1); - var listener = function(details) { - return {redirectUrl: url_2}; - }; - chrome.webRequest.onHeadersReceived.addListener( - listener, - { urls: [url_1] }, - ["blocking"] - ); - - assertRedirectSucceeds(serverRedirect, url_2, function() { - chrome.webRequest.onHeadersReceived.removeListener(listener); - }); - }, - - function redirectToUnallowedServerRedirectOnHeadersReceived() { - var url = getServerURL('echo'); - var redirectURL = getServerURL('server-redirect?' + - getURLNonWebAccessible()); - var listener = function(details) { - return {redirectUrl: redirectURL}; - }; - chrome.webRequest.onHeadersReceived.addListener(listener, - {urls: [url]}, onHeadersReceivedExtraInfoSpec); - - // The page should be redirected to redirectURL, but not to the non web - // accessible URL. - assertRedirectSucceeds(url, redirectURL, function() { - chrome.webRequest.onHeadersReceived.removeListener(listener); - }); - }, - - function redirectToDataUrlOnBeforeRequest() { - var url = getServerURL('echo'); - var listener = function(details) { - return {redirectUrl: dataURL}; - }; - chrome.webRequest.onBeforeRequest.addListener(listener, - {urls: [url]}, ['blocking']); - - assertRedirectSucceeds(url, dataURL, function() { - chrome.webRequest.onBeforeRequest.removeListener(listener); - }); - }, - - function redirectToAboutUrlOnBeforeRequest() { - var url = getServerURL('echo'); - var listener = function(details) { - return {redirectUrl: aboutURL}; - }; - chrome.webRequest.onBeforeRequest.addListener(listener, - {urls: [url]}, ['blocking']); - - assertRedirectSucceeds(url, aboutURL, function() { - chrome.webRequest.onBeforeRequest.removeListener(listener); - }); - }, - - function redirectToNonWebAccessibleUrlOnBeforeRequest() { - var url = getServerURL('echo'); - var listener = function(details) { - return {redirectUrl: getURLNonWebAccessible()}; - }; - chrome.webRequest.onBeforeRequest.addListener(listener, - {urls: [url]}, ['blocking']); - - assertRedirectSucceeds(url, getURLNonWebAccessible(), function() { - chrome.webRequest.onBeforeRequest.removeListener(listener); - }); - }, - - function redirectToServerRedirectOnBeforeRequest() { - var url = getServerURL('echo'); - var redirectURL = getServerURL('server-redirect?' + - getURLWebAccessible()); - var listener = function(details) { - return {redirectUrl: redirectURL}; - }; - chrome.webRequest.onBeforeRequest.addListener(listener, - {urls: [url]}, ['blocking']); - - assertRedirectSucceeds(url, getURLWebAccessible(), function() { - chrome.webRequest.onBeforeRequest.removeListener(listener); - }); - }, - - // A server redirect immediately followed by an extension redirect. - // Regression test for: - // - https://crbug.com/882661 - // - https://crbug.com/880741 - function serverRedirectThenExtensionRedirectOnBeforeRequest() { - var url_1 = getServerURL('echo'); - var url_2 = getURLWebAccessible(); - var serverRedirect = getServerURL('server-redirect?' + url_1); - var listener = function(details) { - return {redirectUrl: url_2}; - }; - chrome.webRequest.onBeforeRequest.addListener( - listener, - { urls: [url_1] }, - ["blocking"] - ); - - assertRedirectSucceeds(serverRedirect, url_2, function() { - chrome.webRequest.onBeforeRequest.removeListener(listener); - }); - }, - - function redirectToUnallowedServerRedirectOnBeforeRequest() { - var url = getServerURL('echo'); - var redirectURL = getServerURL('server-redirect?' + - getURLNonWebAccessible()); - var listener = function(details) { - return {redirectUrl: redirectURL}; - }; - chrome.webRequest.onBeforeRequest.addListener(listener, - {urls: [url]}, ['blocking']); - - // The page should be redirected to redirectURL, but not to the non web - // accessible URL. - assertRedirectSucceeds(url, redirectURL, function() { - chrome.webRequest.onBeforeRequest.removeListener(listener); - }); - }, - - function redirectToAboutUrlWithServerRedirect() { - assertRedirectFails(getServerURL('server-redirect?' + aboutURL)); - }, - - function redirectToDataUrlWithServerRedirect() { - assertRedirectFails(getServerURL('server-redirect?' + dataURL)); - }, - - function redirectToNonWebAccessibleUrlWithServerRedirect() { - assertRedirectFails( - getServerURL('server-redirect?' + getURLNonWebAccessible())); - }, - - function redirectToWebAccessibleUrlWithServerRedirect() { - assertRedirectSucceeds( - getServerURL('server-redirect?' + getURLWebAccessible()), - getURLWebAccessible()); - }, - ]); -}); +runTests([ + function redirectToDataUrlOnHeadersReceived() { + var url = getServerURL('echo'); + var listener = function(details) { + return {redirectUrl: dataURL}; + }; + chrome.webRequest.onHeadersReceived.addListener(listener, + {urls: [url]}, ['blocking']); + + assertRedirectSucceeds(url, dataURL, function() { + chrome.webRequest.onHeadersReceived.removeListener(listener); + }); + }, + + function redirectToAboutUrlOnHeadersReceived() { + var url = getServerURL('echo'); + var listener = function(details) { + return {redirectUrl: aboutURL}; + }; + chrome.webRequest.onHeadersReceived.addListener(listener, + {urls: [url]}, ['blocking']); + + assertRedirectSucceeds(url, aboutURL, function() { + chrome.webRequest.onHeadersReceived.removeListener(listener); + }); + }, + + function redirectToNonWebAccessibleUrlOnHeadersReceived() { + var url = getServerURL('echo'); + var listener = function(details) { + return {redirectUrl: getURLNonWebAccessible()}; + }; + chrome.webRequest.onHeadersReceived.addListener(listener, + {urls: [url]}, ['blocking']); + + assertRedirectSucceeds(url, getURLNonWebAccessible(), function() { + chrome.webRequest.onHeadersReceived.removeListener(listener); + }); + }, + + function redirectToServerRedirectOnHeadersReceived() { + var url = getServerURL('echo'); + var redirectURL = getServerURL('server-redirect?' + getURLWebAccessible()); + var listener = function(details) { + return {redirectUrl: redirectURL}; + }; + chrome.webRequest.onHeadersReceived.addListener(listener, + {urls: [url]}, ['blocking']); + + assertRedirectSucceeds(url, getURLWebAccessible(), function() { + chrome.webRequest.onHeadersReceived.removeListener(listener); + }); + }, + + function serverRedirectThenExtensionRedirectOnHeadersReceived() { + var url_1 = getServerURL('echo'); + var url_2 = getURLWebAccessible(); + var serverRedirect = getServerURL('server-redirect?' + url_1); + var listener = function(details) { + return {redirectUrl: url_2}; + }; + chrome.webRequest.onHeadersReceived.addListener( + listener, + { urls: [url_1] }, + ["blocking"] + ); + + assertRedirectSucceeds(serverRedirect, url_2, function() { + chrome.webRequest.onHeadersReceived.removeListener(listener); + }); + }, + + function redirectToUnallowedServerRedirectOnHeadersReceived() { + var url = getServerURL('echo'); + var redirectURL = getServerURL('server-redirect?' + + getURLNonWebAccessible()); + var listener = function(details) { + return {redirectUrl: redirectURL}; + }; + chrome.webRequest.onHeadersReceived.addListener(listener, + {urls: [url]}, ['blocking']); + + // The page should be redirected to redirectURL, but not to the non web + // accessible URL. + assertRedirectSucceeds(url, redirectURL, function() { + chrome.webRequest.onHeadersReceived.removeListener(listener); + }); + }, + + function redirectToDataUrlOnBeforeRequest() { + var url = getServerURL('echo'); + var listener = function(details) { + return {redirectUrl: dataURL}; + }; + chrome.webRequest.onBeforeRequest.addListener(listener, + {urls: [url]}, ['blocking']); + + assertRedirectSucceeds(url, dataURL, function() { + chrome.webRequest.onBeforeRequest.removeListener(listener); + }); + }, + + function redirectToAboutUrlOnBeforeRequest() { + var url = getServerURL('echo'); + var listener = function(details) { + return {redirectUrl: aboutURL}; + }; + chrome.webRequest.onBeforeRequest.addListener(listener, + {urls: [url]}, ['blocking']); + + assertRedirectSucceeds(url, aboutURL, function() { + chrome.webRequest.onBeforeRequest.removeListener(listener); + }); + }, + + function redirectToNonWebAccessibleUrlOnBeforeRequest() { + var url = getServerURL('echo'); + var listener = function(details) { + return {redirectUrl: getURLNonWebAccessible()}; + }; + chrome.webRequest.onBeforeRequest.addListener(listener, + {urls: [url]}, ['blocking']); + + assertRedirectSucceeds(url, getURLNonWebAccessible(), function() { + chrome.webRequest.onBeforeRequest.removeListener(listener); + }); + }, + + function redirectToServerRedirectOnBeforeRequest() { + var url = getServerURL('echo'); + var redirectURL = getServerURL('server-redirect?' + getURLWebAccessible()); + var listener = function(details) { + return {redirectUrl: redirectURL}; + }; + chrome.webRequest.onBeforeRequest.addListener(listener, + {urls: [url]}, ['blocking']); + + assertRedirectSucceeds(url, getURLWebAccessible(), function() { + chrome.webRequest.onBeforeRequest.removeListener(listener); + }); + }, + + // A server redirect immediately followed by an extension redirect. + // Regression test for: + // - https://crbug.com/882661 + // - https://crbug.com/880741 + function serverRedirectThenExtensionRedirectOnBeforeRequest() { + var url_1 = getServerURL('echo'); + var url_2 = getURLWebAccessible(); + var serverRedirect = getServerURL('server-redirect?' + url_1); + var listener = function(details) { + return {redirectUrl: url_2}; + }; + chrome.webRequest.onBeforeRequest.addListener( + listener, + { urls: [url_1] }, + ["blocking"] + ); + + assertRedirectSucceeds(serverRedirect, url_2, function() { + chrome.webRequest.onBeforeRequest.removeListener(listener); + }); + }, + + function redirectToUnallowedServerRedirectOnBeforeRequest() { + var url = getServerURL('echo'); + var redirectURL = getServerURL('server-redirect?' + + getURLNonWebAccessible()); + var listener = function(details) { + return {redirectUrl: redirectURL}; + }; + chrome.webRequest.onBeforeRequest.addListener(listener, + {urls: [url]}, ['blocking']); + + // The page should be redirected to redirectURL, but not to the non web + // accessible URL. + assertRedirectSucceeds(url, redirectURL, function() { + chrome.webRequest.onBeforeRequest.removeListener(listener); + }); + }, + + function redirectToAboutUrlWithServerRedirect() { + assertRedirectFails(getServerURL('server-redirect?' + aboutURL)); + }, + + function redirectToDataUrlWithServerRedirect() { + assertRedirectFails(getServerURL('server-redirect?' + dataURL)); + }, + + function redirectToNonWebAccessibleUrlWithServerRedirect() { + assertRedirectFails( + getServerURL('server-redirect?' + getURLNonWebAccessible())); + }, + + function redirectToWebAccessibleUrlWithServerRedirect() { + assertRedirectSucceeds( + getServerURL('server-redirect?' + getURLWebAccessible()), + getURLWebAccessible()); + }, +]); diff --git a/chrome/test/data/extensions/api_test/webrequest/test_subresource_redirects.js b/chrome/test/data/extensions/api_test/webrequest/test_subresource_redirects.js index b845b8eb4ad3..c3686c3fdb7a 100644 --- a/chrome/test/data/extensions/api_test/webrequest/test_subresource_redirects.js +++ b/chrome/test/data/extensions/api_test/webrequest/test_subresource_redirects.js @@ -46,137 +46,129 @@ function assertRedirectFails(url, callback) { }); } -chrome.test.getConfig(function(config) { - var onHeadersReceivedExtraInfoSpec = ['blocking']; - if (config.customArg === 'useExtraHeaders') - onHeadersReceivedExtraInfoSpec.push('extraHeaders'); - - runTests([ - function subresourceRedirectToDataUrlOnHeadersReceived() { - var url = getServerURL('echo'); - var listener = function(details) { - return {redirectUrl: dataURL}; - }; - chrome.webRequest.onHeadersReceived.addListener(listener, - {urls: [url]}, onHeadersReceivedExtraInfoSpec); - - assertRedirectSucceeds(url, dataURL, function() { - chrome.webRequest.onHeadersReceived.removeListener(listener); - }); - }, - - function subresourceRedirectToNonWebAccessibleUrlOnHeadersReceived() { - var url = getServerURL('echo'); - var listener = function(details) { - return {redirectUrl: getURLNonWebAccessible()}; - }; - chrome.webRequest.onHeadersReceived.addListener(listener, - {urls: [url]}, onHeadersReceivedExtraInfoSpec); - - assertRedirectSucceeds(url, getURLNonWebAccessible(), function() { - chrome.webRequest.onHeadersReceived.removeListener(listener); - }); - }, - - function subresourceRedirectToServerRedirectOnHeadersReceived() { - var url = getServerURL('echo'); - var redirectURL = getServerURL('server-redirect?' + - getURLWebAccessible()); - var listener = function(details) { - return {redirectUrl: redirectURL}; - }; - chrome.webRequest.onHeadersReceived.addListener(listener, - {urls: [url]}, onHeadersReceivedExtraInfoSpec); - - assertRedirectSucceeds(url, getURLWebAccessible(), function() { - chrome.webRequest.onHeadersReceived.removeListener(listener); - }); - }, - - function subresourceRedirectToUnallowedServerRedirectOnHeadersReceived() { - var url = getServerURL('echo'); - var redirectURL = getServerURL('server-redirect?' + - getURLNonWebAccessible()); - var listener = function(details) { - return {redirectUrl: redirectURL}; - }; - chrome.webRequest.onHeadersReceived.addListener(listener, - {urls: [url]}, onHeadersReceivedExtraInfoSpec); - - assertRedirectFails(url, function() { - chrome.webRequest.onHeadersReceived.removeListener(listener); - }); - }, - - function subresourceRedirectToDataUrlOnBeforeRequest() { - var url = getServerURL('echo'); - var listener = function(details) { - return {redirectUrl: dataURL}; - }; - chrome.webRequest.onBeforeRequest.addListener(listener, - {urls: [url]}, ['blocking']); - - assertRedirectSucceeds(url, dataURL, function() { - chrome.webRequest.onBeforeRequest.removeListener(listener); - }); - }, - - function subresourceRedirectToNonWebAccessibleUrlOnBeforeRequest() { - var url = getServerURL('echo'); - var listener = function(details) { - return {redirectUrl: getURLNonWebAccessible()}; - }; - chrome.webRequest.onBeforeRequest.addListener(listener, - {urls: [url]}, ['blocking']); - - assertRedirectSucceeds(url, getURLNonWebAccessible(), function() { - chrome.webRequest.onBeforeRequest.removeListener(listener); - }); - }, - - function subresourceRedirectToServerRedirectOnBeforeRequest() { - var url = getServerURL('echo'); - var redirectURL = getServerURL('server-redirect?' + - getURLWebAccessible()); - var listener = function(details) { - return {redirectUrl: redirectURL}; - }; - chrome.webRequest.onBeforeRequest.addListener(listener, - {urls: [url]}, ['blocking']); - - assertRedirectSucceeds(url, getURLWebAccessible(), function() { - chrome.webRequest.onBeforeRequest.removeListener(listener); - }); - }, - - function subresourceRedirectToUnallowedServerRedirectOnBeforeRequest() { - var url = getServerURL('echo'); - var redirectURL = getServerURL('server-redirect?' + - getURLNonWebAccessible()); - var listener = function(details) { - return {redirectUrl: redirectURL}; - }; - chrome.webRequest.onBeforeRequest.addListener(listener, - {urls: [url]}, ['blocking']); - - assertRedirectFails(url, function() { - chrome.webRequest.onBeforeRequest.removeListener(listener); - }); - }, - - function subresourceRedirectToDataUrlWithServerRedirect() { - assertRedirectFails(getServerURL('server-redirect?' + dataURL)); - }, - - function subresourceRedirectToNonWebAccessibleWithServerRedirect() { - assertRedirectFails( - getServerURL('server-redirect?' + getURLNonWebAccessible())); - }, - - function subresourceRedirectToWebAccessibleWithServerRedirect() { - assertRedirectSucceeds( - getServerURL('server-redirect?' + getURLWebAccessible()), - getURLWebAccessible()); - }, - ]); -}); +runTests([ + function subresourceRedirectToDataUrlOnHeadersReceived() { + var url = getServerURL('echo'); + var listener = function(details) { + return {redirectUrl: dataURL}; + }; + chrome.webRequest.onHeadersReceived.addListener(listener, + {urls: [url]}, ['blocking']); + + assertRedirectSucceeds(url, dataURL, function() { + chrome.webRequest.onHeadersReceived.removeListener(listener); + }); + }, + + function subresourceRedirectToNonWebAccessibleUrlOnHeadersReceived() { + var url = getServerURL('echo'); + var listener = function(details) { + return {redirectUrl: getURLNonWebAccessible()}; + }; + chrome.webRequest.onHeadersReceived.addListener(listener, + {urls: [url]}, ['blocking']); + + assertRedirectSucceeds(url, getURLNonWebAccessible(), function() { + chrome.webRequest.onHeadersReceived.removeListener(listener); + }); + }, + + function subresourceRedirectToServerRedirectOnHeadersReceived() { + var url = getServerURL('echo'); + var redirectURL = getServerURL('server-redirect?' + getURLWebAccessible()); + var listener = function(details) { + return {redirectUrl: redirectURL}; + }; + chrome.webRequest.onHeadersReceived.addListener(listener, + {urls: [url]}, ['blocking']); + + assertRedirectSucceeds(url, getURLWebAccessible(), function() { + chrome.webRequest.onHeadersReceived.removeListener(listener); + }); + }, + + function subresourceRedirectToUnallowedServerRedirectOnHeadersReceived() { + var url = getServerURL('echo'); + var redirectURL = getServerURL('server-redirect?' + + getURLNonWebAccessible()); + var listener = function(details) { + return {redirectUrl: redirectURL}; + }; + chrome.webRequest.onHeadersReceived.addListener(listener, + {urls: [url]}, ['blocking']); + + assertRedirectFails(url, function() { + chrome.webRequest.onHeadersReceived.removeListener(listener); + }); + }, + + function subresourceRedirectToDataUrlOnBeforeRequest() { + var url = getServerURL('echo'); + var listener = function(details) { + return {redirectUrl: dataURL}; + }; + chrome.webRequest.onBeforeRequest.addListener(listener, + {urls: [url]}, ['blocking']); + + assertRedirectSucceeds(url, dataURL, function() { + chrome.webRequest.onBeforeRequest.removeListener(listener); + }); + }, + + function subresourceRedirectToNonWebAccessibleUrlOnBeforeRequest() { + var url = getServerURL('echo'); + var listener = function(details) { + return {redirectUrl: getURLNonWebAccessible()}; + }; + chrome.webRequest.onBeforeRequest.addListener(listener, + {urls: [url]}, ['blocking']); + + assertRedirectSucceeds(url, getURLNonWebAccessible(), function() { + chrome.webRequest.onBeforeRequest.removeListener(listener); + }); + }, + + function subresourceRedirectToServerRedirectOnBeforeRequest() { + var url = getServerURL('echo'); + var redirectURL = getServerURL('server-redirect?' + getURLWebAccessible()); + var listener = function(details) { + return {redirectUrl: redirectURL}; + }; + chrome.webRequest.onBeforeRequest.addListener(listener, + {urls: [url]}, ['blocking']); + + assertRedirectSucceeds(url, getURLWebAccessible(), function() { + chrome.webRequest.onBeforeRequest.removeListener(listener); + }); + }, + + function subresourceRedirectToUnallowedServerRedirectOnBeforeRequest() { + var url = getServerURL('echo'); + var redirectURL = getServerURL('server-redirect?' + + getURLNonWebAccessible()); + var listener = function(details) { + return {redirectUrl: redirectURL}; + }; + chrome.webRequest.onBeforeRequest.addListener(listener, + {urls: [url]}, ['blocking']); + + assertRedirectFails(url, function() { + chrome.webRequest.onBeforeRequest.removeListener(listener); + }); + }, + + function subresourceRedirectToDataUrlWithServerRedirect() { + assertRedirectFails(getServerURL('server-redirect?' + dataURL)); + }, + + function subresourceRedirectToNonWebAccessibleWithServerRedirect() { + assertRedirectFails( + getServerURL('server-redirect?' + getURLNonWebAccessible())); + }, + + function subresourceRedirectToWebAccessibleWithServerRedirect() { + assertRedirectSucceeds( + getServerURL('server-redirect?' + getURLWebAccessible()), + getURLWebAccessible()); + }, +]); diff --git a/extensions/browser/api/web_request/web_request_proxying_url_loader_factory.cc b/extensions/browser/api/web_request/web_request_proxying_url_loader_factory.cc index 28381408a9b7..e5b9c0c301c2 100644 --- a/extensions/browser/api/web_request/web_request_proxying_url_loader_factory.cc +++ b/extensions/browser/api/web_request/web_request_proxying_url_loader_factory.cc @@ -288,6 +288,18 @@ void WebRequestProxyingURLLoaderFactory::InProgressRequest::OnHeadersReceived( void WebRequestProxyingURLLoaderFactory::InProgressRequest:: HandleBeforeRequestRedirect() { + // The extension requested a redirect. Close the connection with the current + // URLLoader and inform the URLLoaderClient the WebRequest API generated a + // redirect. To load |redirect_url_|, a new URLLoader will be recreated + // after receiving FollowRedirect(). + + // Forgetting to close the connection with the current URLLoader caused + // bugs. The latter doesn't know anything about the redirect. Continuing + // the load with it gives unexpected results. See + // https://crbug.com/882661#c72. + proxied_client_binding_.Close(); + target_loader_.reset(); + constexpr int kInternalRedirectStatusCode = 307; net::RedirectInfo redirect_info; @@ -549,7 +561,13 @@ void WebRequestProxyingURLLoaderFactory::InProgressRequest:: redirect_info.new_method = request_.method; redirect_info.new_url = new_url; redirect_info.new_site_for_cookies = new_url; + + // These will get re-bound if a new request is initiated by + // |FollowRedirect()|. + proxied_client_binding_.Close(); + target_loader_.reset(); on_receive_response_received_ = false; + ContinueToBeforeRedirect(redirect_info, net::OK); return; } @@ -574,10 +592,8 @@ void WebRequestProxyingURLLoaderFactory::InProgressRequest:: info_->AddResponseInfoFromResourceResponse(current_response_); - // These will get re-bound if a new request is initiated by - // |FollowRedirect()|. - proxied_client_binding_.Close(); - target_loader_.reset(); + if (proxied_client_binding_.is_bound()) + proxied_client_binding_.ResumeIncomingMethodCallProcessing(); ExtensionWebRequestEventRouter::GetInstance()->OnBeforeRedirect( factory_->browser_context_, factory_->info_map_, &info_.value(),