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,
IN_PROC_BROWSER_TEST_F(ExtensionWebRequestApiTest,
MAYBE_WebRequestDeclarative2) {
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_;
}
......
......@@ -27,6 +27,8 @@ var EditRequestCookie = chrome.declarativeWebRequest.EditRequestCookie;
var EditResponseCookie = chrome.declarativeWebRequest.EditResponseCookie;
var RemoveRequestCookie = chrome.declarativeWebRequest.RemoveRequestCookie;
var RemoveResponseCookie = chrome.declarativeWebRequest.RemoveResponseCookie;
var headerName = 'Foo';
var headerValue = 'Bar';
// Constants as functions, not to be called until after runTests.
function getURLEchoUserAgent() {
......@@ -37,14 +39,8 @@ function getURLHttpSimple() {
return getServerURL("extensions/api_test/webrequest/simpleLoad/a.html");
}
function getURLOfHTMLWithThirdParty() {
// Returns the URL of a HTML document with a third-party resource.
return getServerURL(
"extensions/api_test/webrequest/declarative/third-party.html");
}
function getURLSetCookie() {
return getServerURL('set-cookie?Foo=Bar');
function getURLSetHeader() {
return getServerURL('set-header?' + headerName + ': ' + headerValue);
}
function getURLSetCookie2() {
......@@ -56,11 +52,6 @@ function getURLEchoCookie() {
return getServerURL('echoheader?Cookie');
}
function getURLHttpXHRData() {
return getServerURL("extensions/api_test/webrequest/xhr/data.json",
"b.com");
}
runTests([
function testSetRequestHeader() {
......@@ -90,21 +81,21 @@ runTests([
expect(); // Used for initialization.
onRequest.addRules(
[{conditions: [new RequestMatcher()],
actions: [new RemoveRequestHeader({name: "user-AGENT"})]
actions: [new RemoveRequestHeader({name: headerName})]
}],
function() {
// Check the page content for our modified User-Agent string.
navigateAndWait(getURLEchoUserAgent(), function() {
chrome.test.listenOnce(chrome.extension.onRequest, function(request) {
chrome.test.assertTrue(request.pass, "User-Agent was not removed.");
});
chrome.tabs.executeScript(tabId,
{
code: "chrome.extension.sendRequest(" +
"{pass: document.body.innerText.indexOf('Mozilla') == -1});"
});
});
chrome.test.callbackPass(function() {
var xhr = new XMLHttpRequest();
xhr.open('GET', getServerURL('echoheader?' + headerName));
xhr.setRequestHeader(headerName, headerValue);
xhr.onload = chrome.test.callbackPass(function() {
chrome.test.assertTrue(xhr.responseText.indexOf(headerValue) == -1,
'Header was not removed.');
});
xhr.onerror = function() {
chrome.test.fail();
}
xhr.send();
}));
},
function testAddResponseHeader() {
......@@ -112,20 +103,20 @@ runTests([
expect(); // Used for initialization.
onRequest.addRules(
[{conditions: [new RequestMatcher()],
actions: [new AddResponseHeader({name: "Set-Cookie", value: "Bar=baz"})]
actions: [new AddResponseHeader({name: headerName, value: headerValue})]
}],
function() {
navigateAndWait(getURLEchoUserAgent(), function() {
chrome.test.listenOnce(chrome.extension.onRequest, function(request) {
chrome.test.assertTrue(request.pass, "Cookie was not added.");
});
chrome.tabs.executeScript(tabId,
{
code: "chrome.extension.sendRequest(" +
"{pass: document.cookie.indexOf('Bar') != -1});"
});
});
chrome.test.callbackPass(function() {
var xhr = new XMLHttpRequest();
xhr.open('GET', getServerURL('echo'));
xhr.onload = chrome.test.callbackPass(function() {
chrome.test.assertTrue(xhr.getResponseHeader(headerName) == 'Bar',
'Header was not added.');
});
xhr.onerror = function() {
chrome.test.fail();
}
xhr.send();
}));
},
function testRemoveResponseHeader() {
......@@ -133,21 +124,21 @@ runTests([
expect(); // Used for initialization.
onRequest.addRules(
[{conditions: [new RequestMatcher()],
actions: [new RemoveResponseHeader({name: "Set-Cookie",
value: "FoO=bAR"})]
actions: [new RemoveResponseHeader({name: headerName,
value: 'Bar'})]
}],
function() {
navigateAndWait(getURLSetCookie(), function() {
chrome.test.listenOnce(chrome.extension.onRequest, function(request) {
chrome.test.assertTrue(request.pass, "Cookie was not removed.");
});
chrome.tabs.executeScript(tabId,
{
code: "chrome.extension.sendRequest(" +
"{pass: document.cookie.indexOf('Foo') == -1});"
});
});
chrome.test.callbackPass(function() {
var xhr = new XMLHttpRequest();
xhr.open('GET', getURLSetHeader());
xhr.onload = chrome.test.callbackPass(function() {
chrome.test.assertTrue(xhr.getResponseHeader(headerName) == null,
'Header was not removed.');
});
xhr.onerror = function() {
chrome.test.fail();
}
xhr.send();
}));
},
function testPriorities() {
......@@ -219,6 +210,13 @@ runTests([
},
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;
expect();
onRequest.addRules(
......
......@@ -398,6 +398,9 @@ void WebRequestProxyingURLLoaderFactory::InProgressRequest::
return;
}
if (override_headers_)
current_response_.headers = override_headers_;
std::string redirect_location;
if (override_headers_ && override_headers_->IsRedirect(&redirect_location)) {
// The response headers may have been overridden by an |onHeadersReceived|
......@@ -416,8 +419,6 @@ void WebRequestProxyingURLLoaderFactory::InProgressRequest::
redirect_info.new_url = 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()
// below.
proxied_client_binding_.Close();
......
......@@ -207,8 +207,6 @@
# http://crbug.com/721414
# TODO(rockot): add support for webRequest API.
-ExtensionWebRequestApiTest.WebRequestBlocking
-ExtensionWebRequestApiTest.WebRequestDeclarative2
-ExtensionWebRequestApiTest.WebRequestDiceHeaderProtection
-ExtensionWebRequestApiTest.WebRequestTypes
# Needs synchronization to wait until after URLLoaderFactories are rebound.
-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