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 "build/build_config.h" | 5 #include "build/build_config.h" |
6 | 6 |
7 #if defined(OS_WIN) | 7 #if defined(OS_WIN) |
8 #include <windows.h> | 8 #include <windows.h> |
9 #include <shlobj.h> | 9 #include <shlobj.h> |
10 #endif | 10 #endif |
(...skipping 6805 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6816 scoped_ptr<URLRequest> req( | 6816 scoped_ptr<URLRequest> req( |
6817 context.CreateRequest(GURL("http://127.0.0.1/"), DEFAULT_PRIORITY, &d)); | 6817 context.CreateRequest(GURL("http://127.0.0.1/"), DEFAULT_PRIORITY, &d)); |
6818 req->Start(); | 6818 req->Start(); |
6819 base::RunLoop().Run(); | 6819 base::RunLoop().Run(); |
6820 | 6820 |
6821 EXPECT_TRUE(d.request_failed()); | 6821 EXPECT_TRUE(d.request_failed()); |
6822 EXPECT_EQ(URLRequestStatus::FAILED, req->status().status()); | 6822 EXPECT_EQ(URLRequestStatus::FAILED, req->status().status()); |
6823 EXPECT_EQ(ERR_NETWORK_IO_SUSPENDED, req->status().error()); | 6823 EXPECT_EQ(ERR_NETWORK_IO_SUSPENDED, req->status().error()); |
6824 } | 6824 } |
6825 | 6825 |
| 6826 TEST_F(URLRequestTestHTTP, NetworkAccessedSetOnNetworkRequest) { |
| 6827 ASSERT_TRUE(test_server_.Start()); |
| 6828 |
| 6829 TestDelegate d; |
| 6830 GURL test_url(test_server_.GetURL(std::string())); |
| 6831 scoped_ptr<URLRequest> req( |
| 6832 default_context_.CreateRequest(test_url, DEFAULT_PRIORITY, &d)); |
| 6833 |
| 6834 req->Start(); |
| 6835 base::RunLoop().Run(); |
| 6836 |
| 6837 EXPECT_TRUE(req->response_info().network_accessed); |
| 6838 } |
| 6839 |
| 6840 TEST_F(URLRequestTestHTTP, NetworkAccessedClearOnCachedResponse) { |
| 6841 ASSERT_TRUE(test_server_.Start()); |
| 6842 |
| 6843 // Populate the cache. |
| 6844 TestDelegate d; |
| 6845 scoped_ptr<URLRequest> req(default_context_.CreateRequest( |
| 6846 test_server_.GetURL("cachetime"), DEFAULT_PRIORITY, &d)); |
| 6847 req->Start(); |
| 6848 base::RunLoop().Run(); |
| 6849 |
| 6850 EXPECT_EQ(URLRequestStatus::SUCCESS, req->status().status()); |
| 6851 EXPECT_TRUE(req->response_info().network_accessed); |
| 6852 EXPECT_FALSE(req->response_info().was_cached); |
| 6853 |
| 6854 req = default_context_.CreateRequest(test_server_.GetURL("cachetime"), |
| 6855 DEFAULT_PRIORITY, &d); |
| 6856 req->Start(); |
| 6857 base::RunLoop().Run(); |
| 6858 |
| 6859 EXPECT_EQ(URLRequestStatus::SUCCESS, req->status().status()); |
| 6860 EXPECT_FALSE(req->response_info().network_accessed); |
| 6861 EXPECT_TRUE(req->response_info().was_cached); |
| 6862 } |
| 6863 |
| 6864 TEST_F(URLRequestTestHTTP, NetworkAccessedClearOnLoadOnlyFromCache) { |
| 6865 ASSERT_TRUE(test_server_.Start()); |
| 6866 |
| 6867 TestDelegate d; |
| 6868 GURL test_url(test_server_.GetURL(std::string())); |
| 6869 scoped_ptr<URLRequest> req( |
| 6870 default_context_.CreateRequest(test_url, DEFAULT_PRIORITY, &d)); |
| 6871 req->SetLoadFlags(LOAD_ONLY_FROM_CACHE); |
| 6872 |
| 6873 req->Start(); |
| 6874 base::RunLoop().Run(); |
| 6875 |
| 6876 EXPECT_FALSE(req->response_info().network_accessed); |
| 6877 } |
| 6878 |
6826 class URLRequestInterceptorTestHTTP : public URLRequestTestHTTP { | 6879 class URLRequestInterceptorTestHTTP : public URLRequestTestHTTP { |
6827 public: | 6880 public: |
6828 // TODO(bengr): Merge this with the URLRequestInterceptorHTTPTest fixture, | 6881 // TODO(bengr): Merge this with the URLRequestInterceptorHTTPTest fixture, |
6829 // ideally remove the dependency on URLRequestTestJob, and maybe move these | 6882 // ideally remove the dependency on URLRequestTestJob, and maybe move these |
6830 // tests into the factory tests. | 6883 // tests into the factory tests. |
6831 URLRequestInterceptorTestHTTP() : URLRequestTestHTTP(), interceptor_(NULL) { | 6884 URLRequestInterceptorTestHTTP() : URLRequestTestHTTP(), interceptor_(NULL) { |
6832 } | 6885 } |
6833 | 6886 |
6834 void SetUpFactory() override { | 6887 void SetUpFactory() override { |
6835 interceptor_ = new MockURLRequestInterceptor(); | 6888 interceptor_ = new MockURLRequestInterceptor(); |
(...skipping 2246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9082 base::GetFileSize(app_path, &file_size); | 9135 base::GetFileSize(app_path, &file_size); |
9083 | 9136 |
9084 EXPECT_FALSE(r->is_pending()); | 9137 EXPECT_FALSE(r->is_pending()); |
9085 EXPECT_EQ(1, d->response_started_count()); | 9138 EXPECT_EQ(1, d->response_started_count()); |
9086 EXPECT_FALSE(d->received_data_before_response()); | 9139 EXPECT_FALSE(d->received_data_before_response()); |
9087 EXPECT_EQ(d->bytes_received(), static_cast<int>(file_size)); | 9140 EXPECT_EQ(d->bytes_received(), static_cast<int>(file_size)); |
9088 } | 9141 } |
9089 } | 9142 } |
9090 #endif // !defined(DISABLE_FTP_SUPPORT) | 9143 #endif // !defined(DISABLE_FTP_SUPPORT) |
9091 | 9144 |
| 9145 TEST_F(URLRequestTest, NetworkAccessedClearBeforeNetworkStart) { |
| 9146 TestDelegate d; |
| 9147 scoped_ptr<URLRequest> req(default_context_.CreateRequest( |
| 9148 GURL("http://test_intercept/foo"), DEFAULT_PRIORITY, &d)); |
| 9149 d.set_quit_on_network_start(true); |
| 9150 |
| 9151 EXPECT_FALSE(req->response_info().network_accessed); |
| 9152 |
| 9153 req->Start(); |
| 9154 base::RunLoop().Run(); |
| 9155 |
| 9156 EXPECT_EQ(1, d.received_before_network_start_count()); |
| 9157 EXPECT_EQ(0, d.response_started_count()); |
| 9158 EXPECT_FALSE(req->response_info().network_accessed); |
| 9159 |
| 9160 req->ResumeNetworkStart(); |
| 9161 base::RunLoop().Run(); |
| 9162 } |
| 9163 |
| 9164 TEST_F(URLRequestTest, NetworkAccessedClearOnDataRequest) { |
| 9165 TestDelegate d; |
| 9166 scoped_ptr<URLRequest> req( |
| 9167 default_context_.CreateRequest(GURL("data:,"), DEFAULT_PRIORITY, &d)); |
| 9168 |
| 9169 EXPECT_FALSE(req->response_info().network_accessed); |
| 9170 |
| 9171 req->Start(); |
| 9172 base::RunLoop().Run(); |
| 9173 |
| 9174 EXPECT_EQ(1, default_network_delegate_.completed_requests()); |
| 9175 EXPECT_FALSE(req->response_info().network_accessed); |
| 9176 } |
| 9177 |
| 9178 TEST_F(URLRequestTest, NetworkAccessedSetOnHostResolutionFailure) { |
| 9179 MockHostResolver host_resolver; |
| 9180 TestNetworkDelegate network_delegate; // Must outlive URLRequest. |
| 9181 TestURLRequestContext context(true); |
| 9182 context.set_network_delegate(&network_delegate); |
| 9183 context.set_host_resolver(&host_resolver); |
| 9184 host_resolver.rules()->AddSimulatedFailure("*"); |
| 9185 context.Init(); |
| 9186 |
| 9187 TestDelegate d; |
| 9188 scoped_ptr<URLRequest> req(context.CreateRequest( |
| 9189 GURL("http://test_intercept/foo"), DEFAULT_PRIORITY, &d)); |
| 9190 |
| 9191 EXPECT_FALSE(req->response_info().network_accessed); |
| 9192 |
| 9193 req->Start(); |
| 9194 base::RunLoop().Run(); |
| 9195 EXPECT_TRUE(req->response_info().network_accessed); |
| 9196 } |
| 9197 |
9092 } // namespace net | 9198 } // namespace net |
OLD | NEW |