| 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" |
| 11 #include "base/threading/thread.h" | 11 #include "base/threading/thread.h" |
| 12 #include "chrome/browser/sync/glue/chrome_sync_notification_bridge.h" | 12 #include "chrome/browser/sync/glue/chrome_sync_notification_bridge.h" |
| 13 #include "chrome/test/base/profile_mock.h" | 13 #include "chrome/test/base/profile_mock.h" |
| 14 #include "content/public/test/test_browser_thread.h" | 14 #include "content/public/test/test_browser_thread.h" |
| 15 #include "sync/internal_api/public/base/model_type.h" | 15 #include "sync/internal_api/public/base/model_type.h" |
| 16 #include "sync/internal_api/public/base/model_type_test_util.h" | 16 #include "sync/internal_api/public/base/model_type_test_util.h" |
| 17 #include "sync/notifier/mock_sync_notifier_observer.h" | 17 #include "sync/notifier/mock_sync_notifier_observer.h" |
| 18 #include "sync/notifier/sync_notifier.h" | 18 #include "sync/notifier/sync_notifier.h" |
| 19 #include "testing/gmock/include/gmock/gmock.h" | 19 #include "testing/gmock/include/gmock/gmock.h" |
| 20 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
| 21 | 21 |
| 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 const char kHandlerName[] = "MockObserver"; |
| 31 |
| 30 class MockChromeSyncNotificationBridge : public ChromeSyncNotificationBridge { | 32 class MockChromeSyncNotificationBridge : public ChromeSyncNotificationBridge { |
| 31 public: | 33 public: |
| 32 MockChromeSyncNotificationBridge( | 34 MockChromeSyncNotificationBridge( |
| 33 const Profile* profile, | 35 const Profile* profile, |
| 34 const scoped_refptr<base::SequencedTaskRunner>& sync_task_runner) | 36 const scoped_refptr<base::SequencedTaskRunner>& sync_task_runner) |
| 35 : ChromeSyncNotificationBridge(profile, sync_task_runner) {} | 37 : ChromeSyncNotificationBridge(profile, sync_task_runner) {} |
| 36 virtual ~MockChromeSyncNotificationBridge() {} | 38 virtual ~MockChromeSyncNotificationBridge() {} |
| 37 | 39 |
| 38 MOCK_METHOD2(UpdateRegisteredIds, void(syncer::SyncNotifierObserver*, | 40 MOCK_METHOD2(SetHandler, |
| 39 const syncer::ObjectIdSet&)); | 41 void(const std::string&, syncer::SyncNotifierObserver*)); |
| 42 MOCK_METHOD2(UpdateRegisteredIds, |
| 43 void(const std::string&, const syncer::ObjectIdSet&)); |
| 40 }; | 44 }; |
| 41 | 45 |
| 42 class MockSyncNotifier : public syncer::SyncNotifier { | 46 class MockSyncNotifier : public syncer::SyncNotifier { |
| 43 public: | 47 public: |
| 44 MockSyncNotifier() {} | 48 MockSyncNotifier() {} |
| 45 virtual ~MockSyncNotifier() {} | 49 virtual ~MockSyncNotifier() {} |
| 46 | 50 |
| 51 MOCK_METHOD2(SetHandler, |
| 52 void(const std::string&, syncer::SyncNotifierObserver*)); |
| 47 MOCK_METHOD2(UpdateRegisteredIds, | 53 MOCK_METHOD2(UpdateRegisteredIds, |
| 48 void(syncer::SyncNotifierObserver*, const syncer::ObjectIdSet&)); | 54 void(const std::string&, const syncer::ObjectIdSet&)); |
| 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 |
| 56 // the exception of UpdateRegisteredIds, which also verifies the call is | 62 // delegate, with the exception of SetHandler and UpdateRegisteredIds, |
| 57 // forwarded to the bridge. | 63 // which also verifies the call is forwarded to the bridge. |
| 58 class BridgedSyncNotifierTest : public testing::Test { | 64 class BridgedSyncNotifierTest : public testing::Test { |
| 59 public: | 65 public: |
| 60 BridgedSyncNotifierTest() | 66 BridgedSyncNotifierTest() |
| 61 : ui_thread_(BrowserThread::UI, &ui_loop_), | 67 : ui_thread_(BrowserThread::UI, &ui_loop_), |
| 62 mock_bridge_(&mock_profile_, ui_loop_.message_loop_proxy()), | 68 mock_bridge_(&mock_profile_, ui_loop_.message_loop_proxy()), |
| 63 mock_delegate_(new MockSyncNotifier), // Owned by bridged_notifier_. | 69 mock_delegate_(new MockSyncNotifier), // Owned by bridged_notifier_. |
| 64 bridged_notifier_(&mock_bridge_, mock_delegate_) {} | 70 bridged_notifier_(&mock_bridge_, mock_delegate_) {} |
| 65 virtual ~BridgedSyncNotifierTest() {} | 71 virtual ~BridgedSyncNotifierTest() {} |
| 66 | 72 |
| 67 protected: | 73 protected: |
| 68 MessageLoop ui_loop_; | 74 MessageLoop ui_loop_; |
| 69 content::TestBrowserThread ui_thread_; | 75 content::TestBrowserThread ui_thread_; |
| 70 NiceMock<ProfileMock> mock_profile_; | 76 NiceMock<ProfileMock> mock_profile_; |
| 71 StrictMock<MockChromeSyncNotificationBridge> mock_bridge_; | 77 StrictMock<MockChromeSyncNotificationBridge> mock_bridge_; |
| 72 MockSyncNotifier* mock_delegate_; | 78 MockSyncNotifier* mock_delegate_; |
| 73 BridgedSyncNotifier bridged_notifier_; | 79 BridgedSyncNotifier bridged_notifier_; |
| 74 }; | 80 }; |
| 75 | 81 |
| 82 TEST_F(BridgedSyncNotifierTest, SetHandler) { |
| 83 syncer::MockSyncNotifierObserver observer; |
| 84 EXPECT_CALL(mock_bridge_, SetHandler(kHandlerName, &observer)); |
| 85 EXPECT_CALL(*mock_delegate_, SetHandler(kHandlerName, &observer)); |
| 86 bridged_notifier_.SetHandler(kHandlerName, &observer); |
| 87 } |
| 88 |
| 76 TEST_F(BridgedSyncNotifierTest, UpdateRegisteredIds) { | 89 TEST_F(BridgedSyncNotifierTest, UpdateRegisteredIds) { |
| 77 syncer::MockSyncNotifierObserver observer; | |
| 78 EXPECT_CALL(mock_bridge_, UpdateRegisteredIds( | 90 EXPECT_CALL(mock_bridge_, UpdateRegisteredIds( |
| 79 &observer, syncer::ObjectIdSet())); | 91 kHandlerName, syncer::ObjectIdSet())); |
| 80 EXPECT_CALL(*mock_delegate_, UpdateRegisteredIds( | 92 EXPECT_CALL(*mock_delegate_, UpdateRegisteredIds( |
| 81 &observer, syncer::ObjectIdSet())); | 93 kHandlerName, syncer::ObjectIdSet())); |
| 82 bridged_notifier_.UpdateRegisteredIds(&observer, syncer::ObjectIdSet()); | 94 bridged_notifier_.UpdateRegisteredIds(kHandlerName, syncer::ObjectIdSet()); |
| 83 } | 95 } |
| 84 | 96 |
| 85 TEST_F(BridgedSyncNotifierTest, SetUniqueId) { | 97 TEST_F(BridgedSyncNotifierTest, SetUniqueId) { |
| 86 std::string unique_id = "unique id"; | 98 std::string unique_id = "unique id"; |
| 87 EXPECT_CALL(*mock_delegate_, SetUniqueId(unique_id)); | 99 EXPECT_CALL(*mock_delegate_, SetUniqueId(unique_id)); |
| 88 bridged_notifier_.SetUniqueId(unique_id); | 100 bridged_notifier_.SetUniqueId(unique_id); |
| 89 } | 101 } |
| 90 | 102 |
| 91 TEST_F(BridgedSyncNotifierTest, SetStateDeprecated) { | 103 TEST_F(BridgedSyncNotifierTest, SetStateDeprecated) { |
| 92 std::string state = "state"; | 104 std::string state = "state"; |
| 93 EXPECT_CALL(*mock_delegate_, SetStateDeprecated(state)); | 105 EXPECT_CALL(*mock_delegate_, SetStateDeprecated(state)); |
| 94 bridged_notifier_.SetStateDeprecated(state); | 106 bridged_notifier_.SetStateDeprecated(state); |
| 95 } | 107 } |
| 96 | 108 |
| 97 TEST_F(BridgedSyncNotifierTest, UpdateCredentials) { | 109 TEST_F(BridgedSyncNotifierTest, UpdateCredentials) { |
| 98 std::string email = "email"; | 110 std::string email = "email"; |
| 99 std::string token = "token"; | 111 std::string token = "token"; |
| 100 EXPECT_CALL(*mock_delegate_, UpdateCredentials(email, token)); | 112 EXPECT_CALL(*mock_delegate_, UpdateCredentials(email, token)); |
| 101 bridged_notifier_.UpdateCredentials(email, token); | 113 bridged_notifier_.UpdateCredentials(email, token); |
| 102 } | 114 } |
| 103 | 115 |
| 104 TEST_F(BridgedSyncNotifierTest, SendNotification) { | 116 TEST_F(BridgedSyncNotifierTest, SendNotification) { |
| 105 syncer::ModelTypeSet changed_types(syncer::SESSIONS, syncer::EXTENSIONS); | 117 syncer::ModelTypeSet changed_types(syncer::SESSIONS, syncer::EXTENSIONS); |
| 106 EXPECT_CALL(*mock_delegate_, SendNotification(HasModelTypes(changed_types))); | 118 EXPECT_CALL(*mock_delegate_, SendNotification(HasModelTypes(changed_types))); |
| 107 bridged_notifier_.SendNotification(changed_types); | 119 bridged_notifier_.SendNotification(changed_types); |
| 108 } | 120 } |
| 109 | 121 |
| 110 } // namespace | 122 } // namespace |
| 111 } // namespace browser_sync | 123 } // namespace browser_sync |
| OLD | NEW |