Add git cl format presubmit warning for extension and apps.
[chromium-blink-merge.git] / net / url_request / url_request_job_unittest.cc
blob99f43141d98fa60960758e2382931f473497851b
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
3 // found in the LICENSE file.
5 #include "net/url_request/url_request_job.h"
7 #include "net/base/request_priority.h"
8 #include "net/http/http_transaction_unittest.h"
9 #include "net/url_request/url_request_test_util.h"
10 #include "testing/gtest/include/gtest/gtest.h"
12 namespace net {
14 namespace {
16 // This is a header that signals the end of the data.
17 const char kGzipGata[] = "\x1f\x08b\x08\0\0\0\0\0\0\3\3\0\0\0\0\0\0\0\0";
19 void GZipServer(const HttpRequestInfo* request,
20 std::string* response_status,
21 std::string* response_headers,
22 std::string* response_data) {
23 response_data->assign(kGzipGata, sizeof(kGzipGata));
26 const MockTransaction kGZip_Transaction = {
27 "http://www.google.com/gzyp",
28 "GET",
29 base::Time(),
30 "",
31 LOAD_NORMAL,
32 "HTTP/1.1 200 OK",
33 "Cache-Control: max-age=10000\n"
34 "Content-Encoding: gzip\n"
35 "Content-Length: 30\n", // Intentionally wrong.
36 base::Time(),
37 "",
38 TEST_MODE_NORMAL,
39 &GZipServer,
44 const MockTransaction kRedirect_Transaction = {
45 "http://www.google.com/redirect",
46 "GET",
47 base::Time(),
48 "",
49 LOAD_NORMAL,
50 "HTTP/1.1 302 Found",
51 "Cache-Control: max-age=10000\n"
52 "Location: http://www.google.com/destination\n"
53 "Content-Length: 5\n",
54 base::Time(),
55 "hello",
56 TEST_MODE_NORMAL,
57 NULL,
62 } // namespace
64 TEST(URLRequestJob, TransactionNotifiedWhenDone) {
65 MockNetworkLayer network_layer;
66 TestURLRequestContext context;
67 context.set_http_transaction_factory(&network_layer);
69 TestDelegate d;
70 TestURLRequest req(
71 GURL(kGZip_Transaction.url), DEFAULT_PRIORITY, &d, &context);
72 AddMockTransaction(&kGZip_Transaction);
74 req.set_method("GET");
75 req.Start();
77 base::MessageLoop::current()->Run();
79 EXPECT_TRUE(network_layer.done_reading_called());
81 RemoveMockTransaction(&kGZip_Transaction);
84 TEST(URLRequestJob, SyncTransactionNotifiedWhenDone) {
85 MockNetworkLayer network_layer;
86 TestURLRequestContext context;
87 context.set_http_transaction_factory(&network_layer);
89 TestDelegate d;
90 TestURLRequest req(
91 GURL(kGZip_Transaction.url), DEFAULT_PRIORITY, &d, &context);
92 MockTransaction transaction(kGZip_Transaction);
93 transaction.test_mode = TEST_MODE_SYNC_ALL;
94 AddMockTransaction(&transaction);
96 req.set_method("GET");
97 req.Start();
99 base::MessageLoop::current()->Run();
101 EXPECT_TRUE(network_layer.done_reading_called());
103 RemoveMockTransaction(&transaction);
106 TEST(URLRequestJob, RedirectTransactionNotifiedWhenDone) {
107 MockNetworkLayer network_layer;
108 TestURLRequestContext context;
109 context.set_http_transaction_factory(&network_layer);
111 TestDelegate d;
112 TestURLRequest req(
113 GURL(kRedirect_Transaction.url), DEFAULT_PRIORITY, &d, &context);
114 AddMockTransaction(&kRedirect_Transaction);
116 req.set_method("GET");
117 req.Start();
119 base::MessageLoop::current()->Run();
121 EXPECT_TRUE(network_layer.done_reading_called());
123 RemoveMockTransaction(&kRedirect_Transaction);
126 } // namespace net