| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #import "ios/chrome/browser/net/retryable_url_fetcher.h" | 5 #import "ios/chrome/browser/net/retryable_url_fetcher.h" |
| 6 | 6 |
| 7 #import "base/mac/scoped_nsobject.h" | 7 #import "base/mac/scoped_nsobject.h" |
| 8 #include "ios/web/public/test/test_web_thread.h" | 8 #include "ios/web/public/test/test_web_thread.h" |
| 9 #include "net/url_request/test_url_fetcher_factory.h" | 9 #include "net/url_request/test_url_fetcher_factory.h" |
| 10 #include "net/url_request/url_fetcher_delegate.h" | 10 #include "net/url_request/url_fetcher_delegate.h" |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 } | 53 } |
| 54 | 54 |
| 55 net::TestURLFetcherFactory factory_; | 55 net::TestURLFetcherFactory factory_; |
| 56 scoped_ptr<web::TestWebThread> io_thread_; | 56 scoped_ptr<web::TestWebThread> io_thread_; |
| 57 base::MessageLoop message_loop_; | 57 base::MessageLoop message_loop_; |
| 58 base::scoped_nsobject<TestRetryableURLFetcherDelegate> test_delegate_; | 58 base::scoped_nsobject<TestRetryableURLFetcherDelegate> test_delegate_; |
| 59 }; | 59 }; |
| 60 | 60 |
| 61 TEST_F(RetryableURLFetcherTest, TestResponse200) { | 61 TEST_F(RetryableURLFetcherTest, TestResponse200) { |
| 62 scoped_refptr<net::URLRequestContextGetter> request_context_getter = | 62 scoped_refptr<net::URLRequestContextGetter> request_context_getter = |
| 63 new net::TestURLRequestContextGetter(message_loop_.message_loop_proxy()); | 63 new net::TestURLRequestContextGetter(message_loop_.task_runner()); |
| 64 base::scoped_nsobject<RetryableURLFetcher> retryableFetcher( | 64 base::scoped_nsobject<RetryableURLFetcher> retryableFetcher( |
| 65 [[RetryableURLFetcher alloc] | 65 [[RetryableURLFetcher alloc] |
| 66 initWithRequestContextGetter:request_context_getter.get() | 66 initWithRequestContextGetter:request_context_getter.get() |
| 67 delegate:test_delegate_.get() | 67 delegate:test_delegate_.get() |
| 68 backoffPolicy:nil]); | 68 backoffPolicy:nil]); |
| 69 [retryableFetcher startFetch]; | 69 [retryableFetcher startFetch]; |
| 70 | 70 |
| 71 // Manually calls the delegate. | 71 // Manually calls the delegate. |
| 72 net::TestURLFetcher* fetcher = factory_.GetFetcherByID(0); | 72 net::TestURLFetcher* fetcher = factory_.GetFetcherByID(0); |
| 73 DCHECK(fetcher); | 73 DCHECK(fetcher); |
| 74 DCHECK(fetcher->delegate()); | 74 DCHECK(fetcher->delegate()); |
| 75 [test_delegate_ setResponsesProcessed:0U]; | 75 [test_delegate_ setResponsesProcessed:0U]; |
| 76 fetcher->set_response_code(200); | 76 fetcher->set_response_code(200); |
| 77 fetcher->SetResponseString([kFakeResponseString UTF8String]); | 77 fetcher->SetResponseString([kFakeResponseString UTF8String]); |
| 78 fetcher->delegate()->OnURLFetchComplete(fetcher); | 78 fetcher->delegate()->OnURLFetchComplete(fetcher); |
| 79 EXPECT_EQ(1U, [test_delegate_ responsesProcessed]); | 79 EXPECT_EQ(1U, [test_delegate_ responsesProcessed]); |
| 80 } | 80 } |
| 81 | 81 |
| 82 TEST_F(RetryableURLFetcherTest, TestResponse404) { | 82 TEST_F(RetryableURLFetcherTest, TestResponse404) { |
| 83 scoped_refptr<net::URLRequestContextGetter> request_context_getter = | 83 scoped_refptr<net::URLRequestContextGetter> request_context_getter = |
| 84 new net::TestURLRequestContextGetter(message_loop_.message_loop_proxy()); | 84 new net::TestURLRequestContextGetter(message_loop_.task_runner()); |
| 85 base::scoped_nsobject<RetryableURLFetcher> retryableFetcher( | 85 base::scoped_nsobject<RetryableURLFetcher> retryableFetcher( |
| 86 [[RetryableURLFetcher alloc] | 86 [[RetryableURLFetcher alloc] |
| 87 initWithRequestContextGetter:request_context_getter.get() | 87 initWithRequestContextGetter:request_context_getter.get() |
| 88 delegate:test_delegate_.get() | 88 delegate:test_delegate_.get() |
| 89 backoffPolicy:nil]); | 89 backoffPolicy:nil]); |
| 90 [retryableFetcher startFetch]; | 90 [retryableFetcher startFetch]; |
| 91 | 91 |
| 92 // Manually calls the delegate. | 92 // Manually calls the delegate. |
| 93 net::TestURLFetcher* fetcher = factory_.GetFetcherByID(0); | 93 net::TestURLFetcher* fetcher = factory_.GetFetcherByID(0); |
| 94 DCHECK(fetcher); | 94 DCHECK(fetcher); |
| 95 DCHECK(fetcher->delegate()); | 95 DCHECK(fetcher->delegate()); |
| 96 [test_delegate_ setResponsesProcessed:0U]; | 96 [test_delegate_ setResponsesProcessed:0U]; |
| 97 fetcher->set_response_code(404); | 97 fetcher->set_response_code(404); |
| 98 fetcher->SetResponseString(""); | 98 fetcher->SetResponseString(""); |
| 99 fetcher->delegate()->OnURLFetchComplete(fetcher); | 99 fetcher->delegate()->OnURLFetchComplete(fetcher); |
| 100 EXPECT_EQ(0U, [test_delegate_ responsesProcessed]); | 100 EXPECT_EQ(0U, [test_delegate_ responsesProcessed]); |
| 101 } | 101 } |
| 102 | 102 |
| 103 } // namespace | 103 } // namespace |
| OLD | NEW |