1 // Copyright 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 #ifndef CHROME_BROWSER_INVALIDATION_FAKE_INVALIDATION_SERVICE_H_ 6 #define CHROME_BROWSER_INVALIDATION_FAKE_INVALIDATION_SERVICE_H_ 7 8 #include <list> 9 #include <utility> 10 11 #include "base/basictypes.h" 12 #include "base/callback_forward.h" 13 #include "chrome/browser/signin/fake_profile_oauth2_token_service.h" 14 #include "components/invalidation/invalidation_service.h" 15 #include "components/invalidation/invalidator_registrar.h" 16 #include "google_apis/gaia/fake_identity_provider.h" 17 #include "sync/notifier/mock_ack_handler.h" 18 19 namespace syncer { 20 class Invalidation; 21 } 22 23 namespace invalidation { 24 25 class InvalidationLogger; 26 27 // An InvalidationService that emits invalidations only when 28 // its EmitInvalidationForTest method is called. 29 class FakeInvalidationService : public InvalidationService { 30 public: 31 FakeInvalidationService(); 32 virtual ~FakeInvalidationService(); 33 34 virtual void RegisterInvalidationHandler( 35 syncer::InvalidationHandler* handler) OVERRIDE; 36 virtual void UpdateRegisteredInvalidationIds( 37 syncer::InvalidationHandler* handler, 38 const syncer::ObjectIdSet& ids) OVERRIDE; 39 virtual void UnregisterInvalidationHandler( 40 syncer::InvalidationHandler* handler) OVERRIDE; 41 42 virtual syncer::InvalidatorState GetInvalidatorState() const OVERRIDE; 43 virtual std::string GetInvalidatorClientId() const OVERRIDE; 44 virtual InvalidationLogger* GetInvalidationLogger() OVERRIDE; 45 virtual void RequestDetailedStatus( 46 base::Callback<void(const base::DictionaryValue&)> caller) const OVERRIDE; 47 virtual IdentityProvider* GetIdentityProvider() OVERRIDE; 48 49 void SetInvalidatorState(syncer::InvalidatorState state); 50 invalidator_registrar()51 const syncer::InvalidatorRegistrar& invalidator_registrar() const { 52 return invalidator_registrar_; 53 } 54 55 void EmitInvalidationForTest(const syncer::Invalidation& invalidation); 56 57 // Emitted invalidations will be hooked up to this AckHandler. Clients can 58 // query it to assert the invalidaitons are being acked properly. 59 syncer::MockAckHandler* GetMockAckHandler(); 60 61 private: 62 std::string client_id_; 63 syncer::InvalidatorRegistrar invalidator_registrar_; 64 syncer::MockAckHandler mock_ack_handler_; 65 FakeProfileOAuth2TokenService token_service_; 66 FakeIdentityProvider identity_provider_; 67 68 DISALLOW_COPY_AND_ASSIGN(FakeInvalidationService); 69 }; 70 71 } // namespace invalidation 72 73 #endif // CHROME_BROWSER_INVALIDATION_FAKE_INVALIDATION_SERVICE_H_ 74