| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/invalidation/ticl_invalidation_service.h" | 5 #include "chrome/browser/invalidation/ticl_invalidation_service.h" |
| 6 | 6 |
| 7 #include "base/prefs/pref_service.h" | 7 #include "base/prefs/pref_service.h" |
| 8 #include "chrome/browser/invalidation/invalidation_service_factory.h" | 8 #include "chrome/browser/invalidation/invalidation_service_factory.h" |
| 9 #include "chrome/browser/invalidation/invalidation_service_test_template.h" | 9 #include "chrome/browser/invalidation/invalidation_service_test_template.h" |
| 10 #include "chrome/browser/invalidation/invalidator_storage.h" |
| 10 #include "chrome/browser/invalidation/profile_invalidation_auth_provider.h" | 11 #include "chrome/browser/invalidation/profile_invalidation_auth_provider.h" |
| 11 #include "chrome/browser/signin/fake_profile_oauth2_token_service.h" | 12 #include "chrome/browser/signin/fake_profile_oauth2_token_service.h" |
| 12 #include "chrome/browser/signin/fake_signin_manager.h" | 13 #include "chrome/browser/signin/fake_signin_manager.h" |
| 13 #include "chrome/browser/signin/signin_manager_factory.h" | 14 #include "chrome/browser/signin/signin_manager_factory.h" |
| 14 #include "chrome/common/pref_names.h" | 15 #include "chrome/common/pref_names.h" |
| 15 #include "chrome/test/base/testing_profile.h" | 16 #include "chrome/test/base/testing_profile.h" |
| 16 #include "components/signin/core/browser/signin_manager.h" | 17 #include "components/signin/core/browser/signin_manager.h" |
| 18 #include "content/public/test/test_browser_thread_bundle.h" |
| 19 #include "net/url_request/url_request_context_getter.h" |
| 17 #include "sync/notifier/fake_invalidation_handler.h" | 20 #include "sync/notifier/fake_invalidation_handler.h" |
| 18 #include "sync/notifier/fake_invalidator.h" | 21 #include "sync/notifier/fake_invalidator.h" |
| 22 #include "sync/notifier/invalidation_state_tracker.h" |
| 19 #include "sync/notifier/invalidation_util.h" | 23 #include "sync/notifier/invalidation_util.h" |
| 20 #include "testing/gtest/include/gtest/gtest.h" | 24 #include "testing/gtest/include/gtest/gtest.h" |
| 21 | 25 |
| 22 namespace invalidation { | 26 namespace invalidation { |
| 23 | 27 |
| 24 class TiclInvalidationServiceTestDelegate { | 28 class TiclInvalidationServiceTestDelegate { |
| 25 public: | 29 public: |
| 26 TiclInvalidationServiceTestDelegate() { } | 30 TiclInvalidationServiceTestDelegate() { } |
| 27 | 31 |
| 28 ~TiclInvalidationServiceTestDelegate() { | 32 ~TiclInvalidationServiceTestDelegate() { |
| 29 DestroyInvalidationService(); | 33 DestroyInvalidationService(); |
| 30 } | 34 } |
| 31 | 35 |
| 32 void CreateInvalidationService() { | 36 void CreateInvalidationService() { |
| 33 CreateUninitializedInvalidationService(); | 37 CreateUninitializedInvalidationService(); |
| 34 InitializeInvalidationService(); | 38 InitializeInvalidationService(); |
| 35 } | 39 } |
| 36 | 40 |
| 37 void CreateUninitializedInvalidationService() { | 41 void CreateUninitializedInvalidationService() { |
| 38 profile_.reset(new TestingProfile()); | 42 profile_.reset(new TestingProfile()); |
| 39 token_service_.reset(new FakeProfileOAuth2TokenService); | 43 token_service_.reset(new FakeProfileOAuth2TokenService); |
| 40 invalidation_service_.reset(new TiclInvalidationService( | 44 invalidation_service_.reset(new TiclInvalidationService( |
| 41 scoped_ptr<InvalidationAuthProvider>( | 45 scoped_ptr<InvalidationAuthProvider>( |
| 42 new ProfileInvalidationAuthProvider( | 46 new ProfileInvalidationAuthProvider( |
| 43 SigninManagerFactory::GetForProfile(profile_.get()), | 47 SigninManagerFactory::GetForProfile(profile_.get()), |
| 44 token_service_.get(), | 48 token_service_.get(), |
| 45 NULL)), | 49 NULL)), |
| 50 profile_->GetRequestContext(), |
| 51 scoped_ptr<syncer::InvalidationStateTracker>( |
| 52 new InvalidatorStorage(profile_->GetPrefs())), |
| 46 profile_.get())); | 53 profile_.get())); |
| 47 } | 54 } |
| 48 | 55 |
| 49 void InitializeInvalidationService() { | 56 void InitializeInvalidationService() { |
| 50 fake_invalidator_ = new syncer::FakeInvalidator(); | 57 fake_invalidator_ = new syncer::FakeInvalidator(); |
| 51 invalidation_service_->InitForTest(fake_invalidator_); | 58 invalidation_service_->InitForTest(fake_invalidator_); |
| 52 } | 59 } |
| 53 | 60 |
| 54 InvalidationService* GetInvalidationService() { | 61 InvalidationService* GetInvalidationService() { |
| 55 return invalidation_service_.get(); | 62 return invalidation_service_.get(); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 builder.AddTestingFactory(SigninManagerFactory::GetInstance(), | 95 builder.AddTestingFactory(SigninManagerFactory::GetInstance(), |
| 89 FakeSigninManagerBase::Build); | 96 FakeSigninManagerBase::Build); |
| 90 profile_ = builder.Build(); | 97 profile_ = builder.Build(); |
| 91 fake_signin_manager_ = static_cast<SigninManagerBase*>( | 98 fake_signin_manager_ = static_cast<SigninManagerBase*>( |
| 92 SigninManagerFactory::GetForProfile(profile_.get())); | 99 SigninManagerFactory::GetForProfile(profile_.get())); |
| 93 token_service_.reset(new FakeProfileOAuth2TokenService); | 100 token_service_.reset(new FakeProfileOAuth2TokenService); |
| 94 | 101 |
| 95 scoped_ptr<InvalidationAuthProvider> auth_provider( | 102 scoped_ptr<InvalidationAuthProvider> auth_provider( |
| 96 new ProfileInvalidationAuthProvider( | 103 new ProfileInvalidationAuthProvider( |
| 97 fake_signin_manager_, token_service_.get(), NULL)); | 104 fake_signin_manager_, token_service_.get(), NULL)); |
| 98 invalidation_service_.reset( | 105 invalidation_service_.reset(new TiclInvalidationService( |
| 99 new TiclInvalidationService(auth_provider.Pass(), profile_.get())); | 106 auth_provider.Pass(), |
| 107 profile_->GetRequestContext(), |
| 108 scoped_ptr<syncer::InvalidationStateTracker>( |
| 109 new InvalidatorStorage(profile_->GetPrefs())), |
| 110 profile_.get())); |
| 100 invalidation_service_->Init(); | 111 invalidation_service_->Init(); |
| 101 } | 112 } |
| 102 | 113 |
| 103 virtual void TearDown() OVERRIDE { | 114 virtual void TearDown() OVERRIDE { |
| 104 invalidation_service_->Shutdown(); | 115 invalidation_service_->Shutdown(); |
| 105 } | 116 } |
| 106 | 117 |
| 107 TiclInvalidationService::InvalidationNetworkChannel GetNetworkChannel() { | 118 TiclInvalidationService::InvalidationNetworkChannel GetNetworkChannel() { |
| 108 return invalidation_service_->network_channel_type_; | 119 return invalidation_service_->network_channel_type_; |
| 109 } | 120 } |
| 110 | 121 |
| 111 protected: | 122 protected: |
| 123 content::TestBrowserThreadBundle thread_bundle_; |
| 112 scoped_ptr<TestingProfile> profile_; | 124 scoped_ptr<TestingProfile> profile_; |
| 113 SigninManagerBase* fake_signin_manager_; | 125 SigninManagerBase* fake_signin_manager_; |
| 114 scoped_ptr<FakeProfileOAuth2TokenService> token_service_; | 126 scoped_ptr<FakeProfileOAuth2TokenService> token_service_; |
| 115 scoped_ptr<TiclInvalidationService> invalidation_service_; | 127 scoped_ptr<TiclInvalidationService> invalidation_service_; |
| 116 }; | 128 }; |
| 117 | 129 |
| 118 TEST_F(TiclInvalidationServiceChannelTest, ChannelSelectionTest) { | 130 TEST_F(TiclInvalidationServiceChannelTest, ChannelSelectionTest) { |
| 119 EXPECT_EQ(TiclInvalidationService::PUSH_CLIENT_CHANNEL, GetNetworkChannel()); | 131 EXPECT_EQ(TiclInvalidationService::PUSH_CLIENT_CHANNEL, GetNetworkChannel()); |
| 120 | 132 |
| 121 // If stars allign use GCM channel. | 133 // If stars allign use GCM channel. |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 } | 179 } |
| 168 | 180 |
| 169 bool called_; | 181 bool called_; |
| 170 base::WeakPtrFactory<FakeCallbackContainer> weak_ptr_factory_; | 182 base::WeakPtrFactory<FakeCallbackContainer> weak_ptr_factory_; |
| 171 }; | 183 }; |
| 172 } // namespace internal | 184 } // namespace internal |
| 173 | 185 |
| 174 // Test that requesting for detailed status doesn't crash even if the | 186 // Test that requesting for detailed status doesn't crash even if the |
| 175 // underlying invalidator is not initialized. | 187 // underlying invalidator is not initialized. |
| 176 TEST(TiclInvalidationServiceLoggingTest, DetailedStatusCallbacksWork) { | 188 TEST(TiclInvalidationServiceLoggingTest, DetailedStatusCallbacksWork) { |
| 189 content::TestBrowserThreadBundle thread_bundle; |
| 190 |
| 177 scoped_ptr<TiclInvalidationServiceTestDelegate> delegate ( | 191 scoped_ptr<TiclInvalidationServiceTestDelegate> delegate ( |
| 178 new TiclInvalidationServiceTestDelegate()); | 192 new TiclInvalidationServiceTestDelegate()); |
| 179 | 193 |
| 180 delegate->CreateUninitializedInvalidationService(); | 194 delegate->CreateUninitializedInvalidationService(); |
| 181 invalidation::InvalidationService* const invalidator = | 195 invalidation::InvalidationService* const invalidator = |
| 182 delegate->GetInvalidationService(); | 196 delegate->GetInvalidationService(); |
| 183 | 197 |
| 184 internal::FakeCallbackContainer fake_container; | 198 internal::FakeCallbackContainer fake_container; |
| 185 invalidator->RequestDetailedStatus( | 199 invalidator->RequestDetailedStatus( |
| 186 base::Bind(&internal::FakeCallbackContainer::FakeCallback, | 200 base::Bind(&internal::FakeCallbackContainer::FakeCallback, |
| 187 fake_container.weak_ptr_factory_.GetWeakPtr())); | 201 fake_container.weak_ptr_factory_.GetWeakPtr())); |
| 188 EXPECT_FALSE(fake_container.called_); | 202 EXPECT_FALSE(fake_container.called_); |
| 189 | 203 |
| 190 delegate->InitializeInvalidationService(); | 204 delegate->InitializeInvalidationService(); |
| 191 | 205 |
| 192 invalidator->RequestDetailedStatus( | 206 invalidator->RequestDetailedStatus( |
| 193 base::Bind(&internal::FakeCallbackContainer::FakeCallback, | 207 base::Bind(&internal::FakeCallbackContainer::FakeCallback, |
| 194 fake_container.weak_ptr_factory_.GetWeakPtr())); | 208 fake_container.weak_ptr_factory_.GetWeakPtr())); |
| 195 EXPECT_TRUE(fake_container.called_); | 209 EXPECT_TRUE(fake_container.called_); |
| 196 } | 210 } |
| 197 } // namespace invalidation | 211 } // namespace invalidation |
| OLD | NEW |