OLD | NEW |
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/url_request/url_request_job.h" | 5 #include "net/url_request/url_request_job.h" |
6 | 6 |
7 #include "net/http/http_transaction_unittest.h" | 7 #include "net/http/http_transaction_unittest.h" |
8 #include "net/url_request/url_request_test_util.h" | 8 #include "net/url_request/url_request_test_util.h" |
9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
10 | 10 |
(...skipping 19 matching lines...) Expand all Loading... |
30 "Content-Encoding: gzip\n" | 30 "Content-Encoding: gzip\n" |
31 "Content-Length: 30\n", // Intentionally wrong. | 31 "Content-Length: 30\n", // Intentionally wrong. |
32 base::Time(), | 32 base::Time(), |
33 "", | 33 "", |
34 TEST_MODE_NORMAL, | 34 TEST_MODE_NORMAL, |
35 &GZipServer, | 35 &GZipServer, |
36 0, | 36 0, |
37 net::OK | 37 net::OK |
38 }; | 38 }; |
39 | 39 |
| 40 const MockTransaction kRedirect_Transaction = { |
| 41 "http://www.google.com/redirect", |
| 42 "GET", |
| 43 base::Time(), |
| 44 "", |
| 45 net::LOAD_NORMAL, |
| 46 "HTTP/1.1 302 Found", |
| 47 "Cache-Control: max-age=10000\n" |
| 48 "Location: http://www.google.com/destination\n" |
| 49 "Content-Length: 5\n", |
| 50 base::Time(), |
| 51 "hello", |
| 52 TEST_MODE_NORMAL, |
| 53 NULL, |
| 54 0, |
| 55 net::OK |
| 56 }; |
| 57 |
40 } // namespace | 58 } // namespace |
41 | 59 |
42 TEST(URLRequestJob, TransactionNotifiedWhenDone) { | 60 TEST(URLRequestJob, TransactionNotifiedWhenDone) { |
43 MockNetworkLayer network_layer; | 61 MockNetworkLayer network_layer; |
44 net::TestURLRequestContext context; | 62 net::TestURLRequestContext context; |
45 context.set_http_transaction_factory(&network_layer); | 63 context.set_http_transaction_factory(&network_layer); |
46 | 64 |
47 net::TestDelegate d; | 65 net::TestDelegate d; |
48 net::TestURLRequest req(GURL(kGZip_Transaction.url), &d, &context, NULL); | 66 net::TestURLRequest req(GURL(kGZip_Transaction.url), &d, &context, NULL); |
49 AddMockTransaction(&kGZip_Transaction); | 67 AddMockTransaction(&kGZip_Transaction); |
(...skipping 21 matching lines...) Expand all Loading... |
71 | 89 |
72 req.set_method("GET"); | 90 req.set_method("GET"); |
73 req.Start(); | 91 req.Start(); |
74 | 92 |
75 base::MessageLoop::current()->Run(); | 93 base::MessageLoop::current()->Run(); |
76 | 94 |
77 EXPECT_TRUE(network_layer.done_reading_called()); | 95 EXPECT_TRUE(network_layer.done_reading_called()); |
78 | 96 |
79 RemoveMockTransaction(&transaction); | 97 RemoveMockTransaction(&transaction); |
80 } | 98 } |
| 99 |
| 100 TEST(URLRequestJob, RedirectTransactionNotifiedWhenDone) { |
| 101 MockNetworkLayer network_layer; |
| 102 net::TestURLRequestContext context; |
| 103 context.set_http_transaction_factory(&network_layer); |
| 104 |
| 105 net::TestDelegate d; |
| 106 net::TestURLRequest req(GURL(kRedirect_Transaction.url), &d, &context, NULL); |
| 107 AddMockTransaction(&kRedirect_Transaction); |
| 108 |
| 109 req.set_method("GET"); |
| 110 req.Start(); |
| 111 |
| 112 base::MessageLoop::current()->Run(); |
| 113 |
| 114 EXPECT_TRUE(network_layer.done_reading_called()); |
| 115 |
| 116 RemoveMockTransaction(&kRedirect_Transaction); |
| 117 } |
OLD | NEW |