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, CreateBitmapFetcherTest) { |
| 55 SyncedNotificationAppInfo app_info(NULL, kTestSendingServiceName, NULL); |
| 56 |
| 57 // Add two bitmaps to the queue. |
| 58 app_info.CreateBitmapFetcher(GURL(kIconUrl1)); |
| 59 app_info.CreateBitmapFetcher(GURL(kIconUrl2)); |
| 60 |
| 61 EXPECT_EQ(GURL(kIconUrl1), app_info.fetchers_[0]->url()); |
| 62 EXPECT_EQ(GURL(kIconUrl2), app_info.fetchers_[1]->url()); |
| 63 EXPECT_EQ(static_cast<unsigned int>(2), app_info.fetchers_.size()); |
| 64 |
| 65 // Adding a dup of an existing URL shouldn't change anything. |
| 66 app_info.CreateBitmapFetcher(GURL(kIconUrl2)); |
| 67 EXPECT_EQ(GURL(kIconUrl1), app_info.fetchers_[0]->url()); |
| 68 EXPECT_EQ(GURL(kIconUrl2), app_info.fetchers_[1]->url()); |
| 69 EXPECT_EQ(static_cast<unsigned int>(2), app_info.fetchers_.size()); |
| 70 } |
| 71 |
| 72 TEST_F(SyncedNotificationAppInfoTest, OnFetchCompleteTest) { |
| 73 StubSyncedNotificationAppInfoService |
| 74 stub_synced_notification_app_info_service(NULL); |
| 75 SyncedNotificationAppInfo app_info( |
| 76 NULL, |
| 77 kTestSendingServiceName, |
| 78 &stub_synced_notification_app_info_service); |
| 79 |
| 80 // Set up the internal state that we expect. |
| 81 app_info.settings_low_dpi_icon_url_ = GURL(kIconUrl1); |
| 82 app_info.settings_high_dpi_icon_url_ = GURL(kIconUrl2); |
| 83 app_info.monochrome_low_dpi_icon_url_ = GURL(kIconUrl3); |
| 84 app_info.monochrome_high_dpi_icon_url_ = GURL(kIconUrl4); |
| 85 |
| 86 // Add the bitmaps to the queue for us to match up. |
| 87 app_info.CreateBitmapFetcher(GURL(kIconUrl1)); |
| 88 app_info.CreateBitmapFetcher(GURL(kIconUrl2)); |
| 89 app_info.CreateBitmapFetcher(GURL(kIconUrl3)); |
| 90 app_info.CreateBitmapFetcher(GURL(kIconUrl4)); |
| 91 |
| 92 // Put some realistic looking bitmap data into the url_fetcher. |
| 93 SkBitmap bitmap; |
| 94 |
| 95 // Put a real bitmap into "bitmap". 2x2 bitmap of green 32 bit pixels. |
| 96 bitmap.setConfig(SkBitmap::kARGB_8888_Config, 2, 2); |
| 97 bitmap.allocPixels(); |
| 98 bitmap.eraseColor(SK_ColorGREEN); |
| 99 |
| 100 app_info.OnFetchComplete(GURL(kIconUrl1), &bitmap); |
| 101 app_info.OnFetchComplete(GURL(kIconUrl2), &bitmap); |
| 102 app_info.OnFetchComplete(GURL(kIconUrl3), &bitmap); |
| 103 app_info.OnFetchComplete(GURL(kIconUrl4), &bitmap); |
| 104 |
| 105 // Expect that the app icon has some data in it. |
| 106 EXPECT_FALSE(app_info.icon().IsEmpty()); |
| 107 |
| 108 // Expect that we reported the fetches all done to the owning service. |
| 109 EXPECT_TRUE(stub_synced_notification_app_info_service. |
| 110 on_bitmap_fetches_done_called()); |
| 111 |
| 112 // TODO(petewil): For more advanced testing, see what happens if one of the |
| 113 // bitmap urls is a duplicate. |
| 114 } |
| 115 |
| 116 // Same as above, but with a valid but empty bitmap |
| 117 TEST_F(SyncedNotificationAppInfoTest, EmptyBitmapTest) { |
| 118 StubSyncedNotificationAppInfoService |
| 119 stub_synced_notification_app_info_service(NULL); |
| 120 SyncedNotificationAppInfo app_info( |
| 121 NULL, |
| 122 kTestSendingServiceName, |
| 123 &stub_synced_notification_app_info_service); |
| 124 |
| 125 // Set up the internal state that FetchBitmaps() would have set. |
| 126 app_info.settings_low_dpi_icon_url_ = GURL(kIconUrl1); |
| 127 app_info.settings_high_dpi_icon_url_ = GURL(kIconUrl2); |
| 128 app_info.monochrome_low_dpi_icon_url_ = GURL(kIconUrl3); |
| 129 app_info.monochrome_high_dpi_icon_url_ = GURL(kIconUrl4); |
| 130 |
| 131 // Add the bitmaps to the queue for us to match up. |
| 132 app_info.CreateBitmapFetcher(GURL(kIconUrl1)); |
| 133 app_info.CreateBitmapFetcher(GURL(kImageUrl1)); |
| 134 app_info.CreateBitmapFetcher(GURL(kButtonOneIconUrl)); |
| 135 app_info.CreateBitmapFetcher(GURL(kButtonTwoIconUrl)); |
| 136 |
| 137 // Put some realistic looking bitmap data into the url_fetcher. |
| 138 SkBitmap empty_bitmap; |
| 139 |
| 140 // Put a null bitmap into "bitmap". 2x2 bitmap of green 32 bit pixels. |
| 141 empty_bitmap.setConfig(SkBitmap::kARGB_8888_Config, 0, 0); |
| 142 empty_bitmap.allocPixels(); |
| 143 empty_bitmap.eraseColor(SK_ColorGREEN); |
| 144 |
| 145 app_info.OnFetchComplete(GURL(kIconUrl1), &empty_bitmap); |
| 146 app_info.OnFetchComplete(GURL(kIconUrl2), &empty_bitmap); |
| 147 app_info.OnFetchComplete(GURL(kIconUrl3), &empty_bitmap); |
| 148 app_info.OnFetchComplete(GURL(kIconUrl4), &empty_bitmap); |
| 149 |
| 150 // Expect that we reported the fetches all done to the owning service. |
| 151 EXPECT_TRUE(stub_synced_notification_app_info_service. |
| 152 on_bitmap_fetches_done_called()); |
| 153 } |
| 154 |
| 155 TEST_F(SyncedNotificationAppInfoTest, AreAllBitmapsFetchedTest) { |
| 156 SyncedNotificationAppInfo app_info(NULL, kTestSendingServiceName, NULL); |
| 157 app_info.settings_low_dpi_icon_url_ = GURL(kTestIconUrl); |
| 158 app_info.settings_high_dpi_icon_url_ = GURL(kTestIconUrl); |
| 159 |
| 160 app_info.settings_low_dpi_icon_fetched_ = true; |
| 161 |
| 162 EXPECT_FALSE(app_info.AreAllBitmapsFetched()); |
| 163 |
| 164 // Set the remaining bitmaps that we have URLs for. |
| 165 app_info.settings_high_dpi_icon_fetched_ = true; |
| 166 |
| 167 EXPECT_TRUE(app_info.AreAllBitmapsFetched()); |
| 168 } |
| 169 |
53 } // namespace notifier | 170 } // namespace notifier |
OLD | NEW |