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

Side by Side Diff: chrome/browser/sync/notifier/bridged_sync_notifier_unittest.cc

Issue 9512005: [Sync] Move BridgedSyncNotifier and ChromeSyncNotificationBridge to glue/ (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Sync to head Created 8 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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 "chrome/browser/sync/notifier/bridged_sync_notifier.h"
6
7 #include <string>
8
9 #include "base/compiler_specific.h"
10 #include "base/message_loop.h"
11 #include "base/threading/thread.h"
12 #include "chrome/browser/sync/notifier/chrome_sync_notification_bridge.h"
13 #include "chrome/browser/sync/notifier/mock_sync_notifier_observer.h"
14 #include "chrome/browser/sync/notifier/sync_notifier.h"
15 #include "chrome/browser/sync/syncable/model_type.h"
16 #include "chrome/browser/sync/syncable/model_type_test_util.h"
17 #include "chrome/test/base/profile_mock.h"
18 #include "content/test/test_browser_thread.h"
19 #include "testing/gmock/include/gmock/gmock.h"
20 #include "testing/gtest/include/gtest/gtest.h"
21
22 namespace sync_notifier {
23 namespace {
24
25 using ::testing::NiceMock;
26 using ::testing::StrictMock;
27 using content::BrowserThread;
28 using syncable::HasModelTypes;
29
30 class MockChromeSyncNotificationBridge : public ChromeSyncNotificationBridge {
31 public:
32 MockChromeSyncNotificationBridge()
33 : ChromeSyncNotificationBridge(&mock_profile_) {}
34 virtual ~MockChromeSyncNotificationBridge() {}
35
36 MOCK_METHOD1(AddObserver, void(SyncNotifierObserver*));
37 MOCK_METHOD1(RemoveObserver, void(SyncNotifierObserver*));
38 private:
39 NiceMock<ProfileMock> mock_profile_;
40 };
41
42 class MockSyncNotifier : public SyncNotifier {
43 public:
44 MockSyncNotifier() {}
45 virtual ~MockSyncNotifier() {}
46
47 MOCK_METHOD1(AddObserver, void(SyncNotifierObserver*));
48 MOCK_METHOD1(RemoveObserver, void(SyncNotifierObserver*));
49 MOCK_METHOD1(SetUniqueId, void(const std::string&));
50 MOCK_METHOD1(SetState, void(const std::string&));
51 MOCK_METHOD2(UpdateCredentials, void(const std::string&, const std::string&));
52 MOCK_METHOD1(UpdateEnabledTypes, void(syncable::ModelTypeSet));
53 MOCK_METHOD1(SendNotification, void(syncable::ModelTypeSet));
54 };
55
56 // All tests just verify that each call is passed through to the delegate, with
57 // the exception of AddObserver/RemoveObserver, which also verify the observer
58 // is registered with the bridge.
59 class BridgedSyncNotifierTest : public testing::Test {
60 public:
61 BridgedSyncNotifierTest()
62 : ui_thread_(BrowserThread::UI, &ui_loop_),
63 mock_delegate_(new MockSyncNotifier), // Owned by bridged_notifier_.
64 bridged_notifier_(&mock_bridge_, mock_delegate_) {}
65 virtual ~BridgedSyncNotifierTest() {}
66
67 protected:
68 MessageLoop ui_loop_;
69 content::TestBrowserThread ui_thread_;
70 StrictMock<MockChromeSyncNotificationBridge> mock_bridge_;
71 MockSyncNotifier* mock_delegate_;
72 BridgedSyncNotifier bridged_notifier_;
73 };
74
75 TEST_F(BridgedSyncNotifierTest, AddObserver) {
76 MockSyncNotifierObserver observer;
77 EXPECT_CALL(mock_bridge_, AddObserver(&observer));
78 EXPECT_CALL(*mock_delegate_, AddObserver(&observer));
79 bridged_notifier_.AddObserver(&observer);
80 }
81
82 TEST_F(BridgedSyncNotifierTest, RemoveObserver) {
83 MockSyncNotifierObserver observer;
84 EXPECT_CALL(mock_bridge_, RemoveObserver(&observer));
85 EXPECT_CALL(*mock_delegate_, RemoveObserver(&observer));
86 bridged_notifier_.RemoveObserver(&observer);
87 }
88
89 TEST_F(BridgedSyncNotifierTest, SetUniqueId) {
90 std::string unique_id = "unique id";
91 EXPECT_CALL(*mock_delegate_, SetUniqueId(unique_id));
92 bridged_notifier_.SetUniqueId(unique_id);
93 }
94
95 TEST_F(BridgedSyncNotifierTest, SetState) {
96 std::string state = "state";
97 EXPECT_CALL(*mock_delegate_, SetState(state));
98 bridged_notifier_.SetState(state);
99 }
100
101 TEST_F(BridgedSyncNotifierTest, UpdateCredentials) {
102 std::string email = "email";
103 std::string token = "token";
104 EXPECT_CALL(*mock_delegate_, UpdateCredentials(email, token));
105 bridged_notifier_.UpdateCredentials(email, token);
106 }
107
108 TEST_F(BridgedSyncNotifierTest, UpdateEnabledTypes) {
109 syncable::ModelTypeSet enabled_types(syncable::BOOKMARKS,
110 syncable::PREFERENCES);
111 EXPECT_CALL(*mock_delegate_,
112 UpdateEnabledTypes(HasModelTypes(enabled_types)));
113 bridged_notifier_.UpdateEnabledTypes(enabled_types);
114 }
115
116 TEST_F(BridgedSyncNotifierTest, SendNotification) {
117 syncable::ModelTypeSet changed_types(syncable::SESSIONS,
118 syncable::EXTENSIONS);
119 EXPECT_CALL(*mock_delegate_, SendNotification(HasModelTypes(changed_types)));
120 bridged_notifier_.SendNotification(changed_types);
121 }
122
123 } // namespace
124 } // namespace sync_notifier
OLDNEW
« no previous file with comments | « chrome/browser/sync/notifier/bridged_sync_notifier.cc ('k') | chrome/browser/sync/notifier/chrome_sync_notification_bridge.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698