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

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

Issue 10824161: [Sync] Avoid unregistering object IDs on shutdown (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Work around brittle unit test Created 8 years, 4 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 17 matching lines...) Expand all
28 using syncer::HasModelTypes; 28 using syncer::HasModelTypes;
29 29
30 class MockChromeSyncNotificationBridge : public ChromeSyncNotificationBridge { 30 class MockChromeSyncNotificationBridge : public ChromeSyncNotificationBridge {
31 public: 31 public:
32 MockChromeSyncNotificationBridge( 32 MockChromeSyncNotificationBridge(
33 const Profile* profile, 33 const Profile* profile,
34 const scoped_refptr<base::SequencedTaskRunner>& sync_task_runner) 34 const scoped_refptr<base::SequencedTaskRunner>& sync_task_runner)
35 : ChromeSyncNotificationBridge(profile, sync_task_runner) {} 35 : ChromeSyncNotificationBridge(profile, sync_task_runner) {}
36 virtual ~MockChromeSyncNotificationBridge() {} 36 virtual ~MockChromeSyncNotificationBridge() {}
37 37
38 MOCK_METHOD2(UpdateRegisteredIds, void(syncer::SyncNotifierObserver*, 38 MOCK_METHOD1(RegisterHandler, void(syncer::SyncNotifierObserver*));
39 const syncer::ObjectIdSet&)); 39 MOCK_METHOD2(UpdateRegisteredIds,
40 void(syncer::SyncNotifierObserver*,
41 const syncer::ObjectIdSet&));
42 MOCK_METHOD1(UnregisterHandler, void(syncer::SyncNotifierObserver*));
40 }; 43 };
41 44
42 class MockSyncNotifier : public syncer::SyncNotifier { 45 class MockSyncNotifier : public syncer::SyncNotifier {
43 public: 46 public:
44 MockSyncNotifier() {} 47 MockSyncNotifier() {}
45 virtual ~MockSyncNotifier() {} 48 virtual ~MockSyncNotifier() {}
46 49
50 MOCK_METHOD1(RegisterHandler, void(syncer::SyncNotifierObserver*));
47 MOCK_METHOD2(UpdateRegisteredIds, 51 MOCK_METHOD2(UpdateRegisteredIds,
48 void(syncer::SyncNotifierObserver*, const syncer::ObjectIdSet&)); 52 void(syncer::SyncNotifierObserver*,
53 const syncer::ObjectIdSet&));
54 MOCK_METHOD1(UnregisterHandler, void(syncer::SyncNotifierObserver*));
49 MOCK_METHOD1(SetUniqueId, void(const std::string&)); 55 MOCK_METHOD1(SetUniqueId, void(const std::string&));
50 MOCK_METHOD1(SetStateDeprecated, void(const std::string&)); 56 MOCK_METHOD1(SetStateDeprecated, void(const std::string&));
51 MOCK_METHOD2(UpdateCredentials, void(const std::string&, const std::string&)); 57 MOCK_METHOD2(UpdateCredentials, void(const std::string&, const std::string&));
52 MOCK_METHOD1(SendNotification, void(syncer::ModelTypeSet)); 58 MOCK_METHOD1(SendNotification, void(syncer::ModelTypeSet));
53 }; 59 };
54 60
55 // All tests just verify that each call is passed through to the delegate, with 61 // All tests just verify that each call is passed through to the delegate, with
56 // the exception of UpdateRegisteredIds, which also verifies the call is 62 // the exception of RegisterHandler, UnregisterHandler, and
57 // forwarded to the bridge. 63 // UpdateRegisteredIds, which also verifies the call is forwarded to the
64 // bridge.
58 class BridgedSyncNotifierTest : public testing::Test { 65 class BridgedSyncNotifierTest : public testing::Test {
59 public: 66 public:
60 BridgedSyncNotifierTest() 67 BridgedSyncNotifierTest()
61 : ui_thread_(BrowserThread::UI, &ui_loop_), 68 : ui_thread_(BrowserThread::UI, &ui_loop_),
62 mock_bridge_(&mock_profile_, ui_loop_.message_loop_proxy()), 69 mock_bridge_(&mock_profile_, ui_loop_.message_loop_proxy()),
63 mock_delegate_(new MockSyncNotifier), // Owned by bridged_notifier_. 70 mock_delegate_(new MockSyncNotifier), // Owned by bridged_notifier_.
64 bridged_notifier_(&mock_bridge_, mock_delegate_) {} 71 bridged_notifier_(&mock_bridge_, mock_delegate_) {}
65 virtual ~BridgedSyncNotifierTest() {} 72 virtual ~BridgedSyncNotifierTest() {}
66 73
67 protected: 74 protected:
68 MessageLoop ui_loop_; 75 MessageLoop ui_loop_;
69 content::TestBrowserThread ui_thread_; 76 content::TestBrowserThread ui_thread_;
70 NiceMock<ProfileMock> mock_profile_; 77 NiceMock<ProfileMock> mock_profile_;
71 StrictMock<MockChromeSyncNotificationBridge> mock_bridge_; 78 StrictMock<MockChromeSyncNotificationBridge> mock_bridge_;
72 MockSyncNotifier* mock_delegate_; 79 MockSyncNotifier* mock_delegate_;
73 BridgedSyncNotifier bridged_notifier_; 80 BridgedSyncNotifier bridged_notifier_;
74 }; 81 };
75 82
83 TEST_F(BridgedSyncNotifierTest, RegisterHandler) {
84 syncer::MockSyncNotifierObserver observer;
85 EXPECT_CALL(mock_bridge_, RegisterHandler(&observer));
86 EXPECT_CALL(*mock_delegate_, RegisterHandler(&observer));
87 bridged_notifier_.RegisterHandler(&observer);
88 }
89
76 TEST_F(BridgedSyncNotifierTest, UpdateRegisteredIds) { 90 TEST_F(BridgedSyncNotifierTest, UpdateRegisteredIds) {
91 EXPECT_CALL(mock_bridge_, UpdateRegisteredIds(
92 NULL, syncer::ObjectIdSet()));
93 EXPECT_CALL(*mock_delegate_, UpdateRegisteredIds(
94 NULL, syncer::ObjectIdSet()));
95 bridged_notifier_.UpdateRegisteredIds(NULL, syncer::ObjectIdSet());
96 }
97
98 TEST_F(BridgedSyncNotifierTest, UnregisterHandler) {
77 syncer::MockSyncNotifierObserver observer; 99 syncer::MockSyncNotifierObserver observer;
78 EXPECT_CALL(mock_bridge_, UpdateRegisteredIds( 100 EXPECT_CALL(mock_bridge_, UnregisterHandler(&observer));
79 &observer, syncer::ObjectIdSet())); 101 EXPECT_CALL(*mock_delegate_, UnregisterHandler(&observer));
80 EXPECT_CALL(*mock_delegate_, UpdateRegisteredIds( 102 bridged_notifier_.UnregisterHandler(&observer);
81 &observer, syncer::ObjectIdSet()));
82 bridged_notifier_.UpdateRegisteredIds(&observer, syncer::ObjectIdSet());
83 } 103 }
84 104
85 TEST_F(BridgedSyncNotifierTest, SetUniqueId) { 105 TEST_F(BridgedSyncNotifierTest, SetUniqueId) {
86 std::string unique_id = "unique id"; 106 std::string unique_id = "unique id";
87 EXPECT_CALL(*mock_delegate_, SetUniqueId(unique_id)); 107 EXPECT_CALL(*mock_delegate_, SetUniqueId(unique_id));
88 bridged_notifier_.SetUniqueId(unique_id); 108 bridged_notifier_.SetUniqueId(unique_id);
89 } 109 }
90 110
91 TEST_F(BridgedSyncNotifierTest, SetStateDeprecated) { 111 TEST_F(BridgedSyncNotifierTest, SetStateDeprecated) {
92 std::string state = "state"; 112 std::string state = "state";
93 EXPECT_CALL(*mock_delegate_, SetStateDeprecated(state)); 113 EXPECT_CALL(*mock_delegate_, SetStateDeprecated(state));
94 bridged_notifier_.SetStateDeprecated(state); 114 bridged_notifier_.SetStateDeprecated(state);
95 } 115 }
96 116
97 TEST_F(BridgedSyncNotifierTest, UpdateCredentials) { 117 TEST_F(BridgedSyncNotifierTest, UpdateCredentials) {
98 std::string email = "email"; 118 std::string email = "email";
99 std::string token = "token"; 119 std::string token = "token";
100 EXPECT_CALL(*mock_delegate_, UpdateCredentials(email, token)); 120 EXPECT_CALL(*mock_delegate_, UpdateCredentials(email, token));
101 bridged_notifier_.UpdateCredentials(email, token); 121 bridged_notifier_.UpdateCredentials(email, token);
102 } 122 }
103 123
104 TEST_F(BridgedSyncNotifierTest, SendNotification) { 124 TEST_F(BridgedSyncNotifierTest, SendNotification) {
105 syncer::ModelTypeSet changed_types(syncer::SESSIONS, syncer::EXTENSIONS); 125 syncer::ModelTypeSet changed_types(syncer::SESSIONS, syncer::EXTENSIONS);
106 EXPECT_CALL(*mock_delegate_, SendNotification(HasModelTypes(changed_types))); 126 EXPECT_CALL(*mock_delegate_, SendNotification(HasModelTypes(changed_types)));
107 bridged_notifier_.SendNotification(changed_types); 127 bridged_notifier_.SendNotification(changed_types);
108 } 128 }
109 129
110 } // namespace 130 } // namespace
111 } // namespace browser_sync 131 } // namespace browser_sync
OLDNEW
« no previous file with comments | « chrome/browser/sync/glue/bridged_sync_notifier.cc ('k') | chrome/browser/sync/glue/chrome_sync_notification_bridge.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698