Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1259)

Side by Side Diff: chrome/common/net/url_fetcher_unittest.cc

Issue 6338002: net: Remove typedef net::URLRequestContext URLRequestContext; (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: for real Created 9 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "base/message_loop_proxy.h" 5 #include "base/message_loop_proxy.h"
6 #include "base/threading/thread.h" 6 #include "base/threading/thread.h"
7 #include "base/synchronization/waitable_event.h" 7 #include "base/synchronization/waitable_event.h"
8 #include "build/build_config.h" 8 #include "build/build_config.h"
9 #include "chrome/common/chrome_plugin_lib.h" 9 #include "chrome/common/chrome_plugin_lib.h"
10 #include "chrome/common/net/url_fetcher.h" 10 #include "chrome/common/net/url_fetcher.h"
(...skipping 16 matching lines...) Expand all
27 namespace { 27 namespace {
28 28
29 const FilePath::CharType kDocRoot[] = FILE_PATH_LITERAL("chrome/test/data"); 29 const FilePath::CharType kDocRoot[] = FILE_PATH_LITERAL("chrome/test/data");
30 30
31 class TestURLRequestContextGetter : public URLRequestContextGetter { 31 class TestURLRequestContextGetter : public URLRequestContextGetter {
32 public: 32 public:
33 explicit TestURLRequestContextGetter( 33 explicit TestURLRequestContextGetter(
34 base::MessageLoopProxy* io_message_loop_proxy) 34 base::MessageLoopProxy* io_message_loop_proxy)
35 : io_message_loop_proxy_(io_message_loop_proxy) { 35 : io_message_loop_proxy_(io_message_loop_proxy) {
36 } 36 }
37 virtual URLRequestContext* GetURLRequestContext() { 37 virtual net::URLRequestContext* GetURLRequestContext() {
38 if (!context_) 38 if (!context_)
39 context_ = new TestURLRequestContext(); 39 context_ = new TestURLRequestContext();
40 return context_; 40 return context_;
41 } 41 }
42 virtual scoped_refptr<base::MessageLoopProxy> GetIOMessageLoopProxy() const { 42 virtual scoped_refptr<base::MessageLoopProxy> GetIOMessageLoopProxy() const {
43 return io_message_loop_proxy_; 43 return io_message_loop_proxy_;
44 } 44 }
45 45
46 protected: 46 protected:
47 scoped_refptr<base::MessageLoopProxy> io_message_loop_proxy_; 47 scoped_refptr<base::MessageLoopProxy> io_message_loop_proxy_;
48 48
49 private: 49 private:
50 ~TestURLRequestContextGetter() {} 50 ~TestURLRequestContextGetter() {}
51 51
52 scoped_refptr<URLRequestContext> context_; 52 scoped_refptr<net::URLRequestContext> context_;
53 }; 53 };
54 54
55 class URLFetcherTest : public testing::Test, public URLFetcher::Delegate { 55 class URLFetcherTest : public testing::Test, public URLFetcher::Delegate {
56 public: 56 public:
57 URLFetcherTest() : fetcher_(NULL) { } 57 URLFetcherTest() : fetcher_(NULL) { }
58 58
59 // Creates a URLFetcher, using the program's main thread to do IO. 59 // Creates a URLFetcher, using the program's main thread to do IO.
60 virtual void CreateFetcher(const GURL& url); 60 virtual void CreateFetcher(const GURL& url);
61 61
62 // URLFetcher::Delegate 62 // URLFetcher::Delegate
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 } 199 }
200 }; 200 };
201 201
202 class CancelTestURLRequestContextGetter : public URLRequestContextGetter { 202 class CancelTestURLRequestContextGetter : public URLRequestContextGetter {
203 public: 203 public:
204 explicit CancelTestURLRequestContextGetter( 204 explicit CancelTestURLRequestContextGetter(
205 base::MessageLoopProxy* io_message_loop_proxy) 205 base::MessageLoopProxy* io_message_loop_proxy)
206 : io_message_loop_proxy_(io_message_loop_proxy), 206 : io_message_loop_proxy_(io_message_loop_proxy),
207 context_created_(false, false) { 207 context_created_(false, false) {
208 } 208 }
209 virtual URLRequestContext* GetURLRequestContext() { 209 virtual net::URLRequestContext* GetURLRequestContext() {
210 if (!context_) { 210 if (!context_) {
211 context_ = new CancelTestURLRequestContext(); 211 context_ = new CancelTestURLRequestContext();
212 context_created_.Signal(); 212 context_created_.Signal();
213 } 213 }
214 return context_; 214 return context_;
215 } 215 }
216 virtual scoped_refptr<base::MessageLoopProxy> GetIOMessageLoopProxy() const { 216 virtual scoped_refptr<base::MessageLoopProxy> GetIOMessageLoopProxy() const {
217 return io_message_loop_proxy_; 217 return io_message_loop_proxy_;
218 } 218 }
219 void WaitForContextCreation() { 219 void WaitForContextCreation() {
220 context_created_.Wait(); 220 context_created_.Wait();
221 } 221 }
222 222
223 private: 223 private:
224 ~CancelTestURLRequestContextGetter() {} 224 ~CancelTestURLRequestContextGetter() {}
225 225
226 scoped_refptr<base::MessageLoopProxy> io_message_loop_proxy_; 226 scoped_refptr<base::MessageLoopProxy> io_message_loop_proxy_;
227 base::WaitableEvent context_created_; 227 base::WaitableEvent context_created_;
228 scoped_refptr<URLRequestContext> context_; 228 scoped_refptr<net::URLRequestContext> context_;
229 }; 229 };
230 230
231 // Version of URLFetcherTest that tests retying the same request twice. 231 // Version of URLFetcherTest that tests retying the same request twice.
232 class URLFetcherMultipleAttemptTest : public URLFetcherTest { 232 class URLFetcherMultipleAttemptTest : public URLFetcherTest {
233 public: 233 public:
234 // URLFetcher::Delegate 234 // URLFetcher::Delegate
235 virtual void OnURLFetchComplete(const URLFetcher* source, 235 virtual void OnURLFetchComplete(const URLFetcher* source,
236 const GURL& url, 236 const GURL& url,
237 const net::URLRequestStatus& status, 237 const net::URLRequestStatus& status,
238 int response_code, 238 int response_code,
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
431 io_message_loop_proxy()->PostTask(FROM_HERE, new MessageLoop::QuitTask()); 431 io_message_loop_proxy()->PostTask(FROM_HERE, new MessageLoop::QuitTask());
432 } 432 }
433 433
434 void URLFetcherCancelTest::CreateFetcher(const GURL& url) { 434 void URLFetcherCancelTest::CreateFetcher(const GURL& url) {
435 fetcher_ = new URLFetcher(url, URLFetcher::GET, this); 435 fetcher_ = new URLFetcher(url, URLFetcher::GET, this);
436 CancelTestURLRequestContextGetter* context_getter = 436 CancelTestURLRequestContextGetter* context_getter =
437 new CancelTestURLRequestContextGetter(io_message_loop_proxy()); 437 new CancelTestURLRequestContextGetter(io_message_loop_proxy());
438 fetcher_->set_request_context(context_getter); 438 fetcher_->set_request_context(context_getter);
439 fetcher_->set_max_retries(2); 439 fetcher_->set_max_retries(2);
440 fetcher_->Start(); 440 fetcher_->Start();
441 // We need to wait for the creation of the URLRequestContext, since we 441 // We need to wait for the creation of the net::URLRequestContext, since we
442 // rely on it being destroyed as a signal to end the test. 442 // rely on it being destroyed as a signal to end the test.
443 context_getter->WaitForContextCreation(); 443 context_getter->WaitForContextCreation();
444 CancelRequest(); 444 CancelRequest();
445 } 445 }
446 446
447 void URLFetcherCancelTest::OnURLFetchComplete( 447 void URLFetcherCancelTest::OnURLFetchComplete(
448 const URLFetcher* source, 448 const URLFetcher* source,
449 const GURL& url, 449 const GURL& url,
450 const net::URLRequestStatus& status, 450 const net::URLRequestStatus& status,
451 int response_code, 451 int response_code,
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after
676 676
677 // Create the fetcher on the main thread. Since IO will happen on the main 677 // Create the fetcher on the main thread. Since IO will happen on the main
678 // thread, this will test URLFetcher's ability to do everything on one 678 // thread, this will test URLFetcher's ability to do everything on one
679 // thread. 679 // thread.
680 CreateFetcher(test_server.GetURL("defaultresponse")); 680 CreateFetcher(test_server.GetURL("defaultresponse"));
681 681
682 MessageLoop::current()->Run(); 682 MessageLoop::current()->Run();
683 } 683 }
684 684
685 } // namespace. 685 } // namespace.
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698