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_
10 #include "base/files/scoped_temp_dir.h"
11 #include "base/macros.h"
12 #include "base/memory/scoped_ptr.h"
19 class DictionaryValue
;
24 class LocalPolicyTestServer
;
26 // This class can be used to apply a user policy to the profile in a
28 class UserPolicyTestHelper
{
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
,
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
);
66 #endif // CHROME_BROWSER_CHROMEOS_POLICY_USER_POLICY_TEST_HELPER_H_