Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(388)

Side by Side Diff: chrome/browser/notifications/sync_notifier/image_holder_unittest.cc

Issue 193773003: Turn on and use the AppInfo data. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Turn on app info: Refactoring the image holders Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include <string>
6
7 #include "chrome/browser/notifications/sync_notifier/image_holder.h"
8 #include "chrome/browser/notifications/sync_notifier/sync_notifier_test_utils.h"
9
10 #include "testing/gtest/include/gtest/gtest.h"
11
12 namespace {
13
14 class TestDelegate : public notifier::ImageHolderDelegate {
15 public:
16 TestDelegate() : on_fetch_complete_called_(false) {}
17 virtual void OnFetchComplete() OVERRIDE {
18 on_fetch_complete_called_ = true;
19 }
20 bool on_fetch_complete_called_;
21 };
22
23 } // namespace.
24
25 namespace notifier {
26
27 typedef testing::Test ImageHolderTest;
28
29 TEST_F(ImageHolderTest, CreateBitmapFetcherTest) {
30 TestDelegate delegate;
31 ImageHolder image_holder(GURL(kIconUrl1), GURL(kIconUrl2), NULL, &delegate);
32
33 EXPECT_EQ(GURL(kIconUrl1), image_holder.fetchers_[0]->url());
34 EXPECT_EQ(GURL(kIconUrl2), image_holder.fetchers_[1]->url());
35 EXPECT_EQ(static_cast<unsigned int>(2), image_holder.fetchers_.size());
36
37 // Adding a dup of an existing URL shouldn't change anything.
38 image_holder.CreateBitmapFetcher(GURL(kIconUrl2));
39 EXPECT_EQ(GURL(kIconUrl1), image_holder.fetchers_[0]->url());
40 EXPECT_EQ(GURL(kIconUrl2), image_holder.fetchers_[1]->url());
41 EXPECT_EQ(static_cast<unsigned int>(2), image_holder.fetchers_.size());
42 }
43
44 TEST_F(ImageHolderTest, OnFetchCompleteTest) {
45 TestDelegate delegate;
46 ImageHolder image_holder(GURL(kIconUrl1), GURL(), NULL, &delegate);
47
48 // Put a real bitmap into "bitmap". 2x2 bitmap of green 32 bit pixels.
49 SkBitmap bitmap;
50 bitmap.setConfig(SkBitmap::kARGB_8888_Config, 2, 2);
51 bitmap.allocPixels();
52 bitmap.eraseColor(SK_ColorGREEN);
53
54 image_holder.OnFetchComplete(GURL(kIconUrl1), &bitmap);
55
56 // Expect that the app icon has some data in it.
57 EXPECT_FALSE(image_holder.low_dpi_image().IsEmpty());
58
59 // Expect that we reported the fetch done to the delegate.
60 EXPECT_TRUE(delegate.on_fetch_complete_called_);
61 }
62
63 TEST_F(ImageHolderTest, IsFetchingDoneTest) {
64 TestDelegate delegate;
65 ImageHolder image_holder1(GURL(kIconUrl1), GURL(kIconUrl2), NULL, &delegate);
66 ImageHolder image_holder2(GURL(kIconUrl1), GURL(), NULL, &delegate);
67 ImageHolder image_holder3(GURL(), GURL(kIconUrl2), NULL, &delegate);
68 ImageHolder image_holder4(GURL(), GURL(), NULL, &delegate);
69
70 // Initially, image holder 4 with no URLs should report done, but no others.
71 EXPECT_FALSE(image_holder1.IsFetchingDone());
72 EXPECT_FALSE(image_holder2.IsFetchingDone());
73 EXPECT_FALSE(image_holder3.IsFetchingDone());
74 EXPECT_TRUE(image_holder4.IsFetchingDone());
75
76 // Put a real bitmap into "bitmap". 2x2 bitmap of green 32 bit pixels.
77 SkBitmap bitmap;
78 bitmap.setConfig(SkBitmap::kARGB_8888_Config, 2, 2);
79 bitmap.allocPixels();
80 bitmap.eraseColor(SK_ColorGREEN);
81
82 // Add the first icon, and image holder 2 should now also report done.
83 image_holder1.OnFetchComplete(GURL(kIconUrl1), &bitmap);
84 image_holder2.OnFetchComplete(GURL(kIconUrl1), &bitmap);
85 image_holder3.OnFetchComplete(GURL(kIconUrl1), &bitmap);
86 image_holder4.OnFetchComplete(GURL(kIconUrl1), &bitmap);
87 EXPECT_FALSE(image_holder1.IsFetchingDone());
88 EXPECT_TRUE(image_holder2.IsFetchingDone());
89 EXPECT_FALSE(image_holder3.IsFetchingDone());
90 EXPECT_TRUE(image_holder4.IsFetchingDone());
91
92 // Add the second image, and now all 4 should report done.
93 image_holder1.OnFetchComplete(GURL(kIconUrl2), &bitmap);
94 image_holder2.OnFetchComplete(GURL(kIconUrl2), &bitmap);
95 image_holder3.OnFetchComplete(GURL(kIconUrl2), &bitmap);
96 image_holder4.OnFetchComplete(GURL(kIconUrl2), &bitmap);
97 EXPECT_TRUE(image_holder1.IsFetchingDone());
98 EXPECT_TRUE(image_holder2.IsFetchingDone());
99 EXPECT_TRUE(image_holder3.IsFetchingDone());
100 EXPECT_TRUE(image_holder4.IsFetchingDone());
101 }
102
103 } // namespace notifier.
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698