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 11 matching lines...) Expand all Loading... |
22 namespace browser_sync { | 22 namespace browser_sync { |
23 namespace { | 23 namespace { |
24 | 24 |
25 using ::testing::NiceMock; | 25 using ::testing::NiceMock; |
26 using ::testing::StrictMock; | 26 using ::testing::StrictMock; |
27 using content::BrowserThread; | 27 using content::BrowserThread; |
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 : ChromeSyncNotificationBridge(&mock_profile_) {} | 33 const Profile* profile, |
| 34 const scoped_refptr<base::SequencedTaskRunner>& sync_task_runner) |
| 35 : ChromeSyncNotificationBridge(profile, sync_task_runner) {} |
34 virtual ~MockChromeSyncNotificationBridge() {} | 36 virtual ~MockChromeSyncNotificationBridge() {} |
35 | 37 |
36 MOCK_METHOD1(AddObserver, void(syncer::SyncNotifierObserver*)); | 38 MOCK_METHOD1(AddObserver, void(syncer::SyncNotifierObserver*)); |
37 MOCK_METHOD1(RemoveObserver, void(syncer::SyncNotifierObserver*)); | 39 MOCK_METHOD1(RemoveObserver, void(syncer::SyncNotifierObserver*)); |
38 private: | |
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_METHOD1(AddObserver, void(syncer::SyncNotifierObserver*)); |
48 MOCK_METHOD1(RemoveObserver, void(syncer::SyncNotifierObserver*)); | 48 MOCK_METHOD1(RemoveObserver, void(syncer::SyncNotifierObserver*)); |
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)); | 52 MOCK_METHOD1(UpdateEnabledTypes, void(syncer::ModelTypeSet)); |
53 MOCK_METHOD1(SendNotification, void(syncer::ModelTypeSet)); | 53 MOCK_METHOD1(SendNotification, void(syncer::ModelTypeSet)); |
54 }; | 54 }; |
55 | 55 |
56 // All tests just verify that each call is passed through to the delegate, with | 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 | 57 // the exception of AddObserver/RemoveObserver, which also verify the observer |
58 // is registered with the bridge. | 58 // is registered with the bridge. |
59 class BridgedSyncNotifierTest : public testing::Test { | 59 class BridgedSyncNotifierTest : public testing::Test { |
60 public: | 60 public: |
61 BridgedSyncNotifierTest() | 61 BridgedSyncNotifierTest() |
62 : ui_thread_(BrowserThread::UI, &ui_loop_), | 62 : ui_thread_(BrowserThread::UI, &ui_loop_), |
| 63 mock_bridge_(&mock_profile_, ui_loop_.message_loop_proxy()), |
63 mock_delegate_(new MockSyncNotifier), // Owned by bridged_notifier_. | 64 mock_delegate_(new MockSyncNotifier), // Owned by bridged_notifier_. |
64 bridged_notifier_(&mock_bridge_, mock_delegate_) {} | 65 bridged_notifier_(&mock_bridge_, mock_delegate_) {} |
65 virtual ~BridgedSyncNotifierTest() {} | 66 virtual ~BridgedSyncNotifierTest() {} |
66 | 67 |
67 protected: | 68 protected: |
68 MessageLoop ui_loop_; | 69 MessageLoop ui_loop_; |
69 content::TestBrowserThread ui_thread_; | 70 content::TestBrowserThread ui_thread_; |
| 71 NiceMock<ProfileMock> mock_profile_; |
70 StrictMock<MockChromeSyncNotificationBridge> mock_bridge_; | 72 StrictMock<MockChromeSyncNotificationBridge> mock_bridge_; |
71 MockSyncNotifier* mock_delegate_; | 73 MockSyncNotifier* mock_delegate_; |
72 BridgedSyncNotifier bridged_notifier_; | 74 BridgedSyncNotifier bridged_notifier_; |
73 }; | 75 }; |
74 | 76 |
75 TEST_F(BridgedSyncNotifierTest, AddObserver) { | 77 TEST_F(BridgedSyncNotifierTest, AddObserver) { |
76 syncer::MockSyncNotifierObserver observer; | 78 syncer::MockSyncNotifierObserver observer; |
77 EXPECT_CALL(mock_bridge_, AddObserver(&observer)); | 79 EXPECT_CALL(mock_bridge_, AddObserver(&observer)); |
78 EXPECT_CALL(*mock_delegate_, AddObserver(&observer)); | 80 EXPECT_CALL(*mock_delegate_, AddObserver(&observer)); |
79 bridged_notifier_.AddObserver(&observer); | 81 bridged_notifier_.AddObserver(&observer); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 } | 115 } |
114 | 116 |
115 TEST_F(BridgedSyncNotifierTest, SendNotification) { | 117 TEST_F(BridgedSyncNotifierTest, SendNotification) { |
116 syncer::ModelTypeSet changed_types(syncer::SESSIONS, syncer::EXTENSIONS); | 118 syncer::ModelTypeSet changed_types(syncer::SESSIONS, syncer::EXTENSIONS); |
117 EXPECT_CALL(*mock_delegate_, SendNotification(HasModelTypes(changed_types))); | 119 EXPECT_CALL(*mock_delegate_, SendNotification(HasModelTypes(changed_types))); |
118 bridged_notifier_.SendNotification(changed_types); | 120 bridged_notifier_.SendNotification(changed_types); |
119 } | 121 } |
120 | 122 |
121 } // namespace | 123 } // namespace |
122 } // namespace browser_sync | 124 } // namespace browser_sync |
OLD | NEW |