device_settings_test_helper.h revision 5821806d5e7f356e8fa4b058a389a808ea183019
1// Copyright (c) 2012 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_CHROMEOS_SETTINGS_DEVICE_SETTINGS_TEST_HELPER_H_
6#define CHROME_BROWSER_CHROMEOS_SETTINGS_DEVICE_SETTINGS_TEST_HELPER_H_
7
8#include <string>
9#include <vector>
10
11#include "base/basictypes.h"
12#include "base/compiler_specific.h"
13#include "chromeos/dbus/session_manager_client.h"
14
15namespace chromeos {
16
17// A helper class for tests mocking out session_manager's device settings
18// interface. The pattern is to initialize DeviceSettingsService with the helper
19// for the SessionManagerClient pointer. The helper records calls made by
20// DeviceSettingsService. The test can then verify state, after which it should
21// call one of the Flush() variants that will resume processing.
22class DeviceSettingsTestHelper : public SessionManagerClient {
23 public:
24  // Wraps a device settings service instance for testing.
25  DeviceSettingsTestHelper();
26  virtual ~DeviceSettingsTestHelper();
27
28  // Flushes operations on the current message loop and the blocking pool.
29  void FlushLoops();
30
31  // Runs all pending store callbacks.
32  void FlushStore();
33
34  // Runs all pending retrieve callbacks.
35  void FlushRetrieve();
36
37  // Flushes all pending operations.
38  void Flush();
39
40  bool store_result() {
41    return store_result_;
42  }
43  void set_store_result(bool store_result) {
44    store_result_ = store_result;
45  }
46
47  const std::string& policy_blob() {
48    return policy_blob_;
49  }
50  void set_policy_blob(const std::string& policy_blob) {
51    policy_blob_ = policy_blob;
52  }
53
54  // SessionManagerClient:
55  virtual void AddObserver(Observer* observer) OVERRIDE;
56  virtual void RemoveObserver(Observer* observer) OVERRIDE;
57  virtual bool HasObserver(Observer* observer) OVERRIDE;
58  virtual void EmitLoginPromptReady() OVERRIDE;
59  virtual void EmitLoginPromptVisible() OVERRIDE;
60  virtual void RestartJob(int pid, const std::string& command_line) OVERRIDE;
61  virtual void RestartEntd() OVERRIDE;
62  virtual void StartSession(const std::string& user_email) OVERRIDE;
63  virtual void StopSession() OVERRIDE;
64  virtual void StartDeviceWipe() OVERRIDE;
65  virtual void RequestLockScreen() OVERRIDE;
66  virtual void NotifyLockScreenShown() OVERRIDE;
67  virtual void RequestUnlockScreen() OVERRIDE;
68  virtual void NotifyLockScreenDismissed() OVERRIDE;
69  virtual bool GetIsScreenLocked() OVERRIDE;
70  virtual void RetrieveDevicePolicy(
71      const RetrievePolicyCallback& callback) OVERRIDE;
72  virtual void RetrieveUserPolicy(
73      const RetrievePolicyCallback& callback) OVERRIDE;
74  virtual void StoreDevicePolicy(const std::string& policy_blob,
75                                 const StorePolicyCallback& callback) OVERRIDE;
76  virtual void StoreUserPolicy(const std::string& policy_blob,
77                               const StorePolicyCallback& callback) OVERRIDE;
78
79 private:
80  bool store_result_;
81  std::string policy_blob_;
82
83  std::vector<StorePolicyCallback> store_callbacks_;
84  std::vector<RetrievePolicyCallback> retrieve_callbacks_;
85
86  DISALLOW_COPY_AND_ASSIGN(DeviceSettingsTestHelper);
87};
88
89// Wraps the singleton device settings and initializes it to the point where it
90// reports OWNERSHIP_NONE for the ownership status.
91class ScopedDeviceSettingsTestHelper : public DeviceSettingsTestHelper {
92 public:
93  ScopedDeviceSettingsTestHelper();
94  virtual ~ScopedDeviceSettingsTestHelper();
95
96 private:
97  DISALLOW_COPY_AND_ASSIGN(ScopedDeviceSettingsTestHelper);
98};
99
100}  // namespace chromeos
101
102#endif  // CHROME_BROWSER_CHROMEOS_SETTINGS_DEVICE_SETTINGS_TEST_HELPER_H_
103