| 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 #include "chrome/browser/bitmap_fetcher/bitmap_fetcher_service.h" | 5 #include "chrome/browser/bitmap_fetcher/bitmap_fetcher_service.h" |
| 6 | 6 |
| 7 #include "chrome/browser/bitmap_fetcher/bitmap_fetcher.h" | 7 #include "chrome/browser/bitmap_fetcher/bitmap_fetcher.h" |
| 8 #include "chrome/test/base/testing_profile.h" | 8 #include "chrome/test/base/testing_profile.h" |
| 9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
| 10 | 10 |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 // Simulate finishing a URL fetch and decode for the given fetcher. | 71 // Simulate finishing a URL fetch and decode for the given fetcher. |
| 72 void CompleteFetch(const GURL& url) { | 72 void CompleteFetch(const GURL& url) { |
| 73 const chrome::BitmapFetcher* fetcher = service_->FindFetcherForUrl(url); | 73 const chrome::BitmapFetcher* fetcher = service_->FindFetcherForUrl(url); |
| 74 ASSERT_TRUE(NULL != fetcher); | 74 ASSERT_TRUE(NULL != fetcher); |
| 75 | 75 |
| 76 // Create a non-empty bitmap. | 76 // Create a non-empty bitmap. |
| 77 SkBitmap image; | 77 SkBitmap image; |
| 78 image.allocN32Pixels(2, 2); | 78 image.allocN32Pixels(2, 2); |
| 79 image.eraseColor(SK_ColorGREEN); | 79 image.eraseColor(SK_ColorGREEN); |
| 80 | 80 |
| 81 const_cast<chrome::BitmapFetcher*>(fetcher)->OnImageDecoded(NULL, image); | 81 const_cast<chrome::BitmapFetcher*>(fetcher)->OnImageDecoded(image); |
| 82 } | 82 } |
| 83 | 83 |
| 84 void FailFetch(const GURL& url) { | 84 void FailFetch(const GURL& url) { |
| 85 const chrome::BitmapFetcher* fetcher = service_->FindFetcherForUrl(url); | 85 const chrome::BitmapFetcher* fetcher = service_->FindFetcherForUrl(url); |
| 86 ASSERT_TRUE(NULL != fetcher); | 86 ASSERT_TRUE(NULL != fetcher); |
| 87 const_cast<chrome::BitmapFetcher*>(fetcher) | 87 const_cast<chrome::BitmapFetcher*>(fetcher)->OnImageDecoded(SkBitmap()); |
| 88 ->OnImageDecoded(NULL, SkBitmap()); | |
| 89 } | 88 } |
| 90 | 89 |
| 91 protected: | 90 protected: |
| 92 scoped_ptr<BitmapFetcherService> service_; | 91 scoped_ptr<BitmapFetcherService> service_; |
| 93 | 92 |
| 94 int imagesChanged_; | 93 int imagesChanged_; |
| 95 int requestsFinished_; | 94 int requestsFinished_; |
| 96 | 95 |
| 97 GURL url1_; | 96 GURL url1_; |
| 98 GURL url2_; | 97 GURL url2_; |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 163 service_->RequestImage(url1_, new TestObserver(this)); | 162 service_->RequestImage(url1_, new TestObserver(this)); |
| 164 service_->RequestImage(url2_, new TestObserver(this)); | 163 service_->RequestImage(url2_, new TestObserver(this)); |
| 165 EXPECT_EQ(0U, cache_size()); | 164 EXPECT_EQ(0U, cache_size()); |
| 166 | 165 |
| 167 CompleteFetch(url1_); | 166 CompleteFetch(url1_); |
| 168 EXPECT_EQ(1U, cache_size()); | 167 EXPECT_EQ(1U, cache_size()); |
| 169 | 168 |
| 170 FailFetch(url2_); | 169 FailFetch(url2_); |
| 171 EXPECT_EQ(1U, cache_size()); | 170 EXPECT_EQ(1U, cache_size()); |
| 172 } | 171 } |
| OLD | NEW |