| OLD | NEW |
| 1 // Copyright 2011 The Chromium Authors. All rights reserved. | 1 // Copyright 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 #import "ios/chrome/browser/net/image_fetcher.h" | 5 #import "ios/chrome/browser/net/image_fetcher.h" |
| 6 | 6 |
| 7 #import <UIKit/UIKit.h> | 7 #import <UIKit/UIKit.h> |
| 8 | 8 |
| 9 #include "base/ios/ios_util.h" | 9 #include "base/ios/ios_util.h" |
| 10 #include "base/mac/scoped_block.h" | 10 #include "base/mac/scoped_block.h" |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 "HTTP/1.1 200 OK\0Content-type: image/webp\0\0"; | 66 "HTTP/1.1 200 OK\0Content-type: image/webp\0\0"; |
| 67 | 67 |
| 68 } // namespace | 68 } // namespace |
| 69 | 69 |
| 70 // TODO(ios): remove the static_cast<UIImage*>(nil) once all the bots have | 70 // TODO(ios): remove the static_cast<UIImage*>(nil) once all the bots have |
| 71 // Xcode 6.0 or later installed, http://crbug.com/440857 | 71 // Xcode 6.0 or later installed, http://crbug.com/440857 |
| 72 | 72 |
| 73 class ImageFetcherTest : public PlatformTest { | 73 class ImageFetcherTest : public PlatformTest { |
| 74 protected: | 74 protected: |
| 75 ImageFetcherTest() | 75 ImageFetcherTest() |
| 76 : pool_(new base::SequencedWorkerPool(1, "TestPool")), | 76 : pool_(new base::SequencedWorkerPool(1, |
| 77 "TestPool", |
| 78 base::TaskPriority::USER_VISIBLE)), |
| 77 image_fetcher_(new ImageFetcher(pool_)), | 79 image_fetcher_(new ImageFetcher(pool_)), |
| 78 result_(nil), | 80 result_(nil), |
| 79 called_(false) { | 81 called_(false) { |
| 80 callback_.reset( | 82 callback_.reset( |
| 81 [^(const GURL& original_url, int http_response_code, NSData* data) { | 83 [^(const GURL& original_url, int http_response_code, NSData* data) { |
| 82 result_ = [UIImage imageWithData:data]; | 84 result_ = [UIImage imageWithData:data]; |
| 83 called_ = true; | 85 called_ = true; |
| 84 } copy]); | 86 } copy]); |
| 85 image_fetcher_->SetRequestContextGetter( | 87 image_fetcher_->SetRequestContextGetter( |
| 86 new net::TestURLRequestContextGetter( | 88 new net::TestURLRequestContextGetter( |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 184 EXPECT_EQ(static_cast<UIImage*>(nil), result_); | 186 EXPECT_EQ(static_cast<UIImage*>(nil), result_); |
| 185 EXPECT_FALSE(called_); | 187 EXPECT_FALSE(called_); |
| 186 } | 188 } |
| 187 | 189 |
| 188 TEST_F(ImageFetcherTest, TestCallbacksNotCalledDuringDeletion) { | 190 TEST_F(ImageFetcherTest, TestCallbacksNotCalledDuringDeletion) { |
| 189 image_fetcher_->StartDownload(GURL(kTestUrl), callback_); | 191 image_fetcher_->StartDownload(GURL(kTestUrl), callback_); |
| 190 image_fetcher_.reset(); | 192 image_fetcher_.reset(); |
| 191 EXPECT_FALSE(called_); | 193 EXPECT_FALSE(called_); |
| 192 } | 194 } |
| 193 | 195 |
| OLD | NEW |