Chromium Code Reviews| Index: chrome/browser/notifier/synced_notification_unittest.cc |
| diff --git a/chrome/browser/notifier/synced_notification_unittest.cc b/chrome/browser/notifier/synced_notification_unittest.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..54ad51010aa73123d58e09f2b74f5fecb713c72e |
| --- /dev/null |
| +++ b/chrome/browser/notifier/synced_notification_unittest.cc |
| @@ -0,0 +1,198 @@ |
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include <string> |
| + |
| +#include "chrome/browser/notifier/synced_notification.h" |
| + |
| +#include "sync/api/sync_data.h" |
| +#include "sync/protocol/sync.pb.h" |
| +#include "sync/protocol/synced_notification_specifics.pb.h" |
| +#include "testing/gtest/include/gtest/gtest.h" |
| + |
| +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.
|
| +using syncer::SyncData; |
| +using sync_pb::SyncedNotification; |
| +using sync_pb::EntitySpecifics; |
| +using sync_pb::SyncedNotificationSpecifics; |
| +using sync_pb::SyncedNotificationRenderInfo_Layout_LayoutType_TITLE_AND_SUBTEXT; |
| + |
| +namespace { |
| + |
| +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.
|
| + |
| +const char TITLE1[] = "New appointment at 2:15"; |
| +const char TITLE2[] = "Email from Mark: Upcoming Ski trip"; |
| +const char APP_ID1[] = "fboilmbenheemaomgaeehigklolhkhnf"; |
| +const char APP_ID2[] = "fbcmoldooppoahjhfflnmljoanccekpf"; |
| +const char COALESCING_KEY1[] = "foo"; |
| +const char COALESCING_KEY2[] = "bar"; |
| +const char BODY1[] = "Space Needle, 12:00 pm"; |
| +const char BODY2[] = "Stevens Pass is our first choice."; |
| +const char ICON_URL1[] = "http://www.google.com/icon1.jpg"; |
| +const char ICON_URL2[]= "http://www.google.com/icon2.jpg"; |
| + |
| +} // namespace |
| + |
| +class SyncedNotificationTest : public testing::Test { |
| + |
|
dcheng
2013/01/18 21:56:13
Unneeded newline.
Pete Williamson
2013/01/23 01:45:55
Done.
|
| + public: |
| + SyncedNotificationTest() : notification1(NULL), |
| + notification2(NULL) {} |
| + ~SyncedNotificationTest() {} |
| + |
| + // Methods from testing::Test. |
| + |
| + virtual void SetUp() { |
| + syncer::SyncData sync_data1 = CreateSyncData(TITLE1, BODY1, ICON_URL1, |
| + APP_ID1, COALESCING_KEY1); |
| + syncer::SyncData sync_data2 = CreateSyncData(TITLE2, BODY2, ICON_URL2, |
| + APP_ID2, COALESCING_KEY2); |
| + |
| + notification1 = new SyncedNotification(sync_data1); |
| + notification2 = new SyncedNotification(sync_data2); |
| + } |
| + |
| + 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.
|
| + } |
| + |
| + // 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.
|
| + SyncedNotification* notification1; |
| + SyncedNotification* notification2; |
| + |
| + private: |
| + |
|
dcheng
2013/01/18 21:56:13
Remove unnecessary newlines please.
|
| + // Helper to create syncer::SyncData. |
| + static SyncData CreateSyncData(const std::string& title, |
| + const std::string& body, |
| + const std::string& icon_url, |
| + const std::string& app_id, |
| + const std::string& coalescing_key) { |
| + |
|
dcheng
2013/01/18 21:56:13
Ditto on newlines.
Pete Williamson
2013/01/23 01:45:55
Done.
|
| + // CreateLocalData makes a copy of this, so this can safely live |
| + // 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
|
| + EntitySpecifics entity_specifics; |
| + |
| + // Get a writeable pointer to the sync notifications specifics inside the |
| + // entity specifics. |
| + SyncedNotificationSpecifics* specifics = |
| + entity_specifics.mutable_synced_notification(); |
| + |
| + // Fill out as much of SyncedNotificationSpecifics as the tests need. |
| + |
| + // Set the layout type to Title and Subtext. |
| + specifics->mutable_coalesced_notification()-> |
| + mutable_render_info()-> |
| + mutable_layout()-> |
| + set_layout_type( |
| + SyncedNotificationRenderInfo_Layout_LayoutType_TITLE_AND_SUBTEXT); |
| + |
| + // Set the APP_ID field in the ID. |
| + specifics->mutable_coalesced_notification()-> |
| + mutable_id()-> |
| + set_app_id(app_id); |
| + |
| + // Set the coalescing key in the ID. |
| + specifics->mutable_coalesced_notification()-> |
| + mutable_id()-> |
| + set_coalescing_key(coalescing_key); |
| + |
| + // Set the title (of a title and subtext). |
| + specifics->mutable_coalesced_notification()-> |
| + mutable_render_info()-> |
| + mutable_layout()-> |
| + mutable_title_and_subtext_data()-> |
| + set_title(title); |
| + |
| + // Set the body text. |
| + specifics->mutable_coalesced_notification()-> |
| + mutable_render_info()-> |
| + mutable_layout()-> |
| + mutable_title_and_subtext_data()-> |
| + add_subtext(body); |
| + |
| + // Set the icon URL (of a title and subtext). |
| + specifics->mutable_coalesced_notification()-> |
| + mutable_render_info()-> |
| + mutable_layout()-> |
| + mutable_title_and_subtext_data()-> |
| + mutable_icon()-> |
| + set_url(icon_url); |
| + |
| + // Set the creation time. |
| + specifics->mutable_coalesced_notification()-> |
| + set_creation_time_msec(FAKE_CREATION_TIME); |
| + |
| + // Set the first notification. |
| + specifics->mutable_coalesced_notification()-> |
| + add_notification(); |
| + |
| + SyncData sync_data = SyncData::CreateLocalData( |
| + "syncer::SYNCED_NOTIFICATIONS", |
| + "SyncedNotificationTest", |
| + entity_specifics); |
| + |
| + return sync_data; |
| + } |
| + |
| + private: |
| + DISALLOW_COPY_AND_ASSIGN(SyncedNotificationTest); |
| +}; |
| + |
| +// test simple accessors |
| + |
| +TEST_F(SyncedNotificationTest, GetAppIdTest) { |
| + string found_app_id = notification1->get_app_id(); |
| + string expected_app_id(APP_ID1); |
| + |
| + EXPECT_TRUE(found_app_id == expected_app_id); |
|
dcheng
2013/01/18 21:56:13
EXPECT_EQ
|
| +} |
| + |
| +TEST_F(SyncedNotificationTest, GetCoalescingKeyTest) { |
| + string found_key = notification1->get_coalescing_key(); |
| + string expected_key(COALESCING_KEY1); |
| + |
| + EXPECT_TRUE(found_key == expected_key); |
| +} |
| + |
| +TEST_F(SyncedNotificationTest, GetTitleTest) { |
| + string found_title = notification1->get_title(); |
| + string expected_title(TITLE1); |
| + |
| + EXPECT_TRUE(found_title == expected_title); |
|
dcheng
2013/01/18 21:56:13
EXPECT_EQ
|
| +} |
| + |
| +TEST_F(SyncedNotificationTest, GetIconURLTest) { |
| + string found_icon_url = notification1->get_icon_url(); |
| + string expected_icon_url(ICON_URL1); |
| + |
| + 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.
|
| +} |
| + |
| +// TODO: test with a multi-line body |
| +TEST_F(SyncedNotificationTest, GetBodyTest) { |
| + string found_body = notification1->get_body(); |
| + string expected_body(BODY1); |
| + |
| + EXPECT_TRUE(found_body == expected_body); |
| +} |
| + |
| +TEST_F(SyncedNotificationTest, GetNotificationIdTest) { |
| + string found_id = notification1->get_notification_id(); |
| + string expected_id(APP_ID1); |
| + expected_id += "/"; |
| + expected_id += COALESCING_KEY1; |
| + |
| + EXPECT_TRUE(found_id == expected_id); |
|
dcheng
2013/01/18 21:56:13
EXPECT_EQ.
Pete Williamson
2013/01/23 01:45:55
Done.
|
| +} |
| + |
| +// test that equals works as we expect |
| +TEST_F(SyncedNotificationTest, EqualsTest) { |
| + EXPECT_TRUE(notification1->Equals(*notification1)); |
| + EXPECT_TRUE(notification2->Equals(*notification2)); |
| + EXPECT_FALSE(notification1->Equals(*notification2)); |
| +} |
| + |
| +// Add a test for set_local_changes and has_local_changes together |
| +// Add a test for a notification being read and or deleted |