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..ab5f20dbc298fbad7bfd3c69ddf67d32724056b0 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 { |
@@ -18,10 +20,85 @@ static char kTestAppId2[] = "TestAppId2"; |
namespace notifier { |
+// Stub out the SyncedNotificationAppInfoService so we can verify that when |
+// bitmaps are fetched, the OnFetchComplete causes a call to |
+// OnBitmapFetchesDone. |
+class StubSyncedNotificationAppInfoService |
+ : public SyncedNotificationAppInfoService { |
+ public: |
+ // Interface functions from SyncedNotificationAppInfoService |
+ explicit StubSyncedNotificationAppInfoService(Profile* profile) |
+ : SyncedNotificationAppInfoService(profile) { |
+ on_bitmap_fetches_done_called_ = false; |
+ } |
+ virtual ~StubSyncedNotificationAppInfoService() {} |
+ virtual void Shutdown() OVERRIDE{}; |
+ virtual syncer::SyncMergeResult MergeDataAndStartSyncing( |
+ syncer::ModelType type, |
+ const syncer::SyncDataList& initial_sync_data, |
+ scoped_ptr<syncer::SyncChangeProcessor> sync_processor, |
+ scoped_ptr<syncer::SyncErrorFactory> error_handler) OVERRIDE { |
+ return syncer::SyncMergeResult(syncer::SYNCED_NOTIFICATION_APP_INFO); |
+ } |
+ virtual void StopSyncing(syncer::ModelType type) OVERRIDE{}; |
+ virtual syncer::SyncError ProcessSyncChanges( |
+ const tracked_objects::Location& from_here, |
+ const syncer::SyncChangeList& change_list) OVERRIDE { |
+ return syncer::SyncError(); |
+ } |
+ virtual syncer::SyncDataList GetAllSyncData(syncer::ModelType type) const |
+ OVERRIDE { |
+ return syncer::SyncDataList(); |
+ } |
+ void ProcessIncomingAppInfoProtobuf( |
+ const sync_pb::SyncedNotificationAppInfo& app_info) {} |
+ void ProcessRemovedAppInfoProtobuf( |
+ const sync_pb::SyncedNotificationAppInfo& app_info) {} |
+ // Remember the arguments we saw in the most recent call. |
+ virtual void OnBitmapFetchesDone(std::vector<std::string> added_app_ids, |
+ std::vector<std::string> removed_app_ids) |
+ OVERRIDE { |
+ added_app_ids_ = added_app_ids; |
+ removed_app_ids_ = removed_app_ids; |
+ on_bitmap_fetches_done_called_ = true; |
+ } |
+ scoped_ptr<SyncedNotificationAppInfo> |
+ CreateSyncedNotificationAppInfoFromProtobuf( |
+ const sync_pb::SyncedNotificationAppInfo& app_info) { |
+ return scoped_ptr<SyncedNotificationAppInfo>(); |
+ } |
+ SyncedNotificationAppInfo* FindSyncedNotificationAppInfoByName( |
+ const std::string& name) { return NULL; } |
+ SyncedNotificationAppInfo* FindSyncedNotificationAppInfoByAppId( |
+ const std::string& app_id) { return NULL; } |
+ std::string FindSendingServiceNameFromAppId(const std::string app_id) { |
+ return std::string(); |
+ } |
+ std::vector<std::string> GetAllSendingServiceNames() { |
+ std::vector<std::string> empty; |
+ return empty; |
+ } |
+ void AddForTest( |
+ scoped_ptr<notifier::SyncedNotificationAppInfo> sending_service_info) {} |
+ static void set_avoid_bitmap_fetching_for_test(bool avoid) {} |
+ |
+ // Probe functions to return data. |
+ std::vector<std::string> added_app_ids() { return added_app_ids_; } |
+ std::vector<std::string> removed_app_ids() { return removed_app_ids_; } |
+ bool on_bitmap_fetches_done_called() { |
+ return on_bitmap_fetches_done_called_; |
+ } |
+ |
+ private: |
+ std::vector<std::string> added_app_ids_; |
+ std::vector<std::string> removed_app_ids_; |
+ bool on_bitmap_fetches_done_called_; |
+}; |
+ |
typedef testing::Test SyncedNotificationAppInfoTest; |
TEST_F(SyncedNotificationAppInfoTest, AddRemoveTest) { |
- SyncedNotificationAppInfo app_info(kTestSendingServiceName); |
+ SyncedNotificationAppInfo app_info(NULL, kTestSendingServiceName, NULL); |
app_info.AddAppId(kTestAppId1); |
@@ -37,7 +114,7 @@ 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); |
@@ -50,4 +127,120 @@ TEST_F(SyncedNotificationAppInfoTest, GetAppIdListTest) { |
EXPECT_EQ(std::string(kTestAppId2), app_id_list[1]); |
} |
+TEST_F(SyncedNotificationAppInfoTest, AddBitmapToFetchQueueTest) { |
+ SyncedNotificationAppInfo app_info(NULL, kTestSendingServiceName, NULL); |
+ |
+ // Add two bitmaps to the queue. |
+ app_info.AddBitmapToFetchQueue(GURL(kIconUrl1)); |
+ app_info.AddBitmapToFetchQueue(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.AddBitmapToFetchQueue(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.AddBitmapToFetchQueue(GURL(kIconUrl1)); |
+ app_info.AddBitmapToFetchQueue(GURL(kIconUrl2)); |
+ app_info.AddBitmapToFetchQueue(GURL(kIconUrl3)); |
+ app_info.AddBitmapToFetchQueue(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.AddBitmapToFetchQueue(GURL(kIconUrl1)); |
+ app_info.AddBitmapToFetchQueue(GURL(kImageUrl1)); |
+ app_info.AddBitmapToFetchQueue(GURL(kButtonOneIconUrl)); |
+ app_info.AddBitmapToFetchQueue(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 |