OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include <string> |
| 6 |
| 7 #include "base/memory/scoped_ptr.h" |
| 8 #include "chrome/browser/notifier/synced_notification.h" |
| 9 #include "sync/api/sync_data.h" |
| 10 #include "sync/protocol/sync.pb.h" |
| 11 #include "sync/protocol/synced_notification_specifics.pb.h" |
| 12 #include "testing/gtest/include/gtest/gtest.h" |
| 13 |
| 14 using syncer::SyncData; |
| 15 using notifier::SyncedNotification; |
| 16 using sync_pb::EntitySpecifics; |
| 17 using sync_pb::SyncedNotificationSpecifics; |
| 18 using sync_pb::SyncedNotificationRenderInfo_Layout_LayoutType_TITLE_AND_SUBTEXT; |
| 19 |
| 20 namespace { |
| 21 |
| 22 const int64 kFakeCreationTime = 42; |
| 23 |
| 24 const char kTitle1[] = "New appointment at 2:15"; |
| 25 const char kTitle2[] = "Email from Mark: Upcoming Ski trip"; |
| 26 const char kAppId1[] = "fboilmbenheemaomgaeehigklolhkhnf"; |
| 27 const char kAppId2[] = "fbcmoldooppoahjhfflnmljoanccekpf"; |
| 28 const char kCoalescingKey1[] = "foo"; |
| 29 const char kCoalescingKey2[] = "bar"; |
| 30 const char kBody1[] = "Space Needle, 12:00 pm"; |
| 31 const char kBody2[] = "Stevens Pass is our first choice."; |
| 32 const char kIconUrl1[] = "http://www.google.com/icon1.jpg"; |
| 33 const char kIconUrl2[]= "http://www.google.com/icon2.jpg"; |
| 34 |
| 35 } // namespace |
| 36 |
| 37 class SyncedNotificationTest : public testing::Test { |
| 38 public: |
| 39 SyncedNotificationTest() : notification1(NULL), |
| 40 notification2(NULL) {} |
| 41 ~SyncedNotificationTest() {} |
| 42 |
| 43 // Methods from testing::Test. |
| 44 |
| 45 virtual void SetUp() OVERRIDE { |
| 46 syncer::SyncData sync_data1 = CreateSyncData(kTitle1, kBody1, kIconUrl1, |
| 47 kAppId1, kCoalescingKey1); |
| 48 syncer::SyncData sync_data2 = CreateSyncData(kTitle2, kBody2, kIconUrl2, |
| 49 kAppId2, kCoalescingKey2); |
| 50 |
| 51 notification1.reset(new SyncedNotification(sync_data1)); |
| 52 notification2.reset(new SyncedNotification(sync_data2)); |
| 53 } |
| 54 |
| 55 virtual void TearDown() OVERRIDE { |
| 56 } |
| 57 |
| 58 scoped_ptr<SyncedNotification> notification1; |
| 59 scoped_ptr<SyncedNotification> notification2; |
| 60 |
| 61 private: |
| 62 // Helper to create syncer::SyncData. |
| 63 static SyncData CreateSyncData(const std::string& title, |
| 64 const std::string& body, |
| 65 const std::string& icon_url, |
| 66 const std::string& app_id, |
| 67 const std::string& coalescing_key) { |
| 68 // CreateLocalData makes a copy of this, so this can safely live |
| 69 // on the stack. |
| 70 EntitySpecifics entity_specifics; |
| 71 |
| 72 // Get a writeable pointer to the sync notifications specifics inside the |
| 73 // entity specifics. |
| 74 SyncedNotificationSpecifics* specifics = |
| 75 entity_specifics.mutable_synced_notification(); |
| 76 |
| 77 specifics->mutable_coalesced_notification()-> |
| 78 mutable_render_info()-> |
| 79 mutable_layout()-> |
| 80 set_layout_type( |
| 81 SyncedNotificationRenderInfo_Layout_LayoutType_TITLE_AND_SUBTEXT); |
| 82 |
| 83 specifics->mutable_coalesced_notification()-> |
| 84 mutable_id()-> |
| 85 set_app_id(app_id); |
| 86 |
| 87 specifics->mutable_coalesced_notification()-> |
| 88 mutable_id()-> |
| 89 set_coalescing_key(coalescing_key); |
| 90 |
| 91 specifics->mutable_coalesced_notification()-> |
| 92 mutable_render_info()-> |
| 93 mutable_layout()-> |
| 94 mutable_title_and_subtext_data()-> |
| 95 set_title(title); |
| 96 |
| 97 specifics->mutable_coalesced_notification()-> |
| 98 mutable_render_info()-> |
| 99 mutable_layout()-> |
| 100 mutable_title_and_subtext_data()-> |
| 101 add_subtext(body); |
| 102 |
| 103 specifics->mutable_coalesced_notification()-> |
| 104 mutable_render_info()-> |
| 105 mutable_layout()-> |
| 106 mutable_title_and_subtext_data()-> |
| 107 mutable_icon()-> |
| 108 set_url(icon_url); |
| 109 |
| 110 specifics->mutable_coalesced_notification()-> |
| 111 set_creation_time_msec(kFakeCreationTime); |
| 112 |
| 113 specifics->mutable_coalesced_notification()-> |
| 114 add_notification(); |
| 115 |
| 116 SyncData sync_data = SyncData::CreateLocalData( |
| 117 "syncer::SYNCED_NOTIFICATIONS", |
| 118 "SyncedNotificationTest", |
| 119 entity_specifics); |
| 120 |
| 121 return sync_data; |
| 122 } |
| 123 |
| 124 private: |
| 125 DISALLOW_COPY_AND_ASSIGN(SyncedNotificationTest); |
| 126 }; |
| 127 |
| 128 // test simple accessors |
| 129 |
| 130 TEST_F(SyncedNotificationTest, GetAppIdTest) { |
| 131 std::string found_app_id = notification1->GetAppId(); |
| 132 std::string expected_app_id(kAppId1); |
| 133 |
| 134 EXPECT_EQ(found_app_id, expected_app_id); |
| 135 } |
| 136 |
| 137 TEST_F(SyncedNotificationTest, GetCoalescingKeyTest) { |
| 138 std::string found_key = notification1->GetCoalescingKey(); |
| 139 std::string expected_key(kCoalescingKey1); |
| 140 |
| 141 EXPECT_EQ(found_key, expected_key); |
| 142 } |
| 143 |
| 144 TEST_F(SyncedNotificationTest, GetTitleTest) { |
| 145 std::string found_title = notification1->GetTitle(); |
| 146 std::string expected_title(kTitle1); |
| 147 |
| 148 EXPECT_EQ(found_title, expected_title); |
| 149 } |
| 150 |
| 151 TEST_F(SyncedNotificationTest, GetIconURLTest) { |
| 152 std::string found_icon_url = notification1->GetIconUrl().spec(); |
| 153 std::string expected_icon_url(kIconUrl1); |
| 154 |
| 155 EXPECT_EQ(found_icon_url, expected_icon_url); |
| 156 } |
| 157 |
| 158 // TODO(petewil): test with a multi-line body |
| 159 TEST_F(SyncedNotificationTest, GetBodyTest) { |
| 160 std::string found_body = notification1->GetBody(); |
| 161 std::string expected_body(kBody1); |
| 162 |
| 163 EXPECT_EQ(found_body, expected_body); |
| 164 } |
| 165 |
| 166 TEST_F(SyncedNotificationTest, GetNotificationIdTest) { |
| 167 std::string found_id = notification1->GetNotificationId(); |
| 168 std::string expected_id(kAppId1); |
| 169 expected_id += "/"; |
| 170 expected_id += kCoalescingKey1; |
| 171 |
| 172 EXPECT_EQ(found_id, expected_id); |
| 173 } |
| 174 |
| 175 // test that equals works as we expect |
| 176 TEST_F(SyncedNotificationTest, EqualsTest) { |
| 177 EXPECT_TRUE(notification1->Equals(*notification1)); |
| 178 EXPECT_TRUE(notification2->Equals(*notification2)); |
| 179 EXPECT_FALSE(notification1->Equals(*notification2)); |
| 180 } |
| 181 |
| 182 // Add a test for set_local_changes and has_local_changes together |
| 183 // Add a test for a notification being read and or deleted |
OLD | NEW |