| 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 "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
| 8 #include "base/run_loop.h" | 8 #include "base/run_loop.h" |
| 9 #include "net/base/request_priority.h" | 9 #include "net/base/request_priority.h" |
| 10 #include "net/http/http_transaction_test_util.h" | 10 #include "net/http/http_transaction_test_util.h" |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 }; | 73 }; |
| 74 | 74 |
| 75 } // namespace | 75 } // namespace |
| 76 | 76 |
| 77 TEST(URLRequestJob, TransactionNotifiedWhenDone) { | 77 TEST(URLRequestJob, TransactionNotifiedWhenDone) { |
| 78 MockNetworkLayer network_layer; | 78 MockNetworkLayer network_layer; |
| 79 TestURLRequestContext context; | 79 TestURLRequestContext context; |
| 80 context.set_http_transaction_factory(&network_layer); | 80 context.set_http_transaction_factory(&network_layer); |
| 81 | 81 |
| 82 TestDelegate d; | 82 TestDelegate d; |
| 83 scoped_ptr<URLRequest> req(context.CreateRequest( | 83 scoped_ptr<URLRequest> req( |
| 84 GURL(kGZip_Transaction.url), DEFAULT_PRIORITY, &d, NULL)); | 84 context.CreateRequest(GURL(kGZip_Transaction.url), DEFAULT_PRIORITY, &d)); |
| 85 AddMockTransaction(&kGZip_Transaction); | 85 AddMockTransaction(&kGZip_Transaction); |
| 86 | 86 |
| 87 req->set_method("GET"); | 87 req->set_method("GET"); |
| 88 req->Start(); | 88 req->Start(); |
| 89 | 89 |
| 90 base::MessageLoop::current()->Run(); | 90 base::MessageLoop::current()->Run(); |
| 91 | 91 |
| 92 EXPECT_TRUE(network_layer.done_reading_called()); | 92 EXPECT_TRUE(network_layer.done_reading_called()); |
| 93 | 93 |
| 94 RemoveMockTransaction(&kGZip_Transaction); | 94 RemoveMockTransaction(&kGZip_Transaction); |
| 95 } | 95 } |
| 96 | 96 |
| 97 TEST(URLRequestJob, SyncTransactionNotifiedWhenDone) { | 97 TEST(URLRequestJob, SyncTransactionNotifiedWhenDone) { |
| 98 MockNetworkLayer network_layer; | 98 MockNetworkLayer network_layer; |
| 99 TestURLRequestContext context; | 99 TestURLRequestContext context; |
| 100 context.set_http_transaction_factory(&network_layer); | 100 context.set_http_transaction_factory(&network_layer); |
| 101 | 101 |
| 102 TestDelegate d; | 102 TestDelegate d; |
| 103 scoped_ptr<URLRequest> req(context.CreateRequest( | 103 scoped_ptr<URLRequest> req( |
| 104 GURL(kGZip_Transaction.url), DEFAULT_PRIORITY, &d, NULL)); | 104 context.CreateRequest(GURL(kGZip_Transaction.url), DEFAULT_PRIORITY, &d)); |
| 105 MockTransaction transaction(kGZip_Transaction); | 105 MockTransaction transaction(kGZip_Transaction); |
| 106 transaction.test_mode = TEST_MODE_SYNC_ALL; | 106 transaction.test_mode = TEST_MODE_SYNC_ALL; |
| 107 AddMockTransaction(&transaction); | 107 AddMockTransaction(&transaction); |
| 108 | 108 |
| 109 req->set_method("GET"); | 109 req->set_method("GET"); |
| 110 req->Start(); | 110 req->Start(); |
| 111 | 111 |
| 112 base::RunLoop().Run(); | 112 base::RunLoop().Run(); |
| 113 | 113 |
| 114 EXPECT_TRUE(network_layer.done_reading_called()); | 114 EXPECT_TRUE(network_layer.done_reading_called()); |
| 115 | 115 |
| 116 RemoveMockTransaction(&transaction); | 116 RemoveMockTransaction(&transaction); |
| 117 } | 117 } |
| 118 | 118 |
| 119 // Tests processing a large gzip header one byte at a time. | 119 // Tests processing a large gzip header one byte at a time. |
| 120 TEST(URLRequestJob, SyncSlowTransaction) { | 120 TEST(URLRequestJob, SyncSlowTransaction) { |
| 121 MockNetworkLayer network_layer; | 121 MockNetworkLayer network_layer; |
| 122 TestURLRequestContext context; | 122 TestURLRequestContext context; |
| 123 context.set_http_transaction_factory(&network_layer); | 123 context.set_http_transaction_factory(&network_layer); |
| 124 | 124 |
| 125 TestDelegate d; | 125 TestDelegate d; |
| 126 scoped_ptr<URLRequest> req(context.CreateRequest( | 126 scoped_ptr<URLRequest> req( |
| 127 GURL(kGZip_Transaction.url), DEFAULT_PRIORITY, &d, NULL)); | 127 context.CreateRequest(GURL(kGZip_Transaction.url), DEFAULT_PRIORITY, &d)); |
| 128 MockTransaction transaction(kGZip_Transaction); | 128 MockTransaction transaction(kGZip_Transaction); |
| 129 transaction.test_mode = TEST_MODE_SYNC_ALL | TEST_MODE_SLOW_READ; | 129 transaction.test_mode = TEST_MODE_SYNC_ALL | TEST_MODE_SLOW_READ; |
| 130 transaction.handler = &BigGZipServer; | 130 transaction.handler = &BigGZipServer; |
| 131 AddMockTransaction(&transaction); | 131 AddMockTransaction(&transaction); |
| 132 | 132 |
| 133 req->set_method("GET"); | 133 req->set_method("GET"); |
| 134 req->Start(); | 134 req->Start(); |
| 135 | 135 |
| 136 base::RunLoop().Run(); | 136 base::RunLoop().Run(); |
| 137 | 137 |
| 138 EXPECT_TRUE(network_layer.done_reading_called()); | 138 EXPECT_TRUE(network_layer.done_reading_called()); |
| 139 | 139 |
| 140 RemoveMockTransaction(&transaction); | 140 RemoveMockTransaction(&transaction); |
| 141 } | 141 } |
| 142 | 142 |
| 143 TEST(URLRequestJob, RedirectTransactionNotifiedWhenDone) { | 143 TEST(URLRequestJob, RedirectTransactionNotifiedWhenDone) { |
| 144 MockNetworkLayer network_layer; | 144 MockNetworkLayer network_layer; |
| 145 TestURLRequestContext context; | 145 TestURLRequestContext context; |
| 146 context.set_http_transaction_factory(&network_layer); | 146 context.set_http_transaction_factory(&network_layer); |
| 147 | 147 |
| 148 TestDelegate d; | 148 TestDelegate d; |
| 149 scoped_ptr<URLRequest> req(context.CreateRequest( | 149 scoped_ptr<URLRequest> req(context.CreateRequest( |
| 150 GURL(kRedirect_Transaction.url), DEFAULT_PRIORITY, &d, NULL)); | 150 GURL(kRedirect_Transaction.url), DEFAULT_PRIORITY, &d)); |
| 151 AddMockTransaction(&kRedirect_Transaction); | 151 AddMockTransaction(&kRedirect_Transaction); |
| 152 | 152 |
| 153 req->set_method("GET"); | 153 req->set_method("GET"); |
| 154 req->Start(); | 154 req->Start(); |
| 155 | 155 |
| 156 base::RunLoop().Run(); | 156 base::RunLoop().Run(); |
| 157 | 157 |
| 158 EXPECT_TRUE(network_layer.done_reading_called()); | 158 EXPECT_TRUE(network_layer.done_reading_called()); |
| 159 | 159 |
| 160 RemoveMockTransaction(&kRedirect_Transaction); | 160 RemoveMockTransaction(&kRedirect_Transaction); |
| 161 } | 161 } |
| 162 | 162 |
| 163 TEST(URLRequestJob, TransactionNotCachedWhenNetworkDelegateRedirects) { | 163 TEST(URLRequestJob, TransactionNotCachedWhenNetworkDelegateRedirects) { |
| 164 MockNetworkLayer network_layer; | 164 MockNetworkLayer network_layer; |
| 165 TestNetworkDelegate network_delegate; | 165 TestNetworkDelegate network_delegate; |
| 166 network_delegate.set_redirect_on_headers_received_url(GURL("http://foo")); | 166 network_delegate.set_redirect_on_headers_received_url(GURL("http://foo")); |
| 167 TestURLRequestContext context; | 167 TestURLRequestContext context; |
| 168 context.set_http_transaction_factory(&network_layer); | 168 context.set_http_transaction_factory(&network_layer); |
| 169 context.set_network_delegate(&network_delegate); | 169 context.set_network_delegate(&network_delegate); |
| 170 | 170 |
| 171 TestDelegate d; | 171 TestDelegate d; |
| 172 scoped_ptr<URLRequest> req(context.CreateRequest( | 172 scoped_ptr<URLRequest> req( |
| 173 GURL(kGZip_Transaction.url), DEFAULT_PRIORITY, &d, NULL)); | 173 context.CreateRequest(GURL(kGZip_Transaction.url), DEFAULT_PRIORITY, &d)); |
| 174 AddMockTransaction(&kGZip_Transaction); | 174 AddMockTransaction(&kGZip_Transaction); |
| 175 | 175 |
| 176 req->set_method("GET"); | 176 req->set_method("GET"); |
| 177 req->Start(); | 177 req->Start(); |
| 178 | 178 |
| 179 base::RunLoop().Run(); | 179 base::RunLoop().Run(); |
| 180 | 180 |
| 181 EXPECT_TRUE(network_layer.stop_caching_called()); | 181 EXPECT_TRUE(network_layer.stop_caching_called()); |
| 182 | 182 |
| 183 RemoveMockTransaction(&kGZip_Transaction); | 183 RemoveMockTransaction(&kGZip_Transaction); |
| 184 } | 184 } |
| 185 | 185 |
| 186 } // namespace net | 186 } // namespace net |
| OLD | NEW |