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

Side by Side Diff: chrome/browser/notifications/sync_notifier/synced_notification_app_info_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: fix windows build 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
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/notifications/sync_notifier/sync_notifier_test_utils.h"
7 #include "chrome/browser/notifications/sync_notifier/synced_notification_app_inf o.h" 8 #include "chrome/browser/notifications/sync_notifier/synced_notification_app_inf o.h"
8 9 #include "chrome/browser/notifications/sync_notifier/synced_notification_app_inf o_service.h"
10 #include "sync/api/sync_error_factory.h"
9 #include "testing/gtest/include/gtest/gtest.h" 11 #include "testing/gtest/include/gtest/gtest.h"
10 12
11 namespace { 13 namespace {
12 14
13 static char kTestSendingServiceName[] = "Sending-Service"; 15 static char kTestSendingServiceName[] = "Sending-Service";
14 static char kTestAppId1[] = "TestAppId1"; 16 static char kTestAppId1[] = "TestAppId1";
15 static char kTestAppId2[] = "TestAppId2"; 17 static char kTestAppId2[] = "TestAppId2";
16 18
17 } // namespace 19 } // namespace
18 20
19 namespace notifier { 21 namespace notifier {
20 22
23 // Stub out the SyncedNotificationAppInfoService so we can verify that when
24 // bitmaps are fetched, the OnFetchComplete causes a call to
25 // OnBitmapFetchesDone.
26 class StubSyncedNotificationAppInfoService
27 : public SyncedNotificationAppInfoService {
28 public:
29 // Interface functions from SyncedNotificationAppInfoService
30 explicit StubSyncedNotificationAppInfoService(Profile* profile)
31 : SyncedNotificationAppInfoService(profile) {
32 on_bitmap_fetches_done_called_ = false;
33 }
34 virtual ~StubSyncedNotificationAppInfoService() {}
35 virtual void Shutdown() OVERRIDE{};
36 virtual syncer::SyncMergeResult MergeDataAndStartSyncing(
37 syncer::ModelType type,
38 const syncer::SyncDataList& initial_sync_data,
39 scoped_ptr<syncer::SyncChangeProcessor> sync_processor,
40 scoped_ptr<syncer::SyncErrorFactory> error_handler) OVERRIDE {
41 return syncer::SyncMergeResult(syncer::SYNCED_NOTIFICATION_APP_INFO);
42 }
43 virtual void StopSyncing(syncer::ModelType type) OVERRIDE{};
44 virtual syncer::SyncError ProcessSyncChanges(
45 const tracked_objects::Location& from_here,
46 const syncer::SyncChangeList& change_list) OVERRIDE {
47 return syncer::SyncError();
48 }
49 virtual syncer::SyncDataList GetAllSyncData(syncer::ModelType type) const
50 OVERRIDE {
51 return syncer::SyncDataList();
52 }
53 void ProcessIncomingAppInfoProtobuf(
54 const sync_pb::SyncedNotificationAppInfo& app_info) {}
55 void ProcessRemovedAppInfoProtobuf(
56 const sync_pb::SyncedNotificationAppInfo& app_info) {}
57 // Remember the arguments we saw in the most recent call.
58 virtual void OnBitmapFetchesDone(std::vector<std::string> added_app_ids,
59 std::vector<std::string> removed_app_ids)
60 OVERRIDE {
61 added_app_ids_ = added_app_ids;
62 removed_app_ids_ = removed_app_ids;
63 on_bitmap_fetches_done_called_ = true;
64 }
65 scoped_ptr<SyncedNotificationAppInfo>
66 CreateSyncedNotificationAppInfoFromProtobuf(
67 const sync_pb::SyncedNotificationAppInfo& app_info) {
68 return scoped_ptr<SyncedNotificationAppInfo>();
69 }
70 SyncedNotificationAppInfo* FindSyncedNotificationAppInfoByName(
71 const std::string& name) { return NULL; }
72 SyncedNotificationAppInfo* FindSyncedNotificationAppInfoByAppId(
73 const std::string& app_id) { return NULL; }
74 std::string FindSendingServiceNameFromAppId(const std::string app_id) {
75 return std::string();
76 }
77 std::vector<std::string> GetAllSendingServiceNames() {
78 std::vector<std::string> empty;
79 return empty;
80 }
81 void AddForTest(
82 scoped_ptr<notifier::SyncedNotificationAppInfo> sending_service_info) {}
83 static void set_avoid_bitmap_fetching_for_test(bool avoid) {}
84
85 // Probe functions to return data.
86 std::vector<std::string> added_app_ids() { return added_app_ids_; }
87 std::vector<std::string> removed_app_ids() { return removed_app_ids_; }
88 bool on_bitmap_fetches_done_called() {
89 return on_bitmap_fetches_done_called_;
90 }
91
92 private:
93 std::vector<std::string> added_app_ids_;
94 std::vector<std::string> removed_app_ids_;
95 bool on_bitmap_fetches_done_called_;
96 };
97
21 typedef testing::Test SyncedNotificationAppInfoTest; 98 typedef testing::Test SyncedNotificationAppInfoTest;
22 99
23 TEST_F(SyncedNotificationAppInfoTest, AddRemoveTest) { 100 TEST_F(SyncedNotificationAppInfoTest, AddRemoveTest) {
24 SyncedNotificationAppInfo app_info(kTestSendingServiceName); 101 SyncedNotificationAppInfo app_info(NULL, kTestSendingServiceName, NULL);
25 102
26 app_info.AddAppId(kTestAppId1); 103 app_info.AddAppId(kTestAppId1);
27 104
28 // Ensure the app id is found 105 // Ensure the app id is found
29 EXPECT_TRUE(app_info.HasAppId(kTestAppId1)); 106 EXPECT_TRUE(app_info.HasAppId(kTestAppId1));
30 107
31 // Ensure a second app id that has not been added is not found. 108 // Ensure a second app id that has not been added is not found.
32 EXPECT_FALSE(app_info.HasAppId(kTestAppId2)); 109 EXPECT_FALSE(app_info.HasAppId(kTestAppId2));
33 110
34 // Remove the first ID and ensure it is no longer found. 111 // Remove the first ID and ensure it is no longer found.
35 app_info.RemoveAppId(kTestAppId1); 112 app_info.RemoveAppId(kTestAppId1);
36 EXPECT_FALSE(app_info.HasAppId(kTestAppId1)); 113 EXPECT_FALSE(app_info.HasAppId(kTestAppId1));
37 } 114 }
38 115
39 TEST_F(SyncedNotificationAppInfoTest, GetAppIdListTest) { 116 TEST_F(SyncedNotificationAppInfoTest, GetAppIdListTest) {
40 SyncedNotificationAppInfo app_info(kTestSendingServiceName); 117 SyncedNotificationAppInfo app_info(NULL, kTestSendingServiceName, NULL);
41 118
42 // Add a few app infos. 119 // Add a few app infos.
43 app_info.AddAppId(kTestAppId1); 120 app_info.AddAppId(kTestAppId1);
44 app_info.AddAppId(kTestAppId2); 121 app_info.AddAppId(kTestAppId2);
45 122
46 std::vector<std::string> app_id_list; 123 std::vector<std::string> app_id_list;
47 app_info.GetAppIdList(&app_id_list); 124 app_info.GetAppIdList(&app_id_list);
48 125
49 EXPECT_EQ(std::string(kTestAppId1), app_id_list[0]); 126 EXPECT_EQ(std::string(kTestAppId1), app_id_list[0]);
50 EXPECT_EQ(std::string(kTestAppId2), app_id_list[1]); 127 EXPECT_EQ(std::string(kTestAppId2), app_id_list[1]);
51 } 128 }
52 129
130 TEST_F(SyncedNotificationAppInfoTest, AddBitmapToFetchQueueTest) {
131 SyncedNotificationAppInfo app_info(NULL, kTestSendingServiceName, NULL);
132
133 // Add two bitmaps to the queue.
134 app_info.AddBitmapToFetchQueue(GURL(kIconUrl1));
135 app_info.AddBitmapToFetchQueue(GURL(kIconUrl2));
136
137 EXPECT_EQ(GURL(kIconUrl1), app_info.fetchers_[0]->url());
138 EXPECT_EQ(GURL(kIconUrl2), app_info.fetchers_[1]->url());
139 EXPECT_EQ(static_cast<unsigned int>(2), app_info.fetchers_.size());
140
141 // Adding a dup of an existing URL shouldn't change anything.
142 app_info.AddBitmapToFetchQueue(GURL(kIconUrl2));
143 EXPECT_EQ(GURL(kIconUrl1), app_info.fetchers_[0]->url());
144 EXPECT_EQ(GURL(kIconUrl2), app_info.fetchers_[1]->url());
145 EXPECT_EQ(static_cast<unsigned int>(2), app_info.fetchers_.size());
146 }
147
148 TEST_F(SyncedNotificationAppInfoTest, OnFetchCompleteTest) {
149 StubSyncedNotificationAppInfoService
150 stub_synced_notification_app_info_service(NULL);
151 SyncedNotificationAppInfo app_info(
152 NULL,
153 kTestSendingServiceName,
154 &stub_synced_notification_app_info_service);
155
156 // Set up the internal state that we expect.
157 app_info.settings_low_dpi_icon_url_ = GURL(kIconUrl1);
158 app_info.settings_high_dpi_icon_url_ = GURL(kIconUrl2);
159 app_info.monochrome_low_dpi_icon_url_ = GURL(kIconUrl3);
160 app_info.monochrome_high_dpi_icon_url_ = GURL(kIconUrl4);
161
162 // Add the bitmaps to the queue for us to match up.
163 app_info.AddBitmapToFetchQueue(GURL(kIconUrl1));
164 app_info.AddBitmapToFetchQueue(GURL(kIconUrl2));
165 app_info.AddBitmapToFetchQueue(GURL(kIconUrl3));
166 app_info.AddBitmapToFetchQueue(GURL(kIconUrl4));
167
168 // Put some realistic looking bitmap data into the url_fetcher.
169 SkBitmap bitmap;
170
171 // Put a real bitmap into "bitmap". 2x2 bitmap of green 32 bit pixels.
172 bitmap.setConfig(SkBitmap::kARGB_8888_Config, 2, 2);
173 bitmap.allocPixels();
174 bitmap.eraseColor(SK_ColorGREEN);
175
176 app_info.OnFetchComplete(GURL(kIconUrl1), &bitmap);
177 app_info.OnFetchComplete(GURL(kIconUrl2), &bitmap);
178 app_info.OnFetchComplete(GURL(kIconUrl3), &bitmap);
179 app_info.OnFetchComplete(GURL(kIconUrl4), &bitmap);
180
181 // Expect that the app icon has some data in it.
182 EXPECT_FALSE(app_info.icon().IsEmpty());
183
184 // Expect that we reported the fetches all done to the owning service.
185 EXPECT_TRUE(stub_synced_notification_app_info_service.
186 on_bitmap_fetches_done_called());
187
188 // TODO(petewil): For more advanced testing, see what happens if one of the
189 // bitmap urls is a duplicate.
190 }
191
192 // Same as above, but with a valid but empty bitmap
193 TEST_F(SyncedNotificationAppInfoTest, EmptyBitmapTest) {
194 StubSyncedNotificationAppInfoService
195 stub_synced_notification_app_info_service(NULL);
196 SyncedNotificationAppInfo app_info(
197 NULL,
198 kTestSendingServiceName,
199 &stub_synced_notification_app_info_service);
200
201 // Set up the internal state that FetchBitmaps() would have set.
202 app_info.settings_low_dpi_icon_url_ = GURL(kIconUrl1);
203 app_info.settings_high_dpi_icon_url_ = GURL(kIconUrl2);
204 app_info.monochrome_low_dpi_icon_url_ = GURL(kIconUrl3);
205 app_info.monochrome_high_dpi_icon_url_ = GURL(kIconUrl4);
206
207 // Add the bitmaps to the queue for us to match up.
208 app_info.AddBitmapToFetchQueue(GURL(kIconUrl1));
209 app_info.AddBitmapToFetchQueue(GURL(kImageUrl1));
210 app_info.AddBitmapToFetchQueue(GURL(kButtonOneIconUrl));
211 app_info.AddBitmapToFetchQueue(GURL(kButtonTwoIconUrl));
212
213 // Put some realistic looking bitmap data into the url_fetcher.
214 SkBitmap empty_bitmap;
215
216 // Put a null bitmap into "bitmap". 2x2 bitmap of green 32 bit pixels.
217 empty_bitmap.setConfig(SkBitmap::kARGB_8888_Config, 0, 0);
218 empty_bitmap.allocPixels();
219 empty_bitmap.eraseColor(SK_ColorGREEN);
220
221 app_info.OnFetchComplete(GURL(kIconUrl1), &empty_bitmap);
222 app_info.OnFetchComplete(GURL(kIconUrl2), &empty_bitmap);
223 app_info.OnFetchComplete(GURL(kIconUrl3), &empty_bitmap);
224 app_info.OnFetchComplete(GURL(kIconUrl4), &empty_bitmap);
225
226 // Expect that we reported the fetches all done to the owning service.
227 EXPECT_TRUE(stub_synced_notification_app_info_service.
228 on_bitmap_fetches_done_called());
229 }
230
231 TEST_F(SyncedNotificationAppInfoTest, AreAllBitmapsFetchedTest) {
232 SyncedNotificationAppInfo app_info(NULL, kTestSendingServiceName, NULL);
233 app_info.settings_low_dpi_icon_url_ = GURL(kTestIconUrl);
234 app_info.settings_high_dpi_icon_url_ = GURL(kTestIconUrl);
235
236 app_info.settings_low_dpi_icon_fetched_ = true;
237
238 EXPECT_FALSE(app_info.AreAllBitmapsFetched());
239
240 // Set the remaining bitmaps that we have URLs for.
241 app_info.settings_high_dpi_icon_fetched_ = true;
242
243 EXPECT_TRUE(app_info.AreAllBitmapsFetched());
244 }
245
53 } // namespace notifier 246 } // namespace notifier
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698