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

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

Issue 10702074: Refactor sync-specific parts out of SyncNotifier/SyncNotifierObserver (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: FOR_THE_HORDE Created 8 years, 5 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
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 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 "chrome/browser/sync/glue/bridged_sync_notifier.h" 5 #include "chrome/browser/sync/glue/bridged_sync_notifier.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/compiler_specific.h" 9 #include "base/compiler_specific.h"
10 #include "base/message_loop.h" 10 #include "base/message_loop.h"
(...skipping 26 matching lines...) Expand all
37 37
38 MOCK_METHOD1(AddObserver, void(syncer::SyncNotifierObserver*)); 38 MOCK_METHOD1(AddObserver, void(syncer::SyncNotifierObserver*));
39 MOCK_METHOD1(RemoveObserver, void(syncer::SyncNotifierObserver*)); 39 MOCK_METHOD1(RemoveObserver, void(syncer::SyncNotifierObserver*));
40 }; 40 };
41 41
42 class MockSyncNotifier : public syncer::SyncNotifier { 42 class MockSyncNotifier : public syncer::SyncNotifier {
43 public: 43 public:
44 MockSyncNotifier() {} 44 MockSyncNotifier() {}
45 virtual ~MockSyncNotifier() {} 45 virtual ~MockSyncNotifier() {}
46 46
47 MOCK_METHOD1(AddObserver, void(syncer::SyncNotifierObserver*)); 47 MOCK_METHOD2(UpdateRegisteredIds,
48 MOCK_METHOD1(RemoveObserver, void(syncer::SyncNotifierObserver*)); 48 void(syncer::SyncNotifierObserver*, const syncer::ObjectIdSet&));
49 MOCK_METHOD1(SetUniqueId, void(const std::string&)); 49 MOCK_METHOD1(SetUniqueId, void(const std::string&));
50 MOCK_METHOD1(SetStateDeprecated, void(const std::string&)); 50 MOCK_METHOD1(SetStateDeprecated, void(const std::string&));
51 MOCK_METHOD2(UpdateCredentials, void(const std::string&, const std::string&)); 51 MOCK_METHOD2(UpdateCredentials, void(const std::string&, const std::string&));
52 MOCK_METHOD1(UpdateEnabledTypes, void(syncer::ModelTypeSet));
53 MOCK_METHOD1(SendNotification, void(syncer::ModelTypeSet)); 52 MOCK_METHOD1(SendNotification, void(syncer::ModelTypeSet));
54 }; 53 };
55 54
56 // All tests just verify that each call is passed through to the delegate, with 55 // 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 56 // the exception of AddObserver/RemoveObserver, which also verify the observer
58 // is registered with the bridge. 57 // is registered with the bridge.
59 class BridgedSyncNotifierTest : public testing::Test { 58 class BridgedSyncNotifierTest : public testing::Test {
60 public: 59 public:
61 BridgedSyncNotifierTest() 60 BridgedSyncNotifierTest()
62 : ui_thread_(BrowserThread::UI, &ui_loop_), 61 : ui_thread_(BrowserThread::UI, &ui_loop_),
63 mock_bridge_(&mock_profile_, ui_loop_.message_loop_proxy()), 62 mock_bridge_(&mock_profile_, ui_loop_.message_loop_proxy()),
64 mock_delegate_(new MockSyncNotifier), // Owned by bridged_notifier_. 63 mock_delegate_(new MockSyncNotifier), // Owned by bridged_notifier_.
65 bridged_notifier_(&mock_bridge_, mock_delegate_) {} 64 bridged_notifier_(&mock_bridge_, mock_delegate_) {}
66 virtual ~BridgedSyncNotifierTest() {} 65 virtual ~BridgedSyncNotifierTest() {}
67 66
68 protected: 67 protected:
69 MessageLoop ui_loop_; 68 MessageLoop ui_loop_;
70 content::TestBrowserThread ui_thread_; 69 content::TestBrowserThread ui_thread_;
71 NiceMock<ProfileMock> mock_profile_; 70 NiceMock<ProfileMock> mock_profile_;
72 StrictMock<MockChromeSyncNotificationBridge> mock_bridge_; 71 StrictMock<MockChromeSyncNotificationBridge> mock_bridge_;
73 MockSyncNotifier* mock_delegate_; 72 MockSyncNotifier* mock_delegate_;
74 BridgedSyncNotifier bridged_notifier_; 73 BridgedSyncNotifier bridged_notifier_;
75 }; 74 };
76 75
77 TEST_F(BridgedSyncNotifierTest, AddObserver) { 76 TEST_F(BridgedSyncNotifierTest, UpdateRegisteredIds) {
78 syncer::MockSyncNotifierObserver observer; 77 syncer::MockSyncNotifierObserver observer;
79 EXPECT_CALL(mock_bridge_, AddObserver(&observer)); 78 EXPECT_CALL(*mock_delegate_, UpdateRegisteredIds(
akalin 2012/07/21 01:09:47 expect on the mock_bridge_ also?
dcheng 2012/07/21 14:06:53 Done.
80 EXPECT_CALL(*mock_delegate_, AddObserver(&observer)); 79 &observer, syncer::ObjectIdSet()));
81 bridged_notifier_.AddObserver(&observer); 80 bridged_notifier_.UpdateRegisteredIds(&observer, syncer::ObjectIdSet());
82 }
83
84 TEST_F(BridgedSyncNotifierTest, RemoveObserver) {
85 syncer::MockSyncNotifierObserver observer;
86 EXPECT_CALL(mock_bridge_, RemoveObserver(&observer));
87 EXPECT_CALL(*mock_delegate_, RemoveObserver(&observer));
88 bridged_notifier_.RemoveObserver(&observer);
89 } 81 }
90 82
91 TEST_F(BridgedSyncNotifierTest, SetUniqueId) { 83 TEST_F(BridgedSyncNotifierTest, SetUniqueId) {
92 std::string unique_id = "unique id"; 84 std::string unique_id = "unique id";
93 EXPECT_CALL(*mock_delegate_, SetUniqueId(unique_id)); 85 EXPECT_CALL(*mock_delegate_, SetUniqueId(unique_id));
94 bridged_notifier_.SetUniqueId(unique_id); 86 bridged_notifier_.SetUniqueId(unique_id);
95 } 87 }
96 88
97 TEST_F(BridgedSyncNotifierTest, SetStateDeprecated) { 89 TEST_F(BridgedSyncNotifierTest, SetStateDeprecated) {
98 std::string state = "state"; 90 std::string state = "state";
99 EXPECT_CALL(*mock_delegate_, SetStateDeprecated(state)); 91 EXPECT_CALL(*mock_delegate_, SetStateDeprecated(state));
100 bridged_notifier_.SetStateDeprecated(state); 92 bridged_notifier_.SetStateDeprecated(state);
101 } 93 }
102 94
103 TEST_F(BridgedSyncNotifierTest, UpdateCredentials) { 95 TEST_F(BridgedSyncNotifierTest, UpdateCredentials) {
104 std::string email = "email"; 96 std::string email = "email";
105 std::string token = "token"; 97 std::string token = "token";
106 EXPECT_CALL(*mock_delegate_, UpdateCredentials(email, token)); 98 EXPECT_CALL(*mock_delegate_, UpdateCredentials(email, token));
107 bridged_notifier_.UpdateCredentials(email, token); 99 bridged_notifier_.UpdateCredentials(email, token);
108 } 100 }
109 101
110 TEST_F(BridgedSyncNotifierTest, UpdateEnabledTypes) {
111 syncer::ModelTypeSet enabled_types(syncer::BOOKMARKS, syncer::PREFERENCES);
112 EXPECT_CALL(*mock_delegate_,
113 UpdateEnabledTypes(HasModelTypes(enabled_types)));
114 bridged_notifier_.UpdateEnabledTypes(enabled_types);
115 }
116
117 TEST_F(BridgedSyncNotifierTest, SendNotification) { 102 TEST_F(BridgedSyncNotifierTest, SendNotification) {
118 syncer::ModelTypeSet changed_types(syncer::SESSIONS, syncer::EXTENSIONS); 103 syncer::ModelTypeSet changed_types(syncer::SESSIONS, syncer::EXTENSIONS);
119 EXPECT_CALL(*mock_delegate_, SendNotification(HasModelTypes(changed_types))); 104 EXPECT_CALL(*mock_delegate_, SendNotification(HasModelTypes(changed_types)));
120 bridged_notifier_.SendNotification(changed_types); 105 bridged_notifier_.SendNotification(changed_types);
121 } 106 }
122 107
123 } // namespace 108 } // namespace
124 } // namespace browser_sync 109 } // namespace browser_sync
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698