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