Upstream version 9.37.197.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / notifications / sync_notifier / synced_notification_app_info_unittest.cc
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.
4
5 #include <string>
6
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"
12
13 namespace {
14
15 static char kTestSendingServiceName[] = "Sending-Service";
16 static char kTestAppId1[] = "TestAppId1";
17 static char kTestAppId2[] = "TestAppId2";
18
19 }  // namespace
20
21 namespace notifier {
22
23 typedef testing::Test SyncedNotificationAppInfoTest;
24
25 TEST_F(SyncedNotificationAppInfoTest, AddRemoveTest) {
26   SyncedNotificationAppInfo app_info(NULL, kTestSendingServiceName, NULL);
27
28   app_info.AddAppId(kTestAppId1);
29
30   // Ensure the app id is found
31   EXPECT_TRUE(app_info.HasAppId(kTestAppId1));
32
33   // Ensure a second app id that has not been added is not found.
34   EXPECT_FALSE(app_info.HasAppId(kTestAppId2));
35
36   // Remove the first ID and ensure it is no longer found.
37   app_info.RemoveAppId(kTestAppId1);
38   EXPECT_FALSE(app_info.HasAppId(kTestAppId1));
39 }
40
41 TEST_F(SyncedNotificationAppInfoTest, GetAppIdListTest) {
42   SyncedNotificationAppInfo app_info(NULL, kTestSendingServiceName, NULL);
43
44   // Add a few app infos.
45   app_info.AddAppId(kTestAppId1);
46   app_info.AddAppId(kTestAppId2);
47
48   std::vector<std::string> app_id_list = app_info.GetAppIdList();
49
50   EXPECT_EQ(std::string(kTestAppId1), app_id_list[0]);
51   EXPECT_EQ(std::string(kTestAppId2), app_id_list[1]);
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
95 }  // namespace notifier