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