OLD | NEW |
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 Loading... |
37 MOCK_METHOD1(RemoveObserver, void(syncer::SyncNotifierObserver*)); | 37 MOCK_METHOD1(RemoveObserver, void(syncer::SyncNotifierObserver*)); |
38 private: | 38 private: |
39 NiceMock<ProfileMock> mock_profile_; | 39 NiceMock<ProfileMock> mock_profile_; |
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_delegate_(new MockSyncNotifier), // Owned by bridged_notifier_. | 62 mock_delegate_(new MockSyncNotifier), // Owned by bridged_notifier_. |
64 bridged_notifier_(&mock_bridge_, mock_delegate_) {} | 63 bridged_notifier_(&mock_bridge_, mock_delegate_) {} |
65 virtual ~BridgedSyncNotifierTest() {} | 64 virtual ~BridgedSyncNotifierTest() {} |
66 | 65 |
67 protected: | 66 protected: |
68 MessageLoop ui_loop_; | 67 MessageLoop ui_loop_; |
69 content::TestBrowserThread ui_thread_; | 68 content::TestBrowserThread ui_thread_; |
70 StrictMock<MockChromeSyncNotificationBridge> mock_bridge_; | 69 StrictMock<MockChromeSyncNotificationBridge> mock_bridge_; |
71 MockSyncNotifier* mock_delegate_; | 70 MockSyncNotifier* mock_delegate_; |
72 BridgedSyncNotifier bridged_notifier_; | 71 BridgedSyncNotifier bridged_notifier_; |
73 }; | 72 }; |
74 | 73 |
75 TEST_F(BridgedSyncNotifierTest, AddObserver) { | 74 TEST_F(BridgedSyncNotifierTest, UpdateRegisteredIds) { |
76 syncer::MockSyncNotifierObserver observer; | 75 syncer::MockSyncNotifierObserver observer; |
77 EXPECT_CALL(mock_bridge_, AddObserver(&observer)); | 76 EXPECT_CALL(*mock_delegate_, UpdateRegisteredIds( |
78 EXPECT_CALL(*mock_delegate_, AddObserver(&observer)); | 77 &observer, syncer::ObjectIdSet())); |
79 bridged_notifier_.AddObserver(&observer); | 78 bridged_notifier_.UpdateRegisteredIds(&observer, syncer::ObjectIdSet()); |
80 } | |
81 | |
82 TEST_F(BridgedSyncNotifierTest, RemoveObserver) { | |
83 syncer::MockSyncNotifierObserver observer; | |
84 EXPECT_CALL(mock_bridge_, RemoveObserver(&observer)); | |
85 EXPECT_CALL(*mock_delegate_, RemoveObserver(&observer)); | |
86 bridged_notifier_.RemoveObserver(&observer); | |
87 } | 79 } |
88 | 80 |
89 TEST_F(BridgedSyncNotifierTest, SetUniqueId) { | 81 TEST_F(BridgedSyncNotifierTest, SetUniqueId) { |
90 std::string unique_id = "unique id"; | 82 std::string unique_id = "unique id"; |
91 EXPECT_CALL(*mock_delegate_, SetUniqueId(unique_id)); | 83 EXPECT_CALL(*mock_delegate_, SetUniqueId(unique_id)); |
92 bridged_notifier_.SetUniqueId(unique_id); | 84 bridged_notifier_.SetUniqueId(unique_id); |
93 } | 85 } |
94 | 86 |
95 TEST_F(BridgedSyncNotifierTest, SetStateDeprecated) { | 87 TEST_F(BridgedSyncNotifierTest, SetStateDeprecated) { |
96 std::string state = "state"; | 88 std::string state = "state"; |
97 EXPECT_CALL(*mock_delegate_, SetStateDeprecated(state)); | 89 EXPECT_CALL(*mock_delegate_, SetStateDeprecated(state)); |
98 bridged_notifier_.SetStateDeprecated(state); | 90 bridged_notifier_.SetStateDeprecated(state); |
99 } | 91 } |
100 | 92 |
101 TEST_F(BridgedSyncNotifierTest, UpdateCredentials) { | 93 TEST_F(BridgedSyncNotifierTest, UpdateCredentials) { |
102 std::string email = "email"; | 94 std::string email = "email"; |
103 std::string token = "token"; | 95 std::string token = "token"; |
104 EXPECT_CALL(*mock_delegate_, UpdateCredentials(email, token)); | 96 EXPECT_CALL(*mock_delegate_, UpdateCredentials(email, token)); |
105 bridged_notifier_.UpdateCredentials(email, token); | 97 bridged_notifier_.UpdateCredentials(email, token); |
106 } | 98 } |
107 | 99 |
108 TEST_F(BridgedSyncNotifierTest, UpdateEnabledTypes) { | |
109 syncer::ModelTypeSet enabled_types(syncer::BOOKMARKS, syncer::PREFERENCES); | |
110 EXPECT_CALL(*mock_delegate_, | |
111 UpdateEnabledTypes(HasModelTypes(enabled_types))); | |
112 bridged_notifier_.UpdateEnabledTypes(enabled_types); | |
113 } | |
114 | |
115 TEST_F(BridgedSyncNotifierTest, SendNotification) { | 100 TEST_F(BridgedSyncNotifierTest, SendNotification) { |
116 syncer::ModelTypeSet changed_types(syncer::SESSIONS, syncer::EXTENSIONS); | 101 syncer::ModelTypeSet changed_types(syncer::SESSIONS, syncer::EXTENSIONS); |
117 EXPECT_CALL(*mock_delegate_, SendNotification(HasModelTypes(changed_types))); | 102 EXPECT_CALL(*mock_delegate_, SendNotification(HasModelTypes(changed_types))); |
118 bridged_notifier_.SendNotification(changed_types); | 103 bridged_notifier_.SendNotification(changed_types); |
119 } | 104 } |
120 | 105 |
121 } // namespace | 106 } // namespace |
122 } // namespace browser_sync | 107 } // namespace browser_sync |
OLD | NEW |