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 "content/public/test/test_browser_thread_bundle.h" | 9 #include "content/public/test/test_browser_thread_bundle.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
(...skipping 24 matching lines...) Expand all Loading... | |
35 }; | 35 }; |
36 | 36 |
37 class TestService : public BitmapFetcherService { | 37 class TestService : public BitmapFetcherService { |
38 public: | 38 public: |
39 explicit TestService(content::BrowserContext* context) | 39 explicit TestService(content::BrowserContext* context) |
40 : BitmapFetcherService(context) {} | 40 : BitmapFetcherService(context) {} |
41 ~TestService() override {} | 41 ~TestService() override {} |
42 | 42 |
43 // Create a fetcher, but don't start downloading. That allows side-stepping | 43 // Create a fetcher, but don't start downloading. That allows side-stepping |
44 // the decode step, which requires a utility process. | 44 // the decode step, which requires a utility process. |
45 chrome::BitmapFetcher* CreateFetcher(const GURL& url) override { | 45 scoped_ptr<chrome::BitmapFetcher> CreateFetcher(const GURL& url) override { |
46 return new chrome::BitmapFetcher(url, this); | 46 return make_scoped_ptr(new chrome::BitmapFetcher(url, this)); |
47 } | 47 } |
48 }; | 48 }; |
49 | 49 |
50 } // namespace | 50 } // namespace |
51 | 51 |
52 class BitmapFetcherServiceTest : public testing::Test, | 52 class BitmapFetcherServiceTest : public testing::Test, |
53 public TestNotificationInterface { | 53 public TestNotificationInterface { |
54 public: | 54 public: |
55 BitmapFetcherServiceTest() | 55 BitmapFetcherServiceTest() |
56 : url1_(GURL("http://example.org/sample-image-1.png")), | 56 : url1_(GURL("http://example.org/sample-image-1.png")), |
57 url2_(GURL("http://example.org/sample-image-2.png")) { | 57 url2_(GURL("http://example.org/sample-image-2.png")) { |
58 } | 58 } |
59 | 59 |
60 void SetUp() override { | 60 void SetUp() override { |
61 service_.reset(new TestService(&profile_)); | 61 service_.reset(new TestService(&profile_)); |
62 requests_finished_ = 0; | 62 requests_finished_ = 0; |
63 images_changed_ = 0; | 63 images_changed_ = 0; |
64 } | 64 } |
65 | 65 |
66 const ScopedVector<BitmapFetcherRequest>& requests() const { | 66 const ScopedVector<BitmapFetcherRequest>& requests() const { |
67 return service_->requests_; | 67 return service_->requests_; |
68 } | 68 } |
69 const ScopedVector<chrome::BitmapFetcher>& active_fetchers() const { | 69 const ScopedVector<chrome::BitmapFetcher>& active_fetchers() const { |
70 return service_->active_fetchers_; | 70 return service_->active_fetchers_; |
Nico
2015/11/11 01:28:23
oh i guess this needs changing too?
danakj
2015/11/11 01:29:08
ah yes thanks.
| |
71 } | 71 } |
72 size_t cache_size() const { return service_->cache_.size(); } | 72 size_t cache_size() const { return service_->cache_.size(); } |
73 | 73 |
74 void OnImageChanged() override { images_changed_++; } | 74 void OnImageChanged() override { images_changed_++; } |
75 | 75 |
76 void OnRequestFinished() override { requests_finished_++; } | 76 void OnRequestFinished() override { requests_finished_++; } |
77 | 77 |
78 // Simulate finishing a URL fetch and decode for the given fetcher. | 78 // Simulate finishing a URL fetch and decode for the given fetcher. |
79 void CompleteFetch(const GURL& url) { | 79 void CompleteFetch(const GURL& url) { |
80 const chrome::BitmapFetcher* fetcher = service_->FindFetcherForUrl(url); | 80 const chrome::BitmapFetcher* fetcher = service_->FindFetcherForUrl(url); |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
188 service_->RequestImage(url1_, new TestObserver(this)); | 188 service_->RequestImage(url1_, new TestObserver(this)); |
189 service_->RequestImage(url2_, new TestObserver(this)); | 189 service_->RequestImage(url2_, new TestObserver(this)); |
190 EXPECT_EQ(0U, cache_size()); | 190 EXPECT_EQ(0U, cache_size()); |
191 | 191 |
192 CompleteFetch(url1_); | 192 CompleteFetch(url1_); |
193 EXPECT_EQ(1U, cache_size()); | 193 EXPECT_EQ(1U, cache_size()); |
194 | 194 |
195 FailFetch(url2_); | 195 FailFetch(url2_); |
196 EXPECT_EQ(1U, cache_size()); | 196 EXPECT_EQ(1U, cache_size()); |
197 } | 197 } |
OLD | NEW |