Elim cr-checkbox
[chromium-blink-merge.git] / chrome / browser / chromeos / policy / user_policy_test_helper.h
blob941a0674c3cdd5c715bbcc36d1229789a3ada223
1 // Copyright 2015 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.
5 #ifndef CHROME_BROWSER_CHROMEOS_POLICY_USER_POLICY_TEST_HELPER_H_
6 #define CHROME_BROWSER_CHROMEOS_POLICY_USER_POLICY_TEST_HELPER_H_
8 #include <string>
10 #include "base/files/scoped_temp_dir.h"
11 #include "base/macros.h"
12 #include "base/memory/scoped_ptr.h"
14 class Profile;
16 namespace base {
17 class CommandLine;
18 class FilePath;
19 class DictionaryValue;
22 namespace policy {
24 class LocalPolicyTestServer;
26 // This class can be used to apply a user policy to the profile in a
27 // BrowserTest.
28 class UserPolicyTestHelper {
29 public:
30 explicit UserPolicyTestHelper(const std::string& account_id);
31 virtual ~UserPolicyTestHelper();
33 // Must be called after construction to start the policy test server.
34 void Init(const base::DictionaryValue& mandatory_policy,
35 const base::DictionaryValue& recommended_policy);
37 // Must be used during BrowserTestBase::SetUpCommandLine to direct Chrome to
38 // the policy test server.
39 void UpdateCommandLine(base::CommandLine* command_line) const;
41 // Can be optionally used to wait for the initial policy to be applied to the
42 // profile. Alternatively, a login can be simulated, which makes it
43 // unnecessary to call this function.
44 void WaitForInitialPolicy(Profile* profile);
46 // Update the policy test server with the given policy. Then refresh and wait
47 // for the new policy being applied to |profile|.
48 void UpdatePolicy(const base::DictionaryValue& mandatory_policy,
49 const base::DictionaryValue& recommended_policy,
50 Profile* profile);
52 private:
53 void WritePolicyFile(const base::DictionaryValue& mandatory,
54 const base::DictionaryValue& recommended);
55 base::FilePath PolicyFilePath() const;
57 const std::string account_id_;
58 base::ScopedTempDir temp_dir_;
59 scoped_ptr<LocalPolicyTestServer> test_server_;
61 DISALLOW_COPY_AND_ASSIGN(UserPolicyTestHelper);
64 } // namespace policy
66 #endif // CHROME_BROWSER_CHROMEOS_POLICY_USER_POLICY_TEST_HELPER_H_