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#ifndef CHROME_BROWSER_CHROMEOS_POLICY_DEVICE_POLICY_CROS_BROWSER_TEST_H_
6#define CHROME_BROWSER_CHROMEOS_POLICY_DEVICE_POLICY_CROS_BROWSER_TEST_H_
7
8#include "base/basictypes.h"
9#include "base/compiler_specific.h"
10#include "chrome/browser/chromeos/policy/device_policy_builder.h"
11#include "chrome/test/base/in_process_browser_test.h"
12#include "chromeos/dbus/dbus_thread_manager.h"
13
14namespace chromeos {
15class FakeSessionManagerClient;
16}
17
18namespace policy {
19
20class DevicePolicyCrosTestHelper {
21 public:
22  DevicePolicyCrosTestHelper();
23  ~DevicePolicyCrosTestHelper();
24
25  // Marks the device as enterprise-owned. Must be called to make device
26  // policies apply Chrome-wide. If this is not called, device policies will
27  // affect CrosSettings only.
28  void MarkAsEnterpriseOwned();
29
30  // Writes the owner key to disk. To be called before installing a policy.
31  void InstallOwnerKey();
32
33  DevicePolicyBuilder* device_policy() { return &device_policy_; }
34
35 private:
36  void OverridePaths();
37
38  // Carries Chrome OS device policies for tests.
39  DevicePolicyBuilder device_policy_;
40
41  DISALLOW_COPY_AND_ASSIGN(DevicePolicyCrosTestHelper);
42};
43
44// Used to test Device policy changes in Chrome OS.
45class DevicePolicyCrosBrowserTest : public InProcessBrowserTest {
46 protected:
47  DevicePolicyCrosBrowserTest();
48  virtual ~DevicePolicyCrosBrowserTest();
49
50  virtual void SetUpInProcessBrowserTestFixture() OVERRIDE;
51  virtual void TearDownInProcessBrowserTestFixture() OVERRIDE;
52
53  // Marks the device as enterprise-owned. Must be called to make device
54  // policies apply Chrome-wide. If this is not called, device policies will
55  // affect CrosSettings only.
56  void MarkAsEnterpriseOwned();
57
58  // Writes the owner key to disk. To be called before installing a policy.
59  void InstallOwnerKey();
60
61  // Reinstalls |device_policy_| as the policy (to be used when it was
62  // recently changed).
63  void RefreshDevicePolicy();
64
65  chromeos::DBusThreadManagerSetter* dbus_setter() {
66    return dbus_setter_.get();
67  }
68
69  chromeos::FakeSessionManagerClient* session_manager_client() {
70    return fake_session_manager_client_;
71  }
72
73  DevicePolicyBuilder* device_policy() { return test_helper_.device_policy(); }
74
75 private:
76  DevicePolicyCrosTestHelper test_helper_;
77
78  // FakeDBusThreadManager uses FakeSessionManagerClient.
79  scoped_ptr<chromeos::DBusThreadManagerSetter> dbus_setter_;
80  chromeos::FakeSessionManagerClient* fake_session_manager_client_;
81
82  DISALLOW_COPY_AND_ASSIGN(DevicePolicyCrosBrowserTest);
83};
84
85}  // namespace policy
86
87#endif  // CHROME_BROWSER_CHROMEOS_POLICY_DEVICE_POLICY_CROS_BROWSER_TEST_H_
88