OLD | NEW |
(Empty) | |
| 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. |
| 4 |
| 5 #ifndef CHROME_BROWSER_CHROMEOS_POLICY_USER_POLICY_TEST_HELPER_H_ |
| 6 #define CHROME_BROWSER_CHROMEOS_POLICY_USER_POLICY_TEST_HELPER_H_ |
| 7 |
| 8 #include <string> |
| 9 |
| 10 #include "base/files/scoped_temp_dir.h" |
| 11 #include "base/macros.h" |
| 12 #include "base/memory/scoped_ptr.h" |
| 13 |
| 14 class Profile; |
| 15 |
| 16 namespace base { |
| 17 class CommandLine; |
| 18 class FilePath; |
| 19 class DictionaryValue; |
| 20 } |
| 21 |
| 22 namespace policy { |
| 23 |
| 24 class LocalPolicyTestServer; |
| 25 |
| 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(); |
| 32 |
| 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); |
| 36 |
| 37 // Must be used during BrowserTestBase::SetUpCommandLine to direct Chrome to |
| 38 // the policy test server. |
| 39 void UpdateCommandLine(base::CommandLine* command_line) const; |
| 40 |
| 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); |
| 45 |
| 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); |
| 51 |
| 52 private: |
| 53 void WritePolicyFile(const base::DictionaryValue& mandatory, |
| 54 const base::DictionaryValue& recommended); |
| 55 base::FilePath PolicyFilePath() const; |
| 56 |
| 57 const std::string account_id_; |
| 58 base::ScopedTempDir temp_dir_; |
| 59 scoped_ptr<LocalPolicyTestServer> test_server_; |
| 60 |
| 61 DISALLOW_COPY_AND_ASSIGN(UserPolicyTestHelper); |
| 62 }; |
| 63 |
| 64 } // namespace policy |
| 65 |
| 66 #endif // CHROME_BROWSER_CHROMEOS_POLICY_USER_POLICY_TEST_HELPER_H_ |
OLD | NEW |