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_fetcher_impl.h" | 5 #include "net/url_request/url_fetcher_impl.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 scoped_refptr<base::MessageLoopProxy> io_message_loop_proxy() { | 101 scoped_refptr<base::MessageLoopProxy> io_message_loop_proxy() { |
102 return io_message_loop_proxy_; | 102 return io_message_loop_proxy_; |
103 } | 103 } |
104 | 104 |
105 TestURLRequestContext* request_context() { | 105 TestURLRequestContext* request_context() { |
106 return context_.get(); | 106 return context_.get(); |
107 } | 107 } |
108 | 108 |
109 protected: | 109 protected: |
110 // testing::Test: | 110 // testing::Test: |
111 virtual void SetUp() override { | 111 void SetUp() override { |
112 testing::Test::SetUp(); | 112 testing::Test::SetUp(); |
113 | 113 |
114 context_.reset(new ThrottlingTestURLRequestContext()); | 114 context_.reset(new ThrottlingTestURLRequestContext()); |
115 io_message_loop_proxy_ = base::MessageLoopProxy::current(); | 115 io_message_loop_proxy_ = base::MessageLoopProxy::current(); |
116 | 116 |
117 #if defined(USE_NSS) || defined(OS_IOS) | 117 #if defined(USE_NSS) || defined(OS_IOS) |
118 crypto::EnsureNSSInit(); | 118 crypto::EnsureNSSInit(); |
119 EnsureNSSHttpIOInit(); | 119 EnsureNSSHttpIOInit(); |
120 #endif | 120 #endif |
121 } | 121 } |
122 | 122 |
123 virtual void TearDown() override { | 123 void TearDown() override { |
124 #if defined(USE_NSS) || defined(OS_IOS) | 124 #if defined(USE_NSS) || defined(OS_IOS) |
125 ShutdownNSSHttpIO(); | 125 ShutdownNSSHttpIO(); |
126 #endif | 126 #endif |
127 } | 127 } |
128 | 128 |
129 // URLFetcher is designed to run on the main UI thread, but in our tests | 129 // URLFetcher is designed to run on the main UI thread, but in our tests |
130 // we assume that the current thread is the IO thread where the URLFetcher | 130 // we assume that the current thread is the IO thread where the URLFetcher |
131 // dispatches its requests to. When we wish to simulate being used from | 131 // dispatches its requests to. When we wish to simulate being used from |
132 // a UI thread, we dispatch a worker thread to do so. | 132 // a UI thread, we dispatch a worker thread to do so. |
133 scoped_refptr<base::MessageLoopProxy> io_message_loop_proxy_; | 133 scoped_refptr<base::MessageLoopProxy> io_message_loop_proxy_; |
134 | 134 |
135 URLFetcherImpl* fetcher_; | 135 URLFetcherImpl* fetcher_; |
136 scoped_ptr<TestURLRequestContext> context_; | 136 scoped_ptr<TestURLRequestContext> context_; |
137 }; | 137 }; |
138 | 138 |
139 // A test fixture that uses a MockHostResolver, so that name resolutions can | 139 // A test fixture that uses a MockHostResolver, so that name resolutions can |
140 // be manipulated by the tests to keep connections in the resolving state. | 140 // be manipulated by the tests to keep connections in the resolving state. |
141 class URLFetcherMockDnsTest : public URLFetcherTest { | 141 class URLFetcherMockDnsTest : public URLFetcherTest { |
142 public: | 142 public: |
143 // testing::Test: | 143 // testing::Test: |
144 virtual void SetUp() override; | 144 void SetUp() override; |
145 | 145 |
146 // URLFetcherTest: | 146 // URLFetcherTest: |
147 void CreateFetcher(const GURL& url) override; | 147 void CreateFetcher(const GURL& url) override; |
148 | 148 |
149 // URLFetcherDelegate: | 149 // URLFetcherDelegate: |
150 void OnURLFetchComplete(const URLFetcher* source) override; | 150 void OnURLFetchComplete(const URLFetcher* source) override; |
151 | 151 |
152 protected: | 152 protected: |
153 GURL test_url_; | 153 GURL test_url_; |
154 scoped_ptr<SpawnedTestServer> test_server_; | 154 scoped_ptr<SpawnedTestServer> test_server_; |
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
340 | 340 |
341 protected: | 341 protected: |
342 std::string expected_host_; | 342 std::string expected_host_; |
343 uint16 expected_port_; | 343 uint16 expected_port_; |
344 }; | 344 }; |
345 | 345 |
346 // Version of URLFetcherTest that tests stopping on a redirect. | 346 // Version of URLFetcherTest that tests stopping on a redirect. |
347 class URLFetcherStopOnRedirectTest : public URLFetcherTest { | 347 class URLFetcherStopOnRedirectTest : public URLFetcherTest { |
348 public: | 348 public: |
349 URLFetcherStopOnRedirectTest(); | 349 URLFetcherStopOnRedirectTest(); |
350 virtual ~URLFetcherStopOnRedirectTest(); | 350 ~URLFetcherStopOnRedirectTest() override; |
351 | 351 |
352 // URLFetcherTest: | 352 // URLFetcherTest: |
353 void CreateFetcher(const GURL& url) override; | 353 void CreateFetcher(const GURL& url) override; |
354 | 354 |
355 // URLFetcherDelegate: | 355 // URLFetcherDelegate: |
356 void OnURLFetchComplete(const URLFetcher* source) override; | 356 void OnURLFetchComplete(const URLFetcher* source) override; |
357 | 357 |
358 protected: | 358 protected: |
359 // The URL we should be redirected to. | 359 // The URL we should be redirected to. |
360 static const char* kRedirectTarget; | 360 static const char* kRedirectTarget; |
(...skipping 1172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1533 | 1533 |
1534 base::MessageLoop::current()->RunUntilIdle(); | 1534 base::MessageLoop::current()->RunUntilIdle(); |
1535 ASSERT_EQ(kTake[i], base::PathExists(file_path_)) << | 1535 ASSERT_EQ(kTake[i], base::PathExists(file_path_)) << |
1536 "FilePath: " << file_path_.value(); | 1536 "FilePath: " << file_path_.value(); |
1537 } | 1537 } |
1538 } | 1538 } |
1539 | 1539 |
1540 } // namespace | 1540 } // namespace |
1541 | 1541 |
1542 } // namespace net | 1542 } // namespace net |
OLD | NEW |