| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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/thread.h" | 6 #include "base/thread.h" |
| 7 #include "base/waitable_event.h" | 7 #include "base/waitable_event.h" |
| 8 #include "chrome/browser/chrome_thread.h" | 8 #include "chrome/browser/chrome_thread.h" |
| 9 #include "chrome/browser/net/url_fetcher.h" | 9 #include "chrome/browser/net/url_fetcher.h" |
| 10 #include "chrome/browser/net/url_fetcher_protect.h" | 10 #include "chrome/browser/net/url_fetcher_protect.h" |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 | 24 |
| 25 const wchar_t kDocRoot[] = L"chrome/test/data"; | 25 const wchar_t kDocRoot[] = L"chrome/test/data"; |
| 26 | 26 |
| 27 class TestURLRequestContextGetter : public URLRequestContextGetter { | 27 class TestURLRequestContextGetter : public URLRequestContextGetter { |
| 28 public: | 28 public: |
| 29 virtual URLRequestContext* GetURLRequestContext() { | 29 virtual URLRequestContext* GetURLRequestContext() { |
| 30 if (!context_) | 30 if (!context_) |
| 31 context_ = new TestURLRequestContext(); | 31 context_ = new TestURLRequestContext(); |
| 32 return context_; | 32 return context_; |
| 33 } | 33 } |
| 34 virtual scoped_refptr<MessageLoopProxy> GetIOMessageLoopProxy() { | 34 virtual scoped_refptr<base::MessageLoopProxy> GetIOMessageLoopProxy() { |
| 35 return ChromeThread::GetMessageLoopProxyForThread(ChromeThread::IO); | 35 return ChromeThread::GetMessageLoopProxyForThread(ChromeThread::IO); |
| 36 } | 36 } |
| 37 | 37 |
| 38 private: | 38 private: |
| 39 ~TestURLRequestContextGetter() {} | 39 ~TestURLRequestContextGetter() {} |
| 40 | 40 |
| 41 scoped_refptr<URLRequestContext> context_; | 41 scoped_refptr<URLRequestContext> context_; |
| 42 }; | 42 }; |
| 43 | 43 |
| 44 class URLFetcherTest : public testing::Test, public URLFetcher::Delegate { | 44 class URLFetcherTest : public testing::Test, public URLFetcher::Delegate { |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 178 public: | 178 public: |
| 179 CancelTestURLRequestContextGetter() : context_created_(false, false) { | 179 CancelTestURLRequestContextGetter() : context_created_(false, false) { |
| 180 } | 180 } |
| 181 virtual URLRequestContext* GetURLRequestContext() { | 181 virtual URLRequestContext* GetURLRequestContext() { |
| 182 if (!context_) { | 182 if (!context_) { |
| 183 context_ = new CancelTestURLRequestContext(); | 183 context_ = new CancelTestURLRequestContext(); |
| 184 context_created_.Signal(); | 184 context_created_.Signal(); |
| 185 } | 185 } |
| 186 return context_; | 186 return context_; |
| 187 } | 187 } |
| 188 virtual scoped_refptr<MessageLoopProxy> GetIOMessageLoopProxy() { | 188 virtual scoped_refptr<base::MessageLoopProxy> GetIOMessageLoopProxy() { |
| 189 return ChromeThread::GetMessageLoopProxyForThread(ChromeThread::IO); | 189 return ChromeThread::GetMessageLoopProxyForThread(ChromeThread::IO); |
| 190 } | 190 } |
| 191 void WaitForContextCreation() { | 191 void WaitForContextCreation() { |
| 192 context_created_.Wait(); | 192 context_created_.Wait(); |
| 193 } | 193 } |
| 194 | 194 |
| 195 private: | 195 private: |
| 196 ~CancelTestURLRequestContextGetter() {} | 196 ~CancelTestURLRequestContextGetter() {} |
| 197 | 197 |
| 198 base::WaitableEvent context_created_; | 198 base::WaitableEvent context_created_; |
| (...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 590 // time difference from now). | 590 // time difference from now). |
| 591 | 591 |
| 592 base::Thread t("URLFetcher test thread"); | 592 base::Thread t("URLFetcher test thread"); |
| 593 ASSERT_TRUE(t.Start()); | 593 ASSERT_TRUE(t.Start()); |
| 594 t.message_loop()->PostTask(FROM_HERE, new FetcherWrapperTask(this, url)); | 594 t.message_loop()->PostTask(FROM_HERE, new FetcherWrapperTask(this, url)); |
| 595 | 595 |
| 596 MessageLoop::current()->Run(); | 596 MessageLoop::current()->Run(); |
| 597 } | 597 } |
| 598 | 598 |
| 599 } // namespace. | 599 } // namespace. |
| OLD | NEW |