OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <string> | 5 #include <string> |
6 | 6 |
7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
8 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
9 #include "chrome/browser/notifications/notification.h" | 9 #include "chrome/browser/notifications/notification.h" |
10 #include "chrome/browser/notifications/notification_ui_manager.h" | 10 #include "chrome/browser/notifications/notification_ui_manager.h" |
11 #include "chrome/browser/notifications/sync_notifier/synced_notification.h" | 11 #include "chrome/browser/notifications/sync_notifier/synced_notification.h" |
12 #include "sync/api/sync_data.h" | 12 #include "sync/api/sync_data.h" |
13 #include "sync/protocol/sync.pb.h" | 13 #include "sync/protocol/sync.pb.h" |
14 #include "sync/protocol/synced_notification_specifics.pb.h" | 14 #include "sync/protocol/synced_notification_specifics.pb.h" |
15 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
16 #if defined(ENABLE_MESSAGE_CENTER) | |
17 #include "ui/message_center/message_center_util.h" | 16 #include "ui/message_center/message_center_util.h" |
18 #include "ui/message_center/notification_types.h" | 17 #include "ui/message_center/notification_types.h" |
19 #endif // ENABLE_MESSAGE_CENTER | |
20 | 18 |
21 using syncer::SyncData; | 19 using syncer::SyncData; |
22 using notifier::SyncedNotification; | 20 using notifier::SyncedNotification; |
23 using sync_pb::EntitySpecifics; | 21 using sync_pb::EntitySpecifics; |
24 using sync_pb::SyncedNotificationSpecifics; | 22 using sync_pb::SyncedNotificationSpecifics; |
25 | 23 |
26 namespace { | 24 namespace { |
27 | 25 |
28 const uint64 kFakeCreationTime = 42; | 26 const uint64 kFakeCreationTime = 42; |
29 const int kProtobufPriority = static_cast<int>( | 27 const int kProtobufPriority = static_cast<int>( |
30 sync_pb::CoalescedSyncedNotification_Priority_LOW); | 28 sync_pb::CoalescedSyncedNotification_Priority_LOW); |
31 #if defined (ENABLE_MESSAGE_CENTER) | |
32 const int kNotificationPriority = static_cast<int>( | 29 const int kNotificationPriority = static_cast<int>( |
33 message_center::LOW_PRIORITY); | 30 message_center::LOW_PRIORITY); |
34 #else // ENABLE_MESSAGE_CENTER | |
35 const int kNotificationPriority = 1; | |
36 #endif // ENABLE_MESSAGE_CENTER | |
37 | 31 |
38 bool UseRichNotifications() { | 32 bool UseRichNotifications() { |
39 #if defined(ENABLE_MESSAGE_CENTER) | |
40 return message_center::IsRichNotificationEnabled(); | 33 return message_center::IsRichNotificationEnabled(); |
41 #else // ENABLE_MESSAGE_CENTER | |
42 return false; | |
43 #endif // ENABLE_MESSAGE_CENTER | |
44 } | 34 } |
45 | 35 |
46 const char kTitle1[] = "New appointment at 2:15"; | 36 const char kTitle1[] = "New appointment at 2:15"; |
47 const char kTitle2[] = "Email from Mark: Upcoming Ski trip"; | 37 const char kTitle2[] = "Email from Mark: Upcoming Ski trip"; |
48 const char kTitle3[] = "Weather alert - light rain tonight."; | 38 const char kTitle3[] = "Weather alert - light rain tonight."; |
49 const char kAppId1[] = "fboilmbenheemaomgaeehigklolhkhnf"; | 39 const char kAppId1[] = "fboilmbenheemaomgaeehigklolhkhnf"; |
50 const char kAppId2[] = "fbcmoldooppoahjhfflnmljoanccekpf"; | 40 const char kAppId2[] = "fbcmoldooppoahjhfflnmljoanccekpf"; |
51 const char kKey1[] = "foo"; | 41 const char kKey1[] = "foo"; |
52 const char kKey2[] = "bar"; | 42 const char kKey2[] = "bar"; |
53 const char kText1[] = "Space Needle, 12:00 pm"; | 43 const char kText1[] = "Space Needle, 12:00 pm"; |
(...skipping 511 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
565 EXPECT_TRUE(notification5->EqualsIgnoringReadState(*notification2_)); | 555 EXPECT_TRUE(notification5->EqualsIgnoringReadState(*notification2_)); |
566 EXPECT_EQ(notification5->GetReadState(), notification2_->GetReadState()); | 556 EXPECT_EQ(notification5->GetReadState(), notification2_->GetReadState()); |
567 EXPECT_FALSE(notification5->EqualsIgnoringReadState(*notification1_)); | 557 EXPECT_FALSE(notification5->EqualsIgnoringReadState(*notification1_)); |
568 } | 558 } |
569 | 559 |
570 TEST_F(SyncedNotificationTest, ShowTest) { | 560 TEST_F(SyncedNotificationTest, ShowTest) { |
571 | 561 |
572 if (!UseRichNotifications()) | 562 if (!UseRichNotifications()) |
573 return; | 563 return; |
574 | 564 |
575 #if defined(ENABLE_MESSAGE_CENTER) | |
576 | |
577 StubNotificationUIManager notification_manager; | 565 StubNotificationUIManager notification_manager; |
578 | 566 |
579 // Call the method under test using the pre-populated data. | 567 // Call the method under test using the pre-populated data. |
580 notification1_->Show(¬ification_manager, NULL, NULL); | 568 notification1_->Show(¬ification_manager, NULL, NULL); |
581 | 569 |
582 // Check the base fields of the notification. | 570 // Check the base fields of the notification. |
583 EXPECT_EQ(message_center::NOTIFICATION_TYPE_IMAGE, | 571 EXPECT_EQ(message_center::NOTIFICATION_TYPE_IMAGE, |
584 notification_manager.notification().type()); | 572 notification_manager.notification().type()); |
585 EXPECT_EQ(kTitle1, | 573 EXPECT_EQ(kTitle1, |
586 UTF16ToUTF8(notification_manager.notification().title())); | 574 UTF16ToUTF8(notification_manager.notification().title())); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
628 UTF8ToUTF16(kContainedMessage3)); | 616 UTF8ToUTF16(kContainedMessage3)); |
629 items->Append(item1); | 617 items->Append(item1); |
630 items->Append(item2); | 618 items->Append(item2); |
631 items->Append(item3); | 619 items->Append(item3); |
632 expected_fields.Set(message_center::kItemsKey, items); | 620 expected_fields.Set(message_center::kItemsKey, items); |
633 | 621 |
634 EXPECT_TRUE(expected_fields.Equals(actual_fields)) | 622 EXPECT_TRUE(expected_fields.Equals(actual_fields)) |
635 << "Expected: " << expected_fields | 623 << "Expected: " << expected_fields |
636 << ", but actual: " << *actual_fields; | 624 << ", but actual: " << *actual_fields; |
637 | 625 |
638 #endif // ENABLE_MESSAGE_CENTER | |
639 | |
640 } | 626 } |
641 | 627 |
642 // TODO(petewil): Add a test for a notification being read and or deleted. | 628 // TODO(petewil): Add a test for a notification being read and or deleted. |
OLD | NEW |