Index: chrome/browser/notifications/sync_notifier/synced_notification_app_info_unittest.cc |
diff --git a/chrome/browser/notifications/sync_notifier/synced_notification_app_info_unittest.cc b/chrome/browser/notifications/sync_notifier/synced_notification_app_info_unittest.cc |
index b6482595a9e9005a1c9ae47db5c2edab0066d5af..eee346c1e676bf9c8622f5e8fdd05a5dd103bf19 100644 |
--- a/chrome/browser/notifications/sync_notifier/synced_notification_app_info_unittest.cc |
+++ b/chrome/browser/notifications/sync_notifier/synced_notification_app_info_unittest.cc |
@@ -4,8 +4,10 @@ |
#include <string> |
+#include "chrome/browser/notifications/sync_notifier/sync_notifier_test_utils.h" |
#include "chrome/browser/notifications/sync_notifier/synced_notification_app_info.h" |
- |
+#include "chrome/browser/notifications/sync_notifier/synced_notification_app_info_service.h" |
+#include "sync/api/sync_error_factory.h" |
#include "testing/gtest/include/gtest/gtest.h" |
namespace { |
@@ -21,7 +23,7 @@ namespace notifier { |
typedef testing::Test SyncedNotificationAppInfoTest; |
TEST_F(SyncedNotificationAppInfoTest, AddRemoveTest) { |
- SyncedNotificationAppInfo app_info(kTestSendingServiceName); |
+ SyncedNotificationAppInfo app_info(NULL, kTestSendingServiceName, NULL); |
app_info.AddAppId(kTestAppId1); |
@@ -37,17 +39,132 @@ TEST_F(SyncedNotificationAppInfoTest, AddRemoveTest) { |
} |
TEST_F(SyncedNotificationAppInfoTest, GetAppIdListTest) { |
- SyncedNotificationAppInfo app_info(kTestSendingServiceName); |
+ SyncedNotificationAppInfo app_info(NULL, kTestSendingServiceName, NULL); |
// Add a few app infos. |
app_info.AddAppId(kTestAppId1); |
app_info.AddAppId(kTestAppId2); |
- std::vector<std::string> app_id_list; |
- app_info.GetAppIdList(&app_id_list); |
+ std::vector<std::string> app_id_list = app_info.GetAppIdList(); |
EXPECT_EQ(std::string(kTestAppId1), app_id_list[0]); |
EXPECT_EQ(std::string(kTestAppId2), app_id_list[1]); |
} |
+TEST_F(SyncedNotificationAppInfoTest, CreateBitmapFetcherTest) { |
+ SyncedNotificationAppInfo app_info(NULL, kTestSendingServiceName, NULL); |
+ |
+ // Add two bitmaps to the queue. |
+ app_info.CreateBitmapFetcher(GURL(kIconUrl1)); |
+ app_info.CreateBitmapFetcher(GURL(kIconUrl2)); |
+ |
+ EXPECT_EQ(GURL(kIconUrl1), app_info.fetchers_[0]->url()); |
+ EXPECT_EQ(GURL(kIconUrl2), app_info.fetchers_[1]->url()); |
+ EXPECT_EQ(static_cast<unsigned int>(2), app_info.fetchers_.size()); |
+ |
+ // Adding a dup of an existing URL shouldn't change anything. |
+ app_info.CreateBitmapFetcher(GURL(kIconUrl2)); |
+ EXPECT_EQ(GURL(kIconUrl1), app_info.fetchers_[0]->url()); |
+ EXPECT_EQ(GURL(kIconUrl2), app_info.fetchers_[1]->url()); |
+ EXPECT_EQ(static_cast<unsigned int>(2), app_info.fetchers_.size()); |
+} |
+ |
+TEST_F(SyncedNotificationAppInfoTest, OnFetchCompleteTest) { |
+ StubSyncedNotificationAppInfoService |
+ stub_synced_notification_app_info_service(NULL); |
+ SyncedNotificationAppInfo app_info( |
+ NULL, |
+ kTestSendingServiceName, |
+ &stub_synced_notification_app_info_service); |
+ |
+ // Set up the internal state that we expect. |
+ app_info.settings_low_dpi_icon_url_ = GURL(kIconUrl1); |
+ app_info.settings_high_dpi_icon_url_ = GURL(kIconUrl2); |
+ app_info.monochrome_low_dpi_icon_url_ = GURL(kIconUrl3); |
+ app_info.monochrome_high_dpi_icon_url_ = GURL(kIconUrl4); |
+ |
+ // Add the bitmaps to the queue for us to match up. |
+ app_info.CreateBitmapFetcher(GURL(kIconUrl1)); |
+ app_info.CreateBitmapFetcher(GURL(kIconUrl2)); |
+ app_info.CreateBitmapFetcher(GURL(kIconUrl3)); |
+ app_info.CreateBitmapFetcher(GURL(kIconUrl4)); |
+ |
+ // Put some realistic looking bitmap data into the url_fetcher. |
+ SkBitmap bitmap; |
+ |
+ // Put a real bitmap into "bitmap". 2x2 bitmap of green 32 bit pixels. |
+ bitmap.setConfig(SkBitmap::kARGB_8888_Config, 2, 2); |
+ bitmap.allocPixels(); |
+ bitmap.eraseColor(SK_ColorGREEN); |
+ |
+ app_info.OnFetchComplete(GURL(kIconUrl1), &bitmap); |
+ app_info.OnFetchComplete(GURL(kIconUrl2), &bitmap); |
+ app_info.OnFetchComplete(GURL(kIconUrl3), &bitmap); |
+ app_info.OnFetchComplete(GURL(kIconUrl4), &bitmap); |
+ |
+ // Expect that the app icon has some data in it. |
+ EXPECT_FALSE(app_info.icon().IsEmpty()); |
+ |
+ // Expect that we reported the fetches all done to the owning service. |
+ EXPECT_TRUE(stub_synced_notification_app_info_service. |
+ on_bitmap_fetches_done_called()); |
+ |
+ // TODO(petewil): For more advanced testing, see what happens if one of the |
+ // bitmap urls is a duplicate. |
+} |
+ |
+// Same as above, but with a valid but empty bitmap |
+TEST_F(SyncedNotificationAppInfoTest, EmptyBitmapTest) { |
+ StubSyncedNotificationAppInfoService |
+ stub_synced_notification_app_info_service(NULL); |
+ SyncedNotificationAppInfo app_info( |
+ NULL, |
+ kTestSendingServiceName, |
+ &stub_synced_notification_app_info_service); |
+ |
+ // Set up the internal state that FetchBitmaps() would have set. |
+ app_info.settings_low_dpi_icon_url_ = GURL(kIconUrl1); |
+ app_info.settings_high_dpi_icon_url_ = GURL(kIconUrl2); |
+ app_info.monochrome_low_dpi_icon_url_ = GURL(kIconUrl3); |
+ app_info.monochrome_high_dpi_icon_url_ = GURL(kIconUrl4); |
+ |
+ // Add the bitmaps to the queue for us to match up. |
+ app_info.CreateBitmapFetcher(GURL(kIconUrl1)); |
+ app_info.CreateBitmapFetcher(GURL(kImageUrl1)); |
+ app_info.CreateBitmapFetcher(GURL(kButtonOneIconUrl)); |
+ app_info.CreateBitmapFetcher(GURL(kButtonTwoIconUrl)); |
+ |
+ // Put some realistic looking bitmap data into the url_fetcher. |
+ SkBitmap empty_bitmap; |
+ |
+ // Put a null bitmap into "bitmap". 2x2 bitmap of green 32 bit pixels. |
+ empty_bitmap.setConfig(SkBitmap::kARGB_8888_Config, 0, 0); |
+ empty_bitmap.allocPixels(); |
+ empty_bitmap.eraseColor(SK_ColorGREEN); |
+ |
+ app_info.OnFetchComplete(GURL(kIconUrl1), &empty_bitmap); |
+ app_info.OnFetchComplete(GURL(kIconUrl2), &empty_bitmap); |
+ app_info.OnFetchComplete(GURL(kIconUrl3), &empty_bitmap); |
+ app_info.OnFetchComplete(GURL(kIconUrl4), &empty_bitmap); |
+ |
+ // Expect that we reported the fetches all done to the owning service. |
+ EXPECT_TRUE(stub_synced_notification_app_info_service. |
+ on_bitmap_fetches_done_called()); |
+} |
+ |
+TEST_F(SyncedNotificationAppInfoTest, AreAllBitmapsFetchedTest) { |
+ SyncedNotificationAppInfo app_info(NULL, kTestSendingServiceName, NULL); |
+ app_info.settings_low_dpi_icon_url_ = GURL(kTestIconUrl); |
+ app_info.settings_high_dpi_icon_url_ = GURL(kTestIconUrl); |
+ |
+ app_info.settings_low_dpi_icon_fetched_ = true; |
+ |
+ EXPECT_FALSE(app_info.AreAllBitmapsFetched()); |
+ |
+ // Set the remaining bitmaps that we have URLs for. |
+ app_info.settings_high_dpi_icon_fetched_ = true; |
+ |
+ EXPECT_TRUE(app_info.AreAllBitmapsFetched()); |
+} |
+ |
} // namespace notifier |