| 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 <string> | 5 #include <string> |
| 6 | 6 |
| 7 #include "chrome/browser/image_holder.h" | 7 #include "chrome/browser/image_holder.h" |
| 8 #include "content/public/test/test_browser_thread_bundle.h" |
| 8 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
| 9 | 10 |
| 10 namespace { | 11 namespace { |
| 11 | 12 |
| 12 const char kIconUrl1[] = "http://www.google.com/icon1.jpg"; | 13 const char kIconUrl1[] = "http://www.google.com/icon1.jpg"; |
| 13 const char kIconUrl2[] = "http://www.google.com/icon2.jpg"; | 14 const char kIconUrl2[] = "http://www.google.com/icon2.jpg"; |
| 14 | 15 |
| 15 class TestDelegate : public chrome::ImageHolderDelegate { | 16 class TestDelegate : public chrome::ImageHolderDelegate { |
| 16 public: | 17 public: |
| 17 TestDelegate() : on_fetch_complete_called_(false) {} | 18 TestDelegate() : on_fetch_complete_called_(false) {} |
| 19 |
| 20 bool on_fetch_complete_called() const { return on_fetch_complete_called_; } |
| 21 |
| 22 // chrome::ImageHolderDelegate |
| 18 void OnFetchComplete() override { on_fetch_complete_called_ = true; } | 23 void OnFetchComplete() override { on_fetch_complete_called_ = true; } |
| 24 |
| 25 private: |
| 26 content::TestBrowserThreadBundle thread_bundle_; |
| 19 bool on_fetch_complete_called_; | 27 bool on_fetch_complete_called_; |
| 28 |
| 29 DISALLOW_COPY_AND_ASSIGN(TestDelegate); |
| 20 }; | 30 }; |
| 21 | 31 |
| 22 } // namespace. | 32 } // namespace |
| 23 | 33 |
| 24 namespace chrome { | 34 namespace chrome { |
| 25 | 35 |
| 26 typedef testing::Test ImageHolderTest; | 36 typedef testing::Test ImageHolderTest; |
| 27 | 37 |
| 28 TEST_F(ImageHolderTest, CreateBitmapFetcherTest) { | 38 TEST_F(ImageHolderTest, CreateBitmapFetcherTest) { |
| 29 TestDelegate delegate; | 39 TestDelegate delegate; |
| 30 ImageHolder image_holder(GURL(kIconUrl1), GURL(kIconUrl2), NULL, &delegate); | 40 ImageHolder image_holder(GURL(kIconUrl1), GURL(kIconUrl2), nullptr, |
| 41 &delegate); |
| 31 | 42 |
| 43 ASSERT_EQ(2U, image_holder.fetchers_.size()); |
| 32 EXPECT_EQ(GURL(kIconUrl1), image_holder.fetchers_[0]->url()); | 44 EXPECT_EQ(GURL(kIconUrl1), image_holder.fetchers_[0]->url()); |
| 33 EXPECT_EQ(GURL(kIconUrl2), image_holder.fetchers_[1]->url()); | 45 EXPECT_EQ(GURL(kIconUrl2), image_holder.fetchers_[1]->url()); |
| 34 EXPECT_EQ(static_cast<unsigned int>(2), image_holder.fetchers_.size()); | |
| 35 | 46 |
| 36 // Adding a dup of an existing URL shouldn't change anything. | 47 // Adding a dup of an existing URL shouldn't change anything. |
| 37 image_holder.CreateBitmapFetcher(GURL(kIconUrl2)); | 48 image_holder.CreateBitmapFetcher(GURL(kIconUrl2)); |
| 49 ASSERT_EQ(2U, image_holder.fetchers_.size()); |
| 38 EXPECT_EQ(GURL(kIconUrl1), image_holder.fetchers_[0]->url()); | 50 EXPECT_EQ(GURL(kIconUrl1), image_holder.fetchers_[0]->url()); |
| 39 EXPECT_EQ(GURL(kIconUrl2), image_holder.fetchers_[1]->url()); | 51 EXPECT_EQ(GURL(kIconUrl2), image_holder.fetchers_[1]->url()); |
| 40 EXPECT_EQ(static_cast<unsigned int>(2), image_holder.fetchers_.size()); | |
| 41 } | 52 } |
| 42 | 53 |
| 43 TEST_F(ImageHolderTest, OnFetchCompleteTest) { | 54 TEST_F(ImageHolderTest, OnFetchCompleteTest) { |
| 44 TestDelegate delegate; | 55 TestDelegate delegate; |
| 45 ImageHolder image_holder(GURL(kIconUrl1), GURL(), NULL, &delegate); | 56 ImageHolder image_holder(GURL(kIconUrl1), GURL(), nullptr, &delegate); |
| 46 | 57 |
| 47 // Put a real bitmap into "bitmap". 2x2 bitmap of green 32 bit pixels. | 58 // Put a real bitmap into "bitmap". 2x2 bitmap of green 32 bit pixels. |
| 48 SkBitmap bitmap; | 59 SkBitmap bitmap; |
| 49 bitmap.allocN32Pixels(2, 2); | 60 bitmap.allocN32Pixels(2, 2); |
| 50 bitmap.eraseColor(SK_ColorGREEN); | 61 bitmap.eraseColor(SK_ColorGREEN); |
| 51 | 62 |
| 52 image_holder.OnFetchComplete(GURL(kIconUrl1), &bitmap); | 63 image_holder.OnFetchComplete(GURL(kIconUrl1), &bitmap); |
| 53 | 64 |
| 54 // Expect that the app icon has some data in it. | 65 // Expect that the app icon has some data in it. |
| 55 EXPECT_FALSE(image_holder.low_dpi_image().IsEmpty()); | 66 EXPECT_FALSE(image_holder.low_dpi_image().IsEmpty()); |
| 56 | 67 |
| 57 // Expect that we reported the fetch done to the delegate. | 68 // Expect that we reported the fetch done to the delegate. |
| 58 EXPECT_TRUE(delegate.on_fetch_complete_called_); | 69 EXPECT_TRUE(delegate.on_fetch_complete_called()); |
| 59 } | 70 } |
| 60 | 71 |
| 61 TEST_F(ImageHolderTest, IsFetchingDoneTest) { | 72 TEST_F(ImageHolderTest, IsFetchingDoneTest) { |
| 62 TestDelegate delegate; | 73 TestDelegate delegate; |
| 63 ImageHolder image_holder1(GURL(kIconUrl1), GURL(kIconUrl2), NULL, &delegate); | 74 ImageHolder image_holder1(GURL(kIconUrl1), GURL(kIconUrl2), nullptr, |
| 64 ImageHolder image_holder2(GURL(kIconUrl1), GURL(), NULL, &delegate); | 75 &delegate); |
| 65 ImageHolder image_holder3(GURL(), GURL(kIconUrl2), NULL, &delegate); | 76 ImageHolder image_holder2(GURL(kIconUrl1), GURL(), nullptr, &delegate); |
| 66 ImageHolder image_holder4(GURL(), GURL(), NULL, &delegate); | 77 ImageHolder image_holder3(GURL(), GURL(kIconUrl2), nullptr, &delegate); |
| 78 ImageHolder image_holder4(GURL(), GURL(), nullptr, &delegate); |
| 67 | 79 |
| 68 // Initially, image holder 4 with no URLs should report done, but no others. | 80 // Initially, image holder 4 with no URLs should report done, but no others. |
| 69 EXPECT_FALSE(image_holder1.IsFetchingDone()); | 81 EXPECT_FALSE(image_holder1.IsFetchingDone()); |
| 70 EXPECT_FALSE(image_holder2.IsFetchingDone()); | 82 EXPECT_FALSE(image_holder2.IsFetchingDone()); |
| 71 EXPECT_FALSE(image_holder3.IsFetchingDone()); | 83 EXPECT_FALSE(image_holder3.IsFetchingDone()); |
| 72 EXPECT_TRUE(image_holder4.IsFetchingDone()); | 84 EXPECT_TRUE(image_holder4.IsFetchingDone()); |
| 73 | 85 |
| 74 // Put a real bitmap into "bitmap". 2x2 bitmap of green 32 bit pixels. | 86 // Put a real bitmap into "bitmap". 2x2 bitmap of green 32 bit pixels. |
| 75 SkBitmap bitmap; | 87 SkBitmap bitmap; |
| 76 bitmap.allocN32Pixels(2, 2); | 88 bitmap.allocN32Pixels(2, 2); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 91 image_holder2.OnFetchComplete(GURL(kIconUrl2), &bitmap); | 103 image_holder2.OnFetchComplete(GURL(kIconUrl2), &bitmap); |
| 92 image_holder3.OnFetchComplete(GURL(kIconUrl2), &bitmap); | 104 image_holder3.OnFetchComplete(GURL(kIconUrl2), &bitmap); |
| 93 image_holder4.OnFetchComplete(GURL(kIconUrl2), &bitmap); | 105 image_holder4.OnFetchComplete(GURL(kIconUrl2), &bitmap); |
| 94 EXPECT_TRUE(image_holder1.IsFetchingDone()); | 106 EXPECT_TRUE(image_holder1.IsFetchingDone()); |
| 95 EXPECT_TRUE(image_holder2.IsFetchingDone()); | 107 EXPECT_TRUE(image_holder2.IsFetchingDone()); |
| 96 EXPECT_TRUE(image_holder3.IsFetchingDone()); | 108 EXPECT_TRUE(image_holder3.IsFetchingDone()); |
| 97 EXPECT_TRUE(image_holder4.IsFetchingDone()); | 109 EXPECT_TRUE(image_holder4.IsFetchingDone()); |
| 98 } | 110 } |
| 99 | 111 |
| 100 } // namespace chrome. | 112 } // namespace chrome. |
| OLD | NEW |