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 3 // found in the LICENSE file. 4 5 #include "chrome/browser/invalidation/ticl_invalidation_service.h" 6 7 #include "chrome/browser/invalidation/invalidation_service_factory.h" 8 #include "chrome/browser/invalidation/invalidation_service_test_template.h" 9 #include "chrome/browser/signin/fake_profile_oauth2_token_service.h" 10 #include "chrome/test/base/testing_profile.h" 11 #include "sync/notifier/fake_invalidation_handler.h" 12 #include "sync/notifier/fake_invalidator.h" 13 #include "sync/notifier/invalidation_util.h" 14 #include "testing/gtest/include/gtest/gtest.h" 15 16 namespace invalidation { 17 18 class TiclInvalidationServiceTestDelegate { 19 public: 20 TiclInvalidationServiceTestDelegate() { } 21 22 ~TiclInvalidationServiceTestDelegate() { 23 DestroyInvalidationService(); 24 } 25 26 void CreateInvalidationService() { 27 fake_invalidator_ = new syncer::FakeInvalidator(); 28 profile_.reset(new TestingProfile()); 29 token_service_.reset(new FakeProfileOAuth2TokenService); 30 invalidation_service_.reset( 31 new TiclInvalidationService(NULL, 32 token_service_.get(), 33 profile_.get())); 34 invalidation_service_->InitForTest(fake_invalidator_); 35 } 36 37 InvalidationService* GetInvalidationService() { 38 return invalidation_service_.get(); 39 } 40 41 void DestroyInvalidationService() { 42 invalidation_service_->Shutdown(); 43 } 44 45 void TriggerOnInvalidatorStateChange(syncer::InvalidatorState state) { 46 fake_invalidator_->EmitOnInvalidatorStateChange(state); 47 } 48 49 void TriggerOnIncomingInvalidation( 50 const syncer::ObjectIdInvalidationMap& invalidation_map) { 51 fake_invalidator_->EmitOnIncomingInvalidation(invalidation_map); 52 } 53 54 syncer::FakeInvalidator* fake_invalidator_; // owned by the service. 55 scoped_ptr<TiclInvalidationService> invalidation_service_; 56 scoped_ptr<TestingProfile> profile_; 57 scoped_ptr<FakeProfileOAuth2TokenService> token_service_; 58 }; 59 60 INSTANTIATE_TYPED_TEST_CASE_P( 61 TiclInvalidationServiceTest, InvalidationServiceTest, 62 TiclInvalidationServiceTestDelegate); 63 64 } // namespace invalidation 65