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/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 |
21 typedef testing::Test SyncedNotificationAppInfoTest; | 23 typedef testing::Test SyncedNotificationAppInfoTest; |
22 | 24 |
23 TEST_F(SyncedNotificationAppInfoTest, AddRemoveTest) { | 25 TEST_F(SyncedNotificationAppInfoTest, AddRemoveTest) { |
24 SyncedNotificationAppInfo app_info(kTestSendingServiceName); | 26 SyncedNotificationAppInfo app_info(NULL, kTestSendingServiceName, NULL); |
25 | 27 |
26 app_info.AddAppId(kTestAppId1); | 28 app_info.AddAppId(kTestAppId1); |
27 | 29 |
28 // Ensure the app id is found | 30 // Ensure the app id is found |
29 EXPECT_TRUE(app_info.HasAppId(kTestAppId1)); | 31 EXPECT_TRUE(app_info.HasAppId(kTestAppId1)); |
30 | 32 |
31 // Ensure a second app id that has not been added is not found. | 33 // Ensure a second app id that has not been added is not found. |
32 EXPECT_FALSE(app_info.HasAppId(kTestAppId2)); | 34 EXPECT_FALSE(app_info.HasAppId(kTestAppId2)); |
33 | 35 |
34 // Remove the first ID and ensure it is no longer found. | 36 // Remove the first ID and ensure it is no longer found. |
35 app_info.RemoveAppId(kTestAppId1); | 37 app_info.RemoveAppId(kTestAppId1); |
36 EXPECT_FALSE(app_info.HasAppId(kTestAppId1)); | 38 EXPECT_FALSE(app_info.HasAppId(kTestAppId1)); |
37 } | 39 } |
38 | 40 |
39 TEST_F(SyncedNotificationAppInfoTest, GetAppIdListTest) { | 41 TEST_F(SyncedNotificationAppInfoTest, GetAppIdListTest) { |
40 SyncedNotificationAppInfo app_info(kTestSendingServiceName); | 42 SyncedNotificationAppInfo app_info(NULL, kTestSendingServiceName, NULL); |
41 | 43 |
42 // Add a few app infos. | 44 // Add a few app infos. |
43 app_info.AddAppId(kTestAppId1); | 45 app_info.AddAppId(kTestAppId1); |
44 app_info.AddAppId(kTestAppId2); | 46 app_info.AddAppId(kTestAppId2); |
45 | 47 |
46 std::vector<std::string> app_id_list; | 48 std::vector<std::string> app_id_list = app_info.GetAppIdList(); |
47 app_info.GetAppIdList(&app_id_list); | |
48 | 49 |
49 EXPECT_EQ(std::string(kTestAppId1), app_id_list[0]); | 50 EXPECT_EQ(std::string(kTestAppId1), app_id_list[0]); |
50 EXPECT_EQ(std::string(kTestAppId2), app_id_list[1]); | 51 EXPECT_EQ(std::string(kTestAppId2), app_id_list[1]); |
51 } | 52 } |
52 | 53 |
| 54 TEST_F(SyncedNotificationAppInfoTest, OnFetchCompleteTest) { |
| 55 StubSyncedNotificationAppInfoService |
| 56 stub_synced_notification_app_info_service(NULL); |
| 57 SyncedNotificationAppInfo app_info( |
| 58 NULL, |
| 59 kTestSendingServiceName, |
| 60 &stub_synced_notification_app_info_service); |
| 61 |
| 62 app_info.OnFetchComplete(); |
| 63 |
| 64 // Expect that we reported the fetches all done to the owning service. |
| 65 EXPECT_TRUE(stub_synced_notification_app_info_service. |
| 66 on_bitmap_fetches_done_called()); |
| 67 |
| 68 } |
| 69 |
| 70 TEST_F(SyncedNotificationAppInfoTest, AreAllBitmapsFetchedTest) { |
| 71 SyncedNotificationAppInfo app_info(NULL, kTestSendingServiceName, NULL); |
| 72 |
| 73 // Before we have any images to fetch, we should report all fetching is done. |
| 74 EXPECT_TRUE(app_info.AreAllBitmapsFetched()); |
| 75 |
| 76 // Add some bitmaps to fetch, we should report fetching is not done. |
| 77 app_info.SetSettingsURLs(GURL(kIconUrl1), GURL(kIconUrl2)); |
| 78 EXPECT_FALSE(app_info.AreAllBitmapsFetched()); |
| 79 |
| 80 // Put a real bitmap into "bitmap". 2x2 bitmap of green 32 bit pixels. |
| 81 SkBitmap bitmap; |
| 82 bitmap.setConfig(SkBitmap::kARGB_8888_Config, 2, 2); |
| 83 bitmap.allocPixels(); |
| 84 bitmap.eraseColor(SK_ColorGREEN); |
| 85 |
| 86 // Now put in one bitmap, we are not done yet. |
| 87 app_info.settings_holder_->OnFetchComplete(GURL(kIconUrl1), &bitmap); |
| 88 EXPECT_FALSE(app_info.AreAllBitmapsFetched()); |
| 89 |
| 90 // Add a second bitmap, and now we should report done. |
| 91 app_info.settings_holder_->OnFetchComplete(GURL(kIconUrl2), &bitmap); |
| 92 EXPECT_TRUE(app_info.AreAllBitmapsFetched()); |
| 93 } |
| 94 |
53 } // namespace notifier | 95 } // namespace notifier |
OLD | NEW |