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

Side by Side Diff: net/http/http_network_layer_unittest.cc

Issue 12886022: Implement offline mode behind a flag (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Setup OfflinePolicy for all started requests. Created 7 years, 8 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « net/http/http_cache_unittest.cc ('k') | net/http/http_network_transaction.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "net/http/http_network_layer.h" 5 #include "net/http/http_network_layer.h"
6 6
7 #include "net/base/net_log.h" 7 #include "net/base/net_log.h"
8 #include "net/cert/mock_cert_verifier.h" 8 #include "net/cert/mock_cert_verifier.h"
9 #include "net/dns/mock_host_resolver.h" 9 #include "net/dns/mock_host_resolver.h"
10 #include "net/http/http_network_session.h" 10 #include "net/http/http_network_session.h"
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 } 81 }
82 82
83 TEST_F(HttpNetworkLayerTest, GET) { 83 TEST_F(HttpNetworkLayerTest, GET) {
84 MockRead data_reads[] = { 84 MockRead data_reads[] = {
85 MockRead("HTTP/1.0 200 OK\r\n\r\n"), 85 MockRead("HTTP/1.0 200 OK\r\n\r\n"),
86 MockRead("hello world"), 86 MockRead("hello world"),
87 MockRead(SYNCHRONOUS, OK), 87 MockRead(SYNCHRONOUS, OK),
88 }; 88 };
89 MockWrite data_writes[] = { 89 MockWrite data_writes[] = {
90 MockWrite("GET / HTTP/1.1\r\n" 90 MockWrite("GET / HTTP/1.1\r\n"
91 "Host: www.google.com\r\n" 91 "Host: www.google.com\r\n"
92 "Connection: keep-alive\r\n" 92 "Connection: keep-alive\r\n"
93 "User-Agent: Foo/1.0\r\n\r\n"), 93 "User-Agent: Foo/1.0\r\n\r\n"),
94 }; 94 };
95 StaticSocketDataProvider data(data_reads, arraysize(data_reads), 95 StaticSocketDataProvider data(data_reads, arraysize(data_reads),
96 data_writes, arraysize(data_writes)); 96 data_writes, arraysize(data_writes));
97 mock_socket_factory_.AddSocketDataProvider(&data); 97 mock_socket_factory_.AddSocketDataProvider(&data);
98 98
99 TestCompletionCallback callback; 99 TestCompletionCallback callback;
100 100
101 HttpRequestInfo request_info; 101 HttpRequestInfo request_info;
102 request_info.url = GURL("http://www.google.com/"); 102 request_info.url = GURL("http://www.google.com/");
103 request_info.method = "GET"; 103 request_info.method = "GET";
104 request_info.extra_headers.SetHeader(HttpRequestHeaders::kUserAgent, 104 request_info.extra_headers.SetHeader(HttpRequestHeaders::kUserAgent,
105 "Foo/1.0"); 105 "Foo/1.0");
106 request_info.load_flags = LOAD_NORMAL; 106 request_info.load_flags = LOAD_NORMAL;
107 107
108 scoped_ptr<HttpTransaction> trans; 108 scoped_ptr<HttpTransaction> trans;
109 int rv = factory_->CreateTransaction(DEFAULT_PRIORITY, &trans, NULL); 109 int rv = factory_->CreateTransaction(DEFAULT_PRIORITY, &trans, NULL);
110 EXPECT_EQ(OK, rv); 110 EXPECT_EQ(OK, rv);
111 111
112 rv = trans->Start(&request_info, callback.callback(), BoundNetLog()); 112 rv = trans->Start(&request_info, callback.callback(), BoundNetLog());
113 if (rv == ERR_IO_PENDING) 113 rv = callback.GetResult(rv);
114 rv = callback.WaitForResult();
115 ASSERT_EQ(OK, rv); 114 ASSERT_EQ(OK, rv);
116 115
117 std::string contents; 116 std::string contents;
118 rv = ReadTransaction(trans.get(), &contents); 117 rv = ReadTransaction(trans.get(), &contents);
119 EXPECT_EQ(OK, rv); 118 EXPECT_EQ(OK, rv);
120 EXPECT_EQ("hello world", contents); 119 EXPECT_EQ("hello world", contents);
121 } 120 }
122 121
123 TEST_F(HttpNetworkLayerTest, ServerFallback) { 122 TEST_F(HttpNetworkLayerTest, ServerFallback) {
124 // Verify that a Connection: Proxy-Bypass header induces proxy fallback to 123 // Verify that a Connection: Proxy-Bypass header induces proxy fallback to
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
283 // We should have read the original page data. 282 // We should have read the original page data.
284 std::string contents; 283 std::string contents;
285 rv = ReadTransaction(trans.get(), &contents); 284 rv = ReadTransaction(trans.get(), &contents);
286 EXPECT_EQ(OK, rv); 285 EXPECT_EQ(OK, rv);
287 EXPECT_EQ("Bypass message", contents); 286 EXPECT_EQ("Bypass message", contents);
288 287
289 // We should have no entries in our bad proxy list. 288 // We should have no entries in our bad proxy list.
290 ASSERT_EQ(0u, proxy_service_->proxy_retry_info().size()); 289 ASSERT_EQ(0u, proxy_service_->proxy_retry_info().size());
291 } 290 }
292 291
292 TEST_F(HttpNetworkLayerTest, NetworkVerified) {
293 MockRead data_reads[] = {
294 MockRead("HTTP/1.0 200 OK\r\n\r\n"),
295 MockRead("hello world"),
296 MockRead(SYNCHRONOUS, OK),
297 };
298 MockWrite data_writes[] = {
299 MockWrite("GET / HTTP/1.1\r\n"
300 "Host: www.google.com\r\n"
301 "Connection: keep-alive\r\n"
302 "User-Agent: Foo/1.0\r\n\r\n"),
303 };
304 StaticSocketDataProvider data(data_reads, arraysize(data_reads),
305 data_writes, arraysize(data_writes));
306 mock_socket_factory_.AddSocketDataProvider(&data);
307
308 TestCompletionCallback callback;
309
310 HttpRequestInfo request_info;
311 request_info.url = GURL("http://www.google.com/");
312 request_info.method = "GET";
313 request_info.extra_headers.SetHeader(HttpRequestHeaders::kUserAgent,
314 "Foo/1.0");
315 request_info.load_flags = LOAD_NORMAL;
316
317 scoped_ptr<HttpTransaction> trans;
318 int rv = factory_->CreateTransaction(DEFAULT_PRIORITY, &trans, NULL);
319 EXPECT_EQ(OK, rv);
320
321 rv = trans->Start(&request_info, callback.callback(), BoundNetLog());
322 ASSERT_EQ(OK, callback.GetResult(rv));
323
324 EXPECT_TRUE(trans->GetResponseInfo()->network_accessed);
325 }
326
327 TEST_F(HttpNetworkLayerTest, NetworkUnVerified) {
328 MockRead data_reads[] = {
329 MockRead(ASYNC, ERR_CONNECTION_RESET),
330 };
331 MockWrite data_writes[] = {
332 MockWrite("GET / HTTP/1.1\r\n"
333 "Host: www.google.com\r\n"
334 "Connection: keep-alive\r\n"
335 "User-Agent: Foo/1.0\r\n\r\n"),
336 };
337 StaticSocketDataProvider data(data_reads, arraysize(data_reads),
338 data_writes, arraysize(data_writes));
339 mock_socket_factory_.AddSocketDataProvider(&data);
340
341 TestCompletionCallback callback;
342
343 HttpRequestInfo request_info;
344 request_info.url = GURL("http://www.google.com/");
345 request_info.method = "GET";
346 request_info.extra_headers.SetHeader(HttpRequestHeaders::kUserAgent,
347 "Foo/1.0");
348 request_info.load_flags = LOAD_NORMAL;
349
350 scoped_ptr<HttpTransaction> trans;
351 int rv = factory_->CreateTransaction(DEFAULT_PRIORITY, &trans, NULL);
352 EXPECT_EQ(OK, rv);
353
354 rv = trans->Start(&request_info, callback.callback(), BoundNetLog());
355 ASSERT_EQ(ERR_CONNECTION_RESET, callback.GetResult(rv));
356
357 // If the response info is null, that means that any consumer won't
358 // see the network accessed bit set.
359 EXPECT_EQ(NULL, trans->GetResponseInfo());
360 }
361
293 } // namespace 362 } // namespace
294 363
295 } // namespace net 364 } // namespace net
OLDNEW
« no previous file with comments | « net/http/http_cache_unittest.cc ('k') | net/http/http_network_transaction.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698