summaryrefslogtreecommitdiffstats
path: root/chrome/browser/services/gcm/gcm_profile_service_test_helper.h
blob: 66eea37b7307eff62edae941948ded20ab84b9c8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_BROWSER_SERVICES_GCM_GCM_PROFILE_SERVICE_TEST_HELPER_H_
#define CHROME_BROWSER_SERVICES_GCM_GCM_PROFILE_SERVICE_TEST_HELPER_H_

#include <string>
#include "base/macros.h"
#include "base/memory/scoped_ptr.h"
#include "chrome/browser/services/gcm/gcm_client_factory.h"
#include "chrome/browser/services/gcm/gcm_client_mock.h"
#include "components/signin/core/browser/signin_manager.h"

class KeyedService;
class Profile;
namespace base {
class RunLoop;
}
namespace content {
class BrowserContext;
}

namespace gcm {

// Helper class for asynchronous waiting.
class Waiter {
 public:
  Waiter();
  ~Waiter();

  // Waits until the asynchrnous operation finishes.
  void WaitUntilCompleted();

  // Signals that the asynchronous operation finishes.
  void SignalCompleted();

  // Runs until UI loop becomes idle.
  void PumpUILoop();

  // Runs until IO loop becomes idle.
  void PumpIOLoop();

 private:
  void PumpIOLoopCompleted();
  void OnIOLoopPump();
  void OnIOLoopPumpCompleted();

  scoped_ptr<base::RunLoop> run_loop_;

  DISALLOW_COPY_AND_ASSIGN(Waiter);
};

#if defined(OS_CHROMEOS)
class FakeSigninManager : public SigninManagerBase {
#else
class FakeSigninManager : public SigninManager {
#endif
 public:
  static KeyedService* Build(content::BrowserContext* context);

  explicit FakeSigninManager(Profile* profile);
  virtual ~FakeSigninManager();

  void SignIn(const std::string& username);
#if defined(OS_CHROMEOS)
  void SignOut();
#else
  virtual void SignOut() OVERRIDE;
#endif

 private:
  Profile* profile_;

  DISALLOW_COPY_AND_ASSIGN(FakeSigninManager);
};

class FakeGCMClientFactory : public GCMClientFactory {
 public:
  explicit FakeGCMClientFactory(
      GCMClientMock::LoadingDelay gcm_client_loading_delay);
  virtual ~FakeGCMClientFactory();

  virtual scoped_ptr<GCMClient> BuildInstance() OVERRIDE;

 private:
  GCMClientMock::LoadingDelay gcm_client_loading_delay_;

  DISALLOW_COPY_AND_ASSIGN(FakeGCMClientFactory);
};

}  // namespace gcm

#endif  // CHROME_BROWSER_SERVICES_GCM_GCM_PROFILE_SERVICE_TEST_HELPER_H_