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

Unified Diff: content/browser/loader/resource_dispatcher_host_unittest.cc

Issue 1271733002: [2/3 chromium] Support redirect option of Request and "opaqueredirect" response type. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: incorporated mmenke's comment Created 5 years, 4 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: content/browser/loader/resource_dispatcher_host_unittest.cc
diff --git a/content/browser/loader/resource_dispatcher_host_unittest.cc b/content/browser/loader/resource_dispatcher_host_unittest.cc
index 80d78c508282411331ebbcb5fe9db93c24250cc0..47a2dbdb83f1f979d248fb104f63f473cd0396d3 100644
--- a/content/browser/loader/resource_dispatcher_host_unittest.cc
+++ b/content/browser/loader/resource_dispatcher_host_unittest.cc
@@ -946,6 +946,12 @@ class ResourceDispatcherHostTest : public testing::Test,
void MakeWebContentsAssociatedTestRequest(int request_id, const GURL& url);
+ void MakeTestFetchRequestWithRedirectMode(
+ int render_view_id,
+ int request_id,
+ const GURL& url,
+ FetchRedirectMode fetch_redirect_mode);
+
void CancelRequest(int request_id);
void RendererCancelRequest(int request_id) {
ResourceMessageFilter* old_filter = SetFilter(filter_.get());
@@ -1072,6 +1078,19 @@ void ResourceDispatcherHostTest::MakeWebContentsAssociatedTestRequest(
KickOffRequest();
}
+void ResourceDispatcherHostTest::MakeTestFetchRequestWithRedirectMode(
+ int render_view_id,
+ int request_id,
+ const GURL& url,
+ FetchRedirectMode fetch_redirect_mode) {
+ ResourceHostMsg_Request request =
+ CreateResourceRequest("GET", RESOURCE_TYPE_SUB_RESOURCE, url);
+ request.fetch_redirect_mode = fetch_redirect_mode;
+ ResourceHostMsg_RequestResource msg(render_view_id, request_id, request);
+ host_.OnMessageReceived(msg, filter_.get());
+ KickOffRequest();
+}
+
void ResourceDispatcherHostTest::CancelRequest(int request_id) {
host_.CancelRequest(filter_->child_id(), request_id);
}
@@ -1183,7 +1202,6 @@ void CheckSuccessfulRedirect(const std::vector<IPC::Message>& messages,
}
void CheckFailedRequest(const std::vector<IPC::Message>& messages,
- const std::string& reference_data,
int expected_error) {
ASSERT_LT(0U, messages.size());
ASSERT_GE(2U, messages.size());
@@ -2019,8 +2037,7 @@ TEST_F(ResourceDispatcherHostTest, TooMuchOutstandingRequestsMemory) {
for (int i = 0; i < 2; ++i) {
// Should have sent a single RequestComplete message.
int index = kMaxRequests + i;
- CheckFailedRequest(msgs[index], net::URLRequestTestJob::test_data_2(),
- net::ERR_INSUFFICIENT_RESOURCES);
+ CheckFailedRequest(msgs[index], net::ERR_INSUFFICIENT_RESOURCES);
}
// The final 2 requests should have succeeded.
@@ -2086,12 +2103,10 @@ TEST_F(ResourceDispatcherHostTest, TooManyOutstandingRequests) {
CheckSuccessfulRequest(msgs[i], net::URLRequestTestJob::test_data_2());
CheckFailedRequest(msgs[kMaxRequestsPerProcess + 0],
- net::URLRequestTestJob::test_data_2(),
net::ERR_INSUFFICIENT_RESOURCES);
CheckSuccessfulRequest(msgs[kMaxRequestsPerProcess + 1],
net::URLRequestTestJob::test_data_2());
CheckFailedRequest(msgs[kMaxRequestsPerProcess + 2],
- net::URLRequestTestJob::test_data_2(),
net::ERR_INSUFFICIENT_RESOURCES);
}
@@ -3329,6 +3344,49 @@ TEST_F(ResourceDispatcherHostTest, TransferRequestRedirected) {
web_contents_observer_->resource_request_redirect_count());
}
+// Confirm that the redirect response is handled as an error when the request's
+// redirect mode is "error".
+TEST_F(ResourceDispatcherHostTest, FetchRedirectModeError) {
+ MakeTestFetchRequestWithRedirectMode(
+ 0, 1, net::URLRequestTestJob::test_url_redirect_to_url_2(),
+ FETCH_REDIRECT_MODE_ERROR);
+
+ // flush all the pending requests
+ while (net::URLRequestTestJob::ProcessOnePendingMessage()) {}
+ base::MessageLoop::current()->RunUntilIdle();
+
+ // sorts out all the messages we saw by request
+ ResourceIPCAccumulator::ClassifiedMessages msgs;
+ accum_.GetClassifiedMessages(&msgs);
+
+ ASSERT_EQ(1U, msgs.size());
+ CheckFailedRequest(msgs[0], net::ERR_ABORTED);
+}
+
+// Confirm that the redirect response is not followed when the request's
+// redirect mode is "manual".
+TEST_F(ResourceDispatcherHostTest, FetchRedirectModeManual) {
+ MakeTestFetchRequestWithRedirectMode(
+ 0, 1, net::URLRequestTestJob::test_url_redirect_to_url_2(),
+ FETCH_REDIRECT_MODE_MANUAL);
+
+ // flush all the pending requests
+ while (net::URLRequestTestJob::ProcessOnePendingMessage()) {}
+ base::MessageLoop::current()->RunUntilIdle();
+
+ // sorts out all the messages we saw by request
+ ResourceIPCAccumulator::ClassifiedMessages msgs;
+ accum_.GetClassifiedMessages(&msgs);
+
+ ASSERT_EQ(1U, msgs.size());
+ ASSERT_EQ(2U, msgs[0].size());
+ ResourceResponseHead response_head;
+ GetResponseHead(msgs[0], &response_head);
+ ASSERT_TRUE(response_head.headers);
+ ASSERT_EQ(302, response_head.headers->response_code());
+ CheckRequestCompleteErrorCode(msgs[0][1], net::OK);
+}
+
net::URLRequestJob* TestURLRequestJobFactory::MaybeCreateJobWithProtocolHandler(
const std::string& scheme,
net::URLRequest* request,

Powered by Google App Engine
This is Rietveld 408576698