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

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: Added tests. 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
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/mock_cert_verifier.h" 7 #include "net/base/mock_cert_verifier.h"
8 #include "net/base/net_log.h" 8 #include "net/base/net_log.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 272 matching lines...) Expand 10 before | Expand all | Expand 10 after
283 // We should have read the original page data. 283 // We should have read the original page data.
284 std::string contents; 284 std::string contents;
285 rv = ReadTransaction(trans.get(), &contents); 285 rv = ReadTransaction(trans.get(), &contents);
286 EXPECT_EQ(OK, rv); 286 EXPECT_EQ(OK, rv);
287 EXPECT_EQ("Bypass message", contents); 287 EXPECT_EQ("Bypass message", contents);
288 288
289 // We should have no entries in our bad proxy list. 289 // We should have no entries in our bad proxy list.
290 ASSERT_EQ(0u, proxy_service_->proxy_retry_info().size()); 290 ASSERT_EQ(0u, proxy_service_->proxy_retry_info().size());
291 } 291 }
292 292
293 TEST_F(HttpNetworkLayerTest, ConfirmNetworkVerified) {
rvargas (doing something else) 2013/04/08 19:11:52 nit: remove "Confirm" from the name of both tests?
Randy Smith (Not in Mondays) 2013/04/08 21:03:11 Done.
294 MockRead data_reads[] = {
295 MockRead("HTTP/1.0 200 OK\r\n\r\n"),
296 MockRead("hello world"),
297 MockRead(SYNCHRONOUS, OK),
298 };
299 MockWrite data_writes[] = {
300 MockWrite("GET / HTTP/1.1\r\n"
301 "Host: www.google.com\r\n"
rvargas (doing something else) 2013/04/08 19:11:52 nit: we usually don't extra indent when splitting
Randy Smith (Not in Mondays) 2013/04/08 21:03:11 Ok. I'll fix the GET test as well (which is where
302 "Connection: keep-alive\r\n"
303 "User-Agent: Foo/1.0\r\n\r\n"),
304 };
305 StaticSocketDataProvider data(data_reads, arraysize(data_reads),
306 data_writes, arraysize(data_writes));
rvargas (doing something else) 2013/04/08 19:11:52 nit: indent four less spaces
Randy Smith (Not in Mondays) 2013/04/08 21:03:11 Done (in GET test as well).
307 mock_socket_factory_.AddSocketDataProvider(&data);
308
309 TestCompletionCallback callback;
310
311 HttpRequestInfo request_info;
312 request_info.url = GURL("http://www.google.com/");
313 request_info.method = "GET";
314 request_info.extra_headers.SetHeader(HttpRequestHeaders::kUserAgent,
315 "Foo/1.0");
316 request_info.load_flags = LOAD_NORMAL;
317
318 scoped_ptr<HttpTransaction> trans;
319 int rv = factory_->CreateTransaction(DEFAULT_PRIORITY, &trans, NULL);
320 EXPECT_EQ(OK, rv);
321
322 rv = trans->Start(&request_info, callback.callback(), BoundNetLog());
323 if (rv == ERR_IO_PENDING)
324 rv = callback.WaitForResult();
rvargas (doing something else) 2013/04/08 19:11:52 nit: callback.GetResult(rv)
Randy Smith (Not in Mondays) 2013/04/08 21:03:11 Done (GET as well).
325 ASSERT_EQ(OK, rv);
326
327 EXPECT_TRUE(trans->GetResponseInfo()->network_accessed);
328 }
329
330 TEST_F(HttpNetworkLayerTest, ConfirmNetworkUnVerified) {
331 MockRead data_reads[] = {
332 MockRead(ASYNC, ERR_CONNECTION_RESET),
333 };
334 MockWrite data_writes[] = {
335 MockWrite("GET / HTTP/1.1\r\n"
336 "Host: www.google.com\r\n"
337 "Connection: keep-alive\r\n"
338 "User-Agent: Foo/1.0\r\n\r\n"),
339 };
340 StaticSocketDataProvider data(data_reads, arraysize(data_reads),
341 data_writes, arraysize(data_writes));
342 mock_socket_factory_.AddSocketDataProvider(&data);
343
344 TestCompletionCallback callback;
345
346 HttpRequestInfo request_info;
347 request_info.url = GURL("http://www.google.com/");
348 request_info.method = "GET";
349 request_info.extra_headers.SetHeader(HttpRequestHeaders::kUserAgent,
350 "Foo/1.0");
351 request_info.load_flags = LOAD_NORMAL;
352
353 scoped_ptr<HttpTransaction> trans;
354 int rv = factory_->CreateTransaction(DEFAULT_PRIORITY, &trans, NULL);
355 EXPECT_EQ(OK, rv);
356
357 rv = trans->Start(&request_info, callback.callback(), BoundNetLog());
358 if (rv == ERR_IO_PENDING)
359 rv = callback.WaitForResult();
360 ASSERT_EQ(ERR_CONNECTION_RESET, rv);
361
362 // If the response info is null, that means that any consumer won't
363 // see the network accessed bit set.
364 EXPECT_EQ(NULL, trans->GetResponseInfo());
365 }
366
293 } // namespace 367 } // namespace
294 368
295 } // namespace net 369 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698