Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1408)

Unified Diff: chrome/browser/notifications/sync_notifier/chrome_notifier_service_unittest.cc

Issue 193773003: Turn on and use the AppInfo data. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Turn on app info: fix windows build Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/notifications/sync_notifier/chrome_notifier_service_unittest.cc
diff --git a/chrome/browser/notifications/sync_notifier/chrome_notifier_service_unittest.cc b/chrome/browser/notifications/sync_notifier/chrome_notifier_service_unittest.cc
index 06650ae9f3d75424939a0524ac9348678d3229f3..9a3a4265f0af185a463408a8f5261c449077e62d 100644
--- a/chrome/browser/notifications/sync_notifier/chrome_notifier_service_unittest.cc
+++ b/chrome/browser/notifications/sync_notifier/chrome_notifier_service_unittest.cc
@@ -16,6 +16,9 @@
#include "chrome/browser/notifications/sync_notifier/chrome_notifier_service.h"
#include "chrome/browser/notifications/sync_notifier/sync_notifier_test_utils.h"
#include "chrome/browser/notifications/sync_notifier/synced_notification.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 "chrome/browser/notifications/sync_notifier/synced_notification_app_info_service_factory.h"
#include "chrome/browser/prefs/browser_prefs.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/common/chrome_switches.h"
@@ -124,6 +127,9 @@ class ChromeNotifierServiceTest : public testing::Test {
// Set up a profile for the unit tests to use.
profile_.reset(new TestingProfile());
+
+ // Set up the testing SyncedNotificationAppInfoService with some test data.
+ AddTestingAppInfos();
}
virtual void TearDown() {
@@ -170,6 +176,30 @@ class ChromeNotifierServiceTest : public testing::Test {
ChromeNotifierService::CreateSyncDataFromNotification(*notification));
}
+ void AddTestingAppInfos() {
+ // Get the SyncedNotificationAppInfoService from the browser object.
+ SyncedNotificationAppInfoService* synced_notification_app_info_service =
+ SyncedNotificationAppInfoServiceFactory::GetForProfile(
+ profile_.get(), Profile::EXPLICIT_ACCESS);
+
+ // Create a notification to add.
+ // The sending_service_infos_ list will take ownership of this pointer.
+ scoped_ptr<SyncedNotificationAppInfo> test_service1(
+ new SyncedNotificationAppInfo(profile_.get(),
+ std::string(kSendingService1Name),
+ synced_notification_app_info_service));
+
+ // Add some App IDs.
+ test_service1->AddAppId(kAppId1);
+ test_service1->AddAppId(kAppId2);
+
+ // Set this icon GURL.
+ test_service1->SetSettingsIcon(GURL(kTestIconUrl));
+
+ // Call AddForTest.
+ synced_notification_app_info_service->AddForTest(test_service1.Pass());
+ }
+
protected:
scoped_ptr<TestingProfile> profile_;
@@ -182,9 +212,6 @@ class ChromeNotifierServiceTest : public testing::Test {
DISALLOW_COPY_AND_ASSIGN(ChromeNotifierServiceTest);
};
-// TODO(petewil): Add more tests as I add functionalty. Tests are based on
-// chrome/browser/extensions/app_notification_manager_sync_unittest.cc
-
// Create a Notification, convert it to SyncData and convert it back.
TEST_F(ChromeNotifierServiceTest, NotificationToSyncDataToNotification) {
scoped_ptr<SyncedNotification> notification1(
@@ -533,7 +560,7 @@ TEST_F(ChromeNotifierServiceTest, ServiceEnabledTest) {
ChromeNotifierService notifier(profile_.get(), notification_manager());
std::set<std::string>::iterator iter;
std::string first_synced_notification_service_id(
- kFirstSyncedNotificationServiceId);
+ kSendingService1Name);
// Create some local fake data.
scoped_ptr<SyncedNotification> n1(CreateNotification(
@@ -542,7 +569,7 @@ TEST_F(ChromeNotifierServiceTest, ServiceEnabledTest) {
// Enable the service and ensure the service is in the list.
// Initially the service starts in the disabled state.
- notifier.OnSyncedNotificationServiceEnabled(kFirstSyncedNotificationServiceId,
+ notifier.OnSyncedNotificationServiceEnabled(kSendingService1Name,
true);
iter = find(notifier.enabled_sending_services_.begin(),
notifier.enabled_sending_services_.end(),
@@ -552,7 +579,7 @@ TEST_F(ChromeNotifierServiceTest, ServiceEnabledTest) {
// Disable the service and ensure it is gone from the list and the
// notification_manager.
- notifier.OnSyncedNotificationServiceEnabled(kFirstSyncedNotificationServiceId,
+ notifier.OnSyncedNotificationServiceEnabled(kSendingService1Name,
false);
iter = find(notifier.enabled_sending_services_.begin(),
notifier.enabled_sending_services_.end(),
@@ -586,7 +613,7 @@ TEST_F(ChromeNotifierServiceTest, MAYBE_AddNewSendingServicesTest) {
kText1,
kIconUrl1,
kImageUrl1,
- kFirstSyncedNotificationServiceId,
+ kAppId1,
kKey1,
kUnread)));
@@ -596,7 +623,7 @@ TEST_F(ChromeNotifierServiceTest, MAYBE_AddNewSendingServicesTest) {
// Verify that the first synced notification service is enabled in memory.
std::set<std::string>::iterator iter;
- std::string first_notification_service_id(kFirstSyncedNotificationServiceId);
+ std::string first_notification_service_id(kSendingService1Name);
iter = find(notifier.enabled_sending_services_.begin(),
notifier.enabled_sending_services_.end(),
first_notification_service_id);
@@ -614,7 +641,7 @@ TEST_F(ChromeNotifierServiceTest, MAYBE_AddNewSendingServicesTest) {
kText2,
kIconUrl2,
kImageUrl2,
- kFirstSyncedNotificationServiceId,
+ kAppId1,
kKey2,
kUnread)));
notifier.ProcessSyncChanges(FROM_HERE, changes);
@@ -630,8 +657,7 @@ TEST_F(ChromeNotifierServiceTest, CheckInitializedServicesTest) {
notifier.set_avoid_bitmap_fetching_for_test(true);
// Initialize but do not enable the sending service.
- notifier.initialized_sending_services_.insert(
- kFirstSyncedNotificationServiceId);
+ notifier.initialized_sending_services_.insert(kSendingService1Name);
ASSERT_EQ(0U, notifier.enabled_sending_services_.size());
ASSERT_EQ(1U, notifier.initialized_sending_services_.size());
@@ -640,8 +666,7 @@ TEST_F(ChromeNotifierServiceTest, CheckInitializedServicesTest) {
EXPECT_EQ(0U, notifier.GetAllSyncData(SYNCED_NOTIFICATIONS).size());
// Set up an ADD.
- std::string first_synced_notification_service_id(
- kFirstSyncedNotificationServiceId);
+ std::string first_synced_notification_service_id(kSendingService1Name);
SyncChangeList changes;
changes.push_back(
@@ -650,7 +675,7 @@ TEST_F(ChromeNotifierServiceTest, CheckInitializedServicesTest) {
kText1,
kIconUrl1,
kImageUrl1,
- kFirstSyncedNotificationServiceId,
+ kAppId1,
kKey1,
kUnread)));
@@ -663,13 +688,45 @@ TEST_F(ChromeNotifierServiceTest, CheckInitializedServicesTest) {
EXPECT_EQ(0U, notification_manager()->added_notifications());
}
-TEST_F(ChromeNotifierServiceTest, CheckFindAppInfo) {
+TEST_F(ChromeNotifierServiceTest, SetAddedAppIdsTest) {
+ ChromeNotifierService notifier(profile_.get(), notification_manager());
+ notifier.set_avoid_bitmap_fetching_for_test(true);
+
+ // Add some notifications to our notification list.
+ scoped_ptr<SyncedNotification> n1(CreateNotification(
+ kTitle1, kText1, kIconUrl1, kImageUrl1, kAppId1, kKey1, kUnread));
+ notifier.AddForTest(n1.Pass());
+
+ EXPECT_EQ(static_cast<size_t>(0),
+ notification_manager()->added_notifications());
+
+ // Call SetAddedAppIds.
+ std::vector<std::string> added_app_ids;
+ added_app_ids.push_back(std::string(kAppId1));
+ notifier.SetAddedAppIds(added_app_ids);
+
+ // Verify the notification was added by the notification_manager.
+ // We see one welcome notification and one new notification.
+ EXPECT_EQ(static_cast<size_t>(2),
+ notification_manager()->added_notifications());
+}
+
+TEST_F(ChromeNotifierServiceTest, SetRemovedAppIdsTest) {
ChromeNotifierService notifier(profile_.get(), notification_manager());
notifier.set_avoid_bitmap_fetching_for_test(true);
- SyncedNotificationAppInfoTemp* app_info =
- notifier.FindAppInfo(kFirstSyncedNotificationServiceId);
- EXPECT_TRUE(app_info != NULL);
+ // Add some notifications to our notification list.
+ scoped_ptr<SyncedNotification> n1(CreateNotification(
+ kTitle1, kText1, kIconUrl1, kImageUrl1, kAppId1, kKey1, kUnread));
+ notifier.AddForTest(n1.Pass());
+
+ // Call SetRemovedAppIds.
+ std::vector<std::string> removed_app_ids;
+ removed_app_ids.push_back(std::string(kAppId1));
+ notifier.SetRemovedAppIds(removed_app_ids);
+
+ // Verify the notification was "removed" in the notification manager.
+ EXPECT_EQ(std::string(kKey1), notification_manager()->dismissed_id());
}
} // namespace notifier

Powered by Google App Engine
This is Rietveld 408576698