| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/sync/glue/bridged_sync_notifier.h" | |
| 6 | |
| 7 #include <string> | |
| 8 | |
| 9 #include "base/compiler_specific.h" | |
| 10 #include "base/message_loop.h" | |
| 11 #include "base/threading/thread.h" | |
| 12 #include "chrome/browser/sync/glue/chrome_sync_notification_bridge.h" | |
| 13 #include "chrome/test/base/profile_mock.h" | |
| 14 #include "content/public/test/test_browser_thread.h" | |
| 15 #include "sync/internal_api/public/base/model_type.h" | |
| 16 #include "sync/internal_api/public/base/model_type_test_util.h" | |
| 17 #include "sync/notifier/fake_sync_notifier.h" | |
| 18 #include "sync/notifier/fake_sync_notifier_observer.h" | |
| 19 #include "sync/notifier/sync_notifier.h" | |
| 20 #include "testing/gmock/include/gmock/gmock.h" | |
| 21 #include "testing/gtest/include/gtest/gtest.h" | |
| 22 | |
| 23 namespace browser_sync { | |
| 24 namespace { | |
| 25 | |
| 26 using ::testing::NiceMock; | |
| 27 using ::testing::StrictMock; | |
| 28 using content::BrowserThread; | |
| 29 using syncer::HasModelTypes; | |
| 30 | |
| 31 class MockChromeSyncNotificationBridge : public ChromeSyncNotificationBridge { | |
| 32 public: | |
| 33 MockChromeSyncNotificationBridge( | |
| 34 const Profile* profile, | |
| 35 const scoped_refptr<base::SequencedTaskRunner>& sync_task_runner) | |
| 36 : ChromeSyncNotificationBridge(profile, sync_task_runner) {} | |
| 37 virtual ~MockChromeSyncNotificationBridge() {} | |
| 38 | |
| 39 MOCK_METHOD1(RegisterHandler, void(syncer::SyncNotifierObserver*)); | |
| 40 MOCK_METHOD2(UpdateRegisteredIds, | |
| 41 void(syncer::SyncNotifierObserver*, | |
| 42 const syncer::ObjectIdSet&)); | |
| 43 MOCK_METHOD1(UnregisterHandler, void(syncer::SyncNotifierObserver*)); | |
| 44 }; | |
| 45 | |
| 46 // All tests just verify that each call is passed through to the delegate, with | |
| 47 // the exception of RegisterHandler, UnregisterHandler, and | |
| 48 // UpdateRegisteredIds, which also verifies the call is forwarded to the | |
| 49 // bridge. | |
| 50 class BridgedSyncNotifierTest : public testing::Test { | |
| 51 public: | |
| 52 BridgedSyncNotifierTest() | |
| 53 : ui_thread_(BrowserThread::UI, &ui_loop_), | |
| 54 mock_bridge_(&mock_profile_, ui_loop_.message_loop_proxy()), | |
| 55 // Owned by bridged_notifier_. | |
| 56 fake_delegate_(new syncer::FakeSyncNotifier()), | |
| 57 bridged_notifier_(&mock_bridge_, fake_delegate_) {} | |
| 58 virtual ~BridgedSyncNotifierTest() {} | |
| 59 | |
| 60 protected: | |
| 61 MessageLoop ui_loop_; | |
| 62 content::TestBrowserThread ui_thread_; | |
| 63 NiceMock<ProfileMock> mock_profile_; | |
| 64 StrictMock<MockChromeSyncNotificationBridge> mock_bridge_; | |
| 65 syncer::FakeSyncNotifier* fake_delegate_; | |
| 66 BridgedSyncNotifier bridged_notifier_; | |
| 67 }; | |
| 68 | |
| 69 TEST_F(BridgedSyncNotifierTest, RegisterHandler) { | |
| 70 const syncer::ObjectIdSet& ids = | |
| 71 syncer::ModelTypeSetToObjectIdSet( | |
| 72 syncer::ModelTypeSet(syncer::APPS, syncer::PREFERENCES)); | |
| 73 | |
| 74 syncer::FakeSyncNotifierObserver observer; | |
| 75 EXPECT_CALL(mock_bridge_, RegisterHandler(&observer)); | |
| 76 EXPECT_CALL(mock_bridge_, UpdateRegisteredIds(&observer, ids)); | |
| 77 EXPECT_CALL(mock_bridge_, UnregisterHandler(&observer)); | |
| 78 | |
| 79 bridged_notifier_.RegisterHandler(&observer); | |
| 80 EXPECT_TRUE(fake_delegate_->IsHandlerRegistered(&observer)); | |
| 81 | |
| 82 bridged_notifier_.UpdateRegisteredIds(&observer, ids); | |
| 83 EXPECT_EQ(ids, fake_delegate_->GetRegisteredIds(&observer)); | |
| 84 | |
| 85 bridged_notifier_.UnregisterHandler(&observer); | |
| 86 EXPECT_FALSE(fake_delegate_->IsHandlerRegistered(&observer)); | |
| 87 } | |
| 88 | |
| 89 TEST_F(BridgedSyncNotifierTest, SetUniqueId) { | |
| 90 const std::string& unique_id = "unique id"; | |
| 91 bridged_notifier_.SetUniqueId(unique_id); | |
| 92 EXPECT_EQ(unique_id, fake_delegate_->GetUniqueId()); | |
| 93 } | |
| 94 | |
| 95 TEST_F(BridgedSyncNotifierTest, SetStateDeprecated) { | |
| 96 const std::string& state = "state"; | |
| 97 bridged_notifier_.SetStateDeprecated(state); | |
| 98 EXPECT_EQ(state, fake_delegate_->GetStateDeprecated()); | |
| 99 } | |
| 100 | |
| 101 TEST_F(BridgedSyncNotifierTest, UpdateCredentials) { | |
| 102 const std::string& email = "email"; | |
| 103 const std::string& token = "token"; | |
| 104 bridged_notifier_.UpdateCredentials(email, token); | |
| 105 EXPECT_EQ(email, fake_delegate_->GetCredentialsEmail()); | |
| 106 EXPECT_EQ(token, fake_delegate_->GetCredentialsToken()); | |
| 107 } | |
| 108 | |
| 109 TEST_F(BridgedSyncNotifierTest, SendNotification) { | |
| 110 const syncer::ModelTypeSet changed_types( | |
| 111 syncer::SESSIONS, syncer::EXTENSIONS); | |
| 112 bridged_notifier_.SendNotification(changed_types); | |
| 113 EXPECT_TRUE(fake_delegate_->GetLastChangedTypes().Equals(changed_types)); | |
| 114 } | |
| 115 | |
| 116 } // namespace | |
| 117 } // namespace browser_sync | |
| OLD | NEW |