Commit a2d2076e authored by Clark DuVall's avatar Clark DuVall Committed by Commit Bot

Fix ExtensionWebRequestApiTest.WebRequestDeclarative2 with network service

This test was modifying Set-Cookie and removing User-Agent, which is no
longer supported with the network service (see crbug.com/827582).

Bug: 827582, 721414
Cq-Include-Trybots: luci.chromium.try:linux_mojo
Change-Id: I977bcc767188eafb76c6d560bb959871ed73808a
Reviewed-on: https://chromium-review.googlesource.com/1145941Reviewed-by: default avatarKen Rockot <rockot@chromium.org>
Commit-Queue: Clark DuVall <cduvall@chromium.org>
Cr-Commit-Position: refs/heads/master@{#577395}
parent f5874da3
...@@ -557,7 +557,12 @@ IN_PROC_BROWSER_TEST_F(ExtensionWebRequestApiTest, ...@@ -557,7 +557,12 @@ IN_PROC_BROWSER_TEST_F(ExtensionWebRequestApiTest,
IN_PROC_BROWSER_TEST_F(ExtensionWebRequestApiTest, IN_PROC_BROWSER_TEST_F(ExtensionWebRequestApiTest,
MAYBE_WebRequestDeclarative2) { MAYBE_WebRequestDeclarative2) {
ASSERT_TRUE(StartEmbeddedTestServer()); ASSERT_TRUE(StartEmbeddedTestServer());
ASSERT_TRUE(RunExtensionSubtest("webrequest", "test_declarative2.html")) const char* network_service_arg =
base::FeatureList::IsEnabled(network::features::kNetworkService)
? "NetworkServiceEnabled"
: "NetworkServiceDisabled";
ASSERT_TRUE(RunExtensionSubtestWithArg("webrequest", "test_declarative2.html",
network_service_arg))
<< message_; << message_;
} }
......
...@@ -27,6 +27,8 @@ var EditRequestCookie = chrome.declarativeWebRequest.EditRequestCookie; ...@@ -27,6 +27,8 @@ var EditRequestCookie = chrome.declarativeWebRequest.EditRequestCookie;
var EditResponseCookie = chrome.declarativeWebRequest.EditResponseCookie; var EditResponseCookie = chrome.declarativeWebRequest.EditResponseCookie;
var RemoveRequestCookie = chrome.declarativeWebRequest.RemoveRequestCookie; var RemoveRequestCookie = chrome.declarativeWebRequest.RemoveRequestCookie;
var RemoveResponseCookie = chrome.declarativeWebRequest.RemoveResponseCookie; var RemoveResponseCookie = chrome.declarativeWebRequest.RemoveResponseCookie;
var headerName = 'Foo';
var headerValue = 'Bar';
// Constants as functions, not to be called until after runTests. // Constants as functions, not to be called until after runTests.
function getURLEchoUserAgent() { function getURLEchoUserAgent() {
...@@ -37,14 +39,8 @@ function getURLHttpSimple() { ...@@ -37,14 +39,8 @@ function getURLHttpSimple() {
return getServerURL("extensions/api_test/webrequest/simpleLoad/a.html"); return getServerURL("extensions/api_test/webrequest/simpleLoad/a.html");
} }
function getURLOfHTMLWithThirdParty() { function getURLSetHeader() {
// Returns the URL of a HTML document with a third-party resource. return getServerURL('set-header?' + headerName + ': ' + headerValue);
return getServerURL(
"extensions/api_test/webrequest/declarative/third-party.html");
}
function getURLSetCookie() {
return getServerURL('set-cookie?Foo=Bar');
} }
function getURLSetCookie2() { function getURLSetCookie2() {
...@@ -56,11 +52,6 @@ function getURLEchoCookie() { ...@@ -56,11 +52,6 @@ function getURLEchoCookie() {
return getServerURL('echoheader?Cookie'); return getServerURL('echoheader?Cookie');
} }
function getURLHttpXHRData() {
return getServerURL("extensions/api_test/webrequest/xhr/data.json",
"b.com");
}
runTests([ runTests([
function testSetRequestHeader() { function testSetRequestHeader() {
...@@ -90,21 +81,21 @@ runTests([ ...@@ -90,21 +81,21 @@ runTests([
expect(); // Used for initialization. expect(); // Used for initialization.
onRequest.addRules( onRequest.addRules(
[{conditions: [new RequestMatcher()], [{conditions: [new RequestMatcher()],
actions: [new RemoveRequestHeader({name: "user-AGENT"})] actions: [new RemoveRequestHeader({name: headerName})]
}], }],
function() { chrome.test.callbackPass(function() {
// Check the page content for our modified User-Agent string. var xhr = new XMLHttpRequest();
navigateAndWait(getURLEchoUserAgent(), function() { xhr.open('GET', getServerURL('echoheader?' + headerName));
chrome.test.listenOnce(chrome.extension.onRequest, function(request) { xhr.setRequestHeader(headerName, headerValue);
chrome.test.assertTrue(request.pass, "User-Agent was not removed."); xhr.onload = chrome.test.callbackPass(function() {
}); chrome.test.assertTrue(xhr.responseText.indexOf(headerValue) == -1,
chrome.tabs.executeScript(tabId, 'Header was not removed.');
{
code: "chrome.extension.sendRequest(" +
"{pass: document.body.innerText.indexOf('Mozilla') == -1});"
});
}); });
}); xhr.onerror = function() {
chrome.test.fail();
}
xhr.send();
}));
}, },
function testAddResponseHeader() { function testAddResponseHeader() {
...@@ -112,20 +103,20 @@ runTests([ ...@@ -112,20 +103,20 @@ runTests([
expect(); // Used for initialization. expect(); // Used for initialization.
onRequest.addRules( onRequest.addRules(
[{conditions: [new RequestMatcher()], [{conditions: [new RequestMatcher()],
actions: [new AddResponseHeader({name: "Set-Cookie", value: "Bar=baz"})] actions: [new AddResponseHeader({name: headerName, value: headerValue})]
}], }],
function() { chrome.test.callbackPass(function() {
navigateAndWait(getURLEchoUserAgent(), function() { var xhr = new XMLHttpRequest();
chrome.test.listenOnce(chrome.extension.onRequest, function(request) { xhr.open('GET', getServerURL('echo'));
chrome.test.assertTrue(request.pass, "Cookie was not added."); xhr.onload = chrome.test.callbackPass(function() {
}); chrome.test.assertTrue(xhr.getResponseHeader(headerName) == 'Bar',
chrome.tabs.executeScript(tabId, 'Header was not added.');
{
code: "chrome.extension.sendRequest(" +
"{pass: document.cookie.indexOf('Bar') != -1});"
});
}); });
}); xhr.onerror = function() {
chrome.test.fail();
}
xhr.send();
}));
}, },
function testRemoveResponseHeader() { function testRemoveResponseHeader() {
...@@ -133,21 +124,21 @@ runTests([ ...@@ -133,21 +124,21 @@ runTests([
expect(); // Used for initialization. expect(); // Used for initialization.
onRequest.addRules( onRequest.addRules(
[{conditions: [new RequestMatcher()], [{conditions: [new RequestMatcher()],
actions: [new RemoveResponseHeader({name: "Set-Cookie", actions: [new RemoveResponseHeader({name: headerName,
value: "FoO=bAR"})] value: 'Bar'})]
}], }],
function() { chrome.test.callbackPass(function() {
navigateAndWait(getURLSetCookie(), function() { var xhr = new XMLHttpRequest();
chrome.test.listenOnce(chrome.extension.onRequest, function(request) { xhr.open('GET', getURLSetHeader());
chrome.test.assertTrue(request.pass, "Cookie was not removed."); xhr.onload = chrome.test.callbackPass(function() {
}); chrome.test.assertTrue(xhr.getResponseHeader(headerName) == null,
chrome.tabs.executeScript(tabId, 'Header was not removed.');
{
code: "chrome.extension.sendRequest(" +
"{pass: document.cookie.indexOf('Foo') == -1});"
});
}); });
}); xhr.onerror = function() {
chrome.test.fail();
}
xhr.send();
}));
}, },
function testPriorities() { function testPriorities() {
...@@ -219,6 +210,13 @@ runTests([ ...@@ -219,6 +210,13 @@ runTests([
}, },
function testEditResponseCookies() { function testEditResponseCookies() {
// TODO(crbug.com/827582): Editing response cookies through
// declarativeWebRequest is not supported with the network service.
if (networkServiceState == 'enabled') {
chrome.test.succeed();
return;
}
ignoreUnexpected = true; ignoreUnexpected = true;
expect(); expect();
onRequest.addRules( onRequest.addRules(
......
...@@ -398,6 +398,9 @@ void WebRequestProxyingURLLoaderFactory::InProgressRequest:: ...@@ -398,6 +398,9 @@ void WebRequestProxyingURLLoaderFactory::InProgressRequest::
return; return;
} }
if (override_headers_)
current_response_.headers = override_headers_;
std::string redirect_location; std::string redirect_location;
if (override_headers_ && override_headers_->IsRedirect(&redirect_location)) { if (override_headers_ && override_headers_->IsRedirect(&redirect_location)) {
// The response headers may have been overridden by an |onHeadersReceived| // The response headers may have been overridden by an |onHeadersReceived|
...@@ -416,8 +419,6 @@ void WebRequestProxyingURLLoaderFactory::InProgressRequest:: ...@@ -416,8 +419,6 @@ void WebRequestProxyingURLLoaderFactory::InProgressRequest::
redirect_info.new_url = new_url; redirect_info.new_url = new_url;
redirect_info.new_site_for_cookies = new_url; redirect_info.new_site_for_cookies = new_url;
current_response_.headers = override_headers_;
// These will get re-bound when a new request is initiated after Restart() // These will get re-bound when a new request is initiated after Restart()
// below. // below.
proxied_client_binding_.Close(); proxied_client_binding_.Close();
......
...@@ -207,8 +207,6 @@ ...@@ -207,8 +207,6 @@
# http://crbug.com/721414 # http://crbug.com/721414
# TODO(rockot): add support for webRequest API. # TODO(rockot): add support for webRequest API.
-ExtensionWebRequestApiTest.WebRequestBlocking -ExtensionWebRequestApiTest.WebRequestBlocking
-ExtensionWebRequestApiTest.WebRequestDeclarative2
-ExtensionWebRequestApiTest.WebRequestDiceHeaderProtection
-ExtensionWebRequestApiTest.WebRequestTypes -ExtensionWebRequestApiTest.WebRequestTypes
# Needs synchronization to wait until after URLLoaderFactories are rebound. # Needs synchronization to wait until after URLLoaderFactories are rebound.
-DevToolsFrontendInWebRequestApiTest.HiddenRequests -DevToolsFrontendInWebRequestApiTest.HiddenRequests
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment