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
3 // found in the LICENSE file.
7 #include "chrome/browser/notifications/sync_notifier/sync_notifier_test_utils.h"
8 #include "chrome/browser/notifications/sync_notifier/synced_notification_app_info.h"
9 #include "chrome/browser/notifications/sync_notifier/synced_notification_app_info_service.h"
10 #include "sync/api/sync_error_factory.h"
11 #include "testing/gtest/include/gtest/gtest.h"
15 static char kTestSendingServiceName[] = "Sending-Service";
16 static char kTestAppId1[] = "TestAppId1";
17 static char kTestAppId2[] = "TestAppId2";
23 typedef testing::Test SyncedNotificationAppInfoTest;
25 TEST_F(SyncedNotificationAppInfoTest, AddRemoveTest) {
26 SyncedNotificationAppInfo app_info(NULL, kTestSendingServiceName, NULL);
28 app_info.AddAppId(kTestAppId1);
30 // Ensure the app id is found
31 EXPECT_TRUE(app_info.HasAppId(kTestAppId1));
33 // Ensure a second app id that has not been added is not found.
34 EXPECT_FALSE(app_info.HasAppId(kTestAppId2));
36 // Remove the first ID and ensure it is no longer found.
37 app_info.RemoveAppId(kTestAppId1);
38 EXPECT_FALSE(app_info.HasAppId(kTestAppId1));
41 TEST_F(SyncedNotificationAppInfoTest, GetAppIdListTest) {
42 SyncedNotificationAppInfo app_info(NULL, kTestSendingServiceName, NULL);
44 // Add a few app infos.
45 app_info.AddAppId(kTestAppId1);
46 app_info.AddAppId(kTestAppId2);
48 std::vector<std::string> app_id_list = app_info.GetAppIdList();
50 EXPECT_EQ(std::string(kTestAppId1), app_id_list[0]);
51 EXPECT_EQ(std::string(kTestAppId2), app_id_list[1]);
54 TEST_F(SyncedNotificationAppInfoTest, OnFetchCompleteTest) {
55 StubSyncedNotificationAppInfoService
56 stub_synced_notification_app_info_service(NULL);
57 SyncedNotificationAppInfo app_info(
59 kTestSendingServiceName,
60 &stub_synced_notification_app_info_service);
62 app_info.OnFetchComplete();
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());
70 TEST_F(SyncedNotificationAppInfoTest, AreAllBitmapsFetchedTest) {
71 SyncedNotificationAppInfo app_info(NULL, kTestSendingServiceName, NULL);
73 // Before we have any images to fetch, we should report all fetching is done.
74 EXPECT_TRUE(app_info.AreAllBitmapsFetched());
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());
80 // Put a real bitmap into "bitmap". 2x2 bitmap of green 32 bit pixels.
82 bitmap.setConfig(SkBitmap::kARGB_8888_Config, 2, 2);
84 bitmap.eraseColor(SK_ColorGREEN);
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());
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());
95 } // namespace notifier