Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2012 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/notifier/synced_notification.h" | |
| 8 | |
| 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 std::string; | |
|
dcheng
2013/01/18 21:56:13
Optional/preference/nit: I'd prefer not to have th
Pete Williamson
2013/01/23 01:45:55
Done.
| |
| 15 using syncer::SyncData; | |
| 16 using sync_pb::SyncedNotification; | |
| 17 using sync_pb::EntitySpecifics; | |
| 18 using sync_pb::SyncedNotificationSpecifics; | |
| 19 using sync_pb::SyncedNotificationRenderInfo_Layout_LayoutType_TITLE_AND_SUBTEXT; | |
| 20 | |
| 21 namespace { | |
| 22 | |
| 23 const unsigned long long FAKE_CREATION_TIME = 42; | |
|
dcheng
2013/01/18 21:56:13
Constants are named kFoo. Also use int64 instead o
Pete Williamson
2013/01/23 01:45:55
Done.
| |
| 24 | |
| 25 const char TITLE1[] = "New appointment at 2:15"; | |
| 26 const char TITLE2[] = "Email from Mark: Upcoming Ski trip"; | |
| 27 const char APP_ID1[] = "fboilmbenheemaomgaeehigklolhkhnf"; | |
| 28 const char APP_ID2[] = "fbcmoldooppoahjhfflnmljoanccekpf"; | |
| 29 const char COALESCING_KEY1[] = "foo"; | |
| 30 const char COALESCING_KEY2[] = "bar"; | |
| 31 const char BODY1[] = "Space Needle, 12:00 pm"; | |
| 32 const char BODY2[] = "Stevens Pass is our first choice."; | |
| 33 const char ICON_URL1[] = "http://www.google.com/icon1.jpg"; | |
| 34 const char ICON_URL2[]= "http://www.google.com/icon2.jpg"; | |
| 35 | |
| 36 } // namespace | |
| 37 | |
| 38 class SyncedNotificationTest : public testing::Test { | |
| 39 | |
|
dcheng
2013/01/18 21:56:13
Unneeded newline.
Pete Williamson
2013/01/23 01:45:55
Done.
| |
| 40 public: | |
| 41 SyncedNotificationTest() : notification1(NULL), | |
| 42 notification2(NULL) {} | |
| 43 ~SyncedNotificationTest() {} | |
| 44 | |
| 45 // Methods from testing::Test. | |
| 46 | |
| 47 virtual void SetUp() { | |
| 48 syncer::SyncData sync_data1 = CreateSyncData(TITLE1, BODY1, ICON_URL1, | |
| 49 APP_ID1, COALESCING_KEY1); | |
| 50 syncer::SyncData sync_data2 = CreateSyncData(TITLE2, BODY2, ICON_URL2, | |
| 51 APP_ID2, COALESCING_KEY2); | |
| 52 | |
| 53 notification1 = new SyncedNotification(sync_data1); | |
| 54 notification2 = new SyncedNotification(sync_data2); | |
| 55 } | |
| 56 | |
| 57 virtual void TearDown() { | |
|
dcheng
2013/01/18 21:56:13
OVERRIDE on SetUp() and TearDown()?
Pete Williamson
2013/01/23 01:45:55
Done.
Pete Williamson
2013/01/23 01:45:55
Done.
| |
| 58 } | |
| 59 | |
| 60 // TODO: convert to scoped_ptr | |
|
dcheng
2013/01/18 21:56:13
Please fix this before checking in. This will prob
Pete Williamson
2013/01/23 01:45:55
Done.
| |
| 61 SyncedNotification* notification1; | |
| 62 SyncedNotification* notification2; | |
| 63 | |
| 64 private: | |
| 65 | |
|
dcheng
2013/01/18 21:56:13
Remove unnecessary newlines please.
| |
| 66 // Helper to create syncer::SyncData. | |
| 67 static SyncData CreateSyncData(const std::string& title, | |
| 68 const std::string& body, | |
| 69 const std::string& icon_url, | |
| 70 const std::string& app_id, | |
| 71 const std::string& coalescing_key) { | |
| 72 | |
|
dcheng
2013/01/18 21:56:13
Ditto on newlines.
Pete Williamson
2013/01/23 01:45:55
Done.
| |
| 73 // CreateLocalData makes a copy of this, so this can safely live | |
| 74 // on the stack. | |
|
dcheng
2013/01/18 21:56:13
Unneeded comments.
Pete Williamson
2013/01/23 01:45:55
Removed most of the comments, left a few of the on
| |
| 75 EntitySpecifics entity_specifics; | |
| 76 | |
| 77 // Get a writeable pointer to the sync notifications specifics inside the | |
| 78 // entity specifics. | |
| 79 SyncedNotificationSpecifics* specifics = | |
| 80 entity_specifics.mutable_synced_notification(); | |
| 81 | |
| 82 // Fill out as much of SyncedNotificationSpecifics as the tests need. | |
| 83 | |
| 84 // Set the layout type to Title and Subtext. | |
| 85 specifics->mutable_coalesced_notification()-> | |
| 86 mutable_render_info()-> | |
| 87 mutable_layout()-> | |
| 88 set_layout_type( | |
| 89 SyncedNotificationRenderInfo_Layout_LayoutType_TITLE_AND_SUBTEXT); | |
| 90 | |
| 91 // Set the APP_ID field in the ID. | |
| 92 specifics->mutable_coalesced_notification()-> | |
| 93 mutable_id()-> | |
| 94 set_app_id(app_id); | |
| 95 | |
| 96 // Set the coalescing key in the ID. | |
| 97 specifics->mutable_coalesced_notification()-> | |
| 98 mutable_id()-> | |
| 99 set_coalescing_key(coalescing_key); | |
| 100 | |
| 101 // Set the title (of a title and subtext). | |
| 102 specifics->mutable_coalesced_notification()-> | |
| 103 mutable_render_info()-> | |
| 104 mutable_layout()-> | |
| 105 mutable_title_and_subtext_data()-> | |
| 106 set_title(title); | |
| 107 | |
| 108 // Set the body text. | |
| 109 specifics->mutable_coalesced_notification()-> | |
| 110 mutable_render_info()-> | |
| 111 mutable_layout()-> | |
| 112 mutable_title_and_subtext_data()-> | |
| 113 add_subtext(body); | |
| 114 | |
| 115 // Set the icon URL (of a title and subtext). | |
| 116 specifics->mutable_coalesced_notification()-> | |
| 117 mutable_render_info()-> | |
| 118 mutable_layout()-> | |
| 119 mutable_title_and_subtext_data()-> | |
| 120 mutable_icon()-> | |
| 121 set_url(icon_url); | |
| 122 | |
| 123 // Set the creation time. | |
| 124 specifics->mutable_coalesced_notification()-> | |
| 125 set_creation_time_msec(FAKE_CREATION_TIME); | |
| 126 | |
| 127 // Set the first notification. | |
| 128 specifics->mutable_coalesced_notification()-> | |
| 129 add_notification(); | |
| 130 | |
| 131 SyncData sync_data = SyncData::CreateLocalData( | |
| 132 "syncer::SYNCED_NOTIFICATIONS", | |
| 133 "SyncedNotificationTest", | |
| 134 entity_specifics); | |
| 135 | |
| 136 return sync_data; | |
| 137 } | |
| 138 | |
| 139 private: | |
| 140 DISALLOW_COPY_AND_ASSIGN(SyncedNotificationTest); | |
| 141 }; | |
| 142 | |
| 143 // test simple accessors | |
| 144 | |
| 145 TEST_F(SyncedNotificationTest, GetAppIdTest) { | |
| 146 string found_app_id = notification1->get_app_id(); | |
| 147 string expected_app_id(APP_ID1); | |
| 148 | |
| 149 EXPECT_TRUE(found_app_id == expected_app_id); | |
|
dcheng
2013/01/18 21:56:13
EXPECT_EQ
| |
| 150 } | |
| 151 | |
| 152 TEST_F(SyncedNotificationTest, GetCoalescingKeyTest) { | |
| 153 string found_key = notification1->get_coalescing_key(); | |
| 154 string expected_key(COALESCING_KEY1); | |
| 155 | |
| 156 EXPECT_TRUE(found_key == expected_key); | |
| 157 } | |
| 158 | |
| 159 TEST_F(SyncedNotificationTest, GetTitleTest) { | |
| 160 string found_title = notification1->get_title(); | |
| 161 string expected_title(TITLE1); | |
| 162 | |
| 163 EXPECT_TRUE(found_title == expected_title); | |
|
dcheng
2013/01/18 21:56:13
EXPECT_EQ
| |
| 164 } | |
| 165 | |
| 166 TEST_F(SyncedNotificationTest, GetIconURLTest) { | |
| 167 string found_icon_url = notification1->get_icon_url(); | |
| 168 string expected_icon_url(ICON_URL1); | |
| 169 | |
| 170 EXPECT_TRUE(found_icon_url == expected_icon_url); | |
|
dcheng
2013/01/18 21:56:13
EXPECT_EQ.
Pete Williamson
2013/01/23 01:45:55
Done.
| |
| 171 } | |
| 172 | |
| 173 // TODO: test with a multi-line body | |
| 174 TEST_F(SyncedNotificationTest, GetBodyTest) { | |
| 175 string found_body = notification1->get_body(); | |
| 176 string expected_body(BODY1); | |
| 177 | |
| 178 EXPECT_TRUE(found_body == expected_body); | |
| 179 } | |
| 180 | |
| 181 TEST_F(SyncedNotificationTest, GetNotificationIdTest) { | |
| 182 string found_id = notification1->get_notification_id(); | |
| 183 string expected_id(APP_ID1); | |
| 184 expected_id += "/"; | |
| 185 expected_id += COALESCING_KEY1; | |
| 186 | |
| 187 EXPECT_TRUE(found_id == expected_id); | |
|
dcheng
2013/01/18 21:56:13
EXPECT_EQ.
Pete Williamson
2013/01/23 01:45:55
Done.
| |
| 188 } | |
| 189 | |
| 190 // test that equals works as we expect | |
| 191 TEST_F(SyncedNotificationTest, EqualsTest) { | |
| 192 EXPECT_TRUE(notification1->Equals(*notification1)); | |
| 193 EXPECT_TRUE(notification2->Equals(*notification2)); | |
| 194 EXPECT_FALSE(notification1->Equals(*notification2)); | |
| 195 } | |
| 196 | |
| 197 // Add a test for set_local_changes and has_local_changes together | |
| 198 // Add a test for a notification being read and or deleted | |
| OLD | NEW |