OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <string> | 5 #include <string> |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
(...skipping 16 matching lines...) Expand all Loading... |
27 #include "components/policy/core/common/policy_switches.h" | 27 #include "components/policy/core/common/policy_switches.h" |
28 #include "extensions/common/extension.h" | 28 #include "extensions/common/extension.h" |
29 #include "net/url_request/url_request_context_getter.h" | 29 #include "net/url_request/url_request_context_getter.h" |
30 #include "policy/proto/cloud_policy.pb.h" | 30 #include "policy/proto/cloud_policy.pb.h" |
31 #include "testing/gmock/include/gmock/gmock.h" | 31 #include "testing/gmock/include/gmock/gmock.h" |
32 #include "testing/gtest/include/gtest/gtest.h" | 32 #include "testing/gtest/include/gtest/gtest.h" |
33 | 33 |
34 #if defined(OS_CHROMEOS) | 34 #if defined(OS_CHROMEOS) |
35 #include "chrome/browser/chromeos/policy/user_cloud_policy_manager_chromeos.h" | 35 #include "chrome/browser/chromeos/policy/user_cloud_policy_manager_chromeos.h" |
36 #include "chrome/browser/chromeos/policy/user_cloud_policy_manager_factory_chrom
eos.h" | 36 #include "chrome/browser/chromeos/policy/user_cloud_policy_manager_factory_chrom
eos.h" |
37 #include "chrome/common/chrome_paths.h" | |
38 #include "chromeos/chromeos_switches.h" | 37 #include "chromeos/chromeos_switches.h" |
39 #else | 38 #else |
40 #include "chrome/browser/policy/cloud/user_cloud_policy_manager.h" | 39 #include "chrome/browser/policy/cloud/user_cloud_policy_manager.h" |
41 #include "chrome/browser/policy/cloud/user_cloud_policy_manager_factory.h" | 40 #include "chrome/browser/policy/cloud/user_cloud_policy_manager_factory.h" |
42 #include "chrome/browser/signin/signin_manager.h" | 41 #include "chrome/browser/signin/signin_manager.h" |
43 #include "chrome/browser/signin/signin_manager_factory.h" | 42 #include "chrome/browser/signin/signin_manager_factory.h" |
44 #endif | 43 #endif |
45 | 44 |
46 using testing::InvokeWithoutArgs; | 45 using testing::InvokeWithoutArgs; |
47 using testing::Mock; | 46 using testing::Mock; |
(...skipping 12 matching lines...) Expand all Loading... |
60 const base::FilePath::CharType kTestExtensionPath[] = | 59 const base::FilePath::CharType kTestExtensionPath[] = |
61 FILE_PATH_LITERAL("extensions/managed_extension"); | 60 FILE_PATH_LITERAL("extensions/managed_extension"); |
62 | 61 |
63 const char kTestPolicy[] = | 62 const char kTestPolicy[] = |
64 "{" | 63 "{" |
65 " \"Name\": {" | 64 " \"Name\": {" |
66 " \"Value\": \"disable_all_the_things\"" | 65 " \"Value\": \"disable_all_the_things\"" |
67 " }" | 66 " }" |
68 "}"; | 67 "}"; |
69 | 68 |
70 #if defined(OS_CHROMEOS) | |
71 const char kTestExtension2[] = "behllobkkfkfnphdnhnkndlbkcpglgmj"; | 69 const char kTestExtension2[] = "behllobkkfkfnphdnhnkndlbkcpglgmj"; |
72 const base::FilePath::CharType kTestExtension2Path[] = | 70 const base::FilePath::CharType kTestExtension2Path[] = |
73 FILE_PATH_LITERAL("extensions/managed_extension2"); | 71 FILE_PATH_LITERAL("extensions/managed_extension2"); |
74 | 72 |
75 const char kTestPolicyJSON[] = "{\"Name\":\"disable_all_the_things\"}"; | 73 const char kTestPolicyJSON[] = "{\"Name\":\"disable_all_the_things\"}"; |
76 | 74 |
77 const char kTestPolicy2[] = | 75 const char kTestPolicy2[] = |
78 "{" | 76 "{" |
79 " \"Another\": {" | 77 " \"Another\": {" |
80 " \"Value\": \"turn_it_off\"" | 78 " \"Value\": \"turn_it_off\"" |
81 " }" | 79 " }" |
82 "}"; | 80 "}"; |
83 | 81 |
84 const char kTestPolicy2JSON[] = "{\"Another\":\"turn_it_off\"}"; | 82 const char kTestPolicy2JSON[] = "{\"Another\":\"turn_it_off\"}"; |
85 #endif // defined(OS_CHROMEOS) | |
86 | 83 |
87 class ComponentCloudPolicyTest : public ExtensionBrowserTest { | 84 class ComponentCloudPolicyTest : public ExtensionBrowserTest { |
88 protected: | 85 protected: |
89 ComponentCloudPolicyTest() {} | 86 ComponentCloudPolicyTest() {} |
90 virtual ~ComponentCloudPolicyTest() {} | 87 virtual ~ComponentCloudPolicyTest() {} |
91 | 88 |
92 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { | 89 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { |
93 ExtensionBrowserTest::SetUpCommandLine(command_line); | 90 ExtensionBrowserTest::SetUpCommandLine(command_line); |
94 #if defined(OS_CHROMEOS) | 91 #if defined(OS_CHROMEOS) |
95 // ExtensionBrowserTest sets the login users to a non-managed value; | 92 // ExtensionBrowserTest sets the login users to a non-managed value; |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
194 base::RunLoop run_loop; | 191 base::RunLoop run_loop; |
195 policy_service->RefreshPolicies(run_loop.QuitClosure()); | 192 policy_service->RefreshPolicies(run_loop.QuitClosure()); |
196 run_loop.Run(); | 193 run_loop.Run(); |
197 } | 194 } |
198 | 195 |
199 LocalPolicyTestServer test_server_; | 196 LocalPolicyTestServer test_server_; |
200 scoped_refptr<const extensions::Extension> extension_; | 197 scoped_refptr<const extensions::Extension> extension_; |
201 scoped_ptr<ExtensionTestMessageListener> event_listener_; | 198 scoped_ptr<ExtensionTestMessageListener> event_listener_; |
202 }; | 199 }; |
203 | 200 |
204 // TODO(joaodasilva): enable these for other platforms once ready. | |
205 #if defined(OS_CHROMEOS) | |
206 | |
207 IN_PROC_BROWSER_TEST_F(ComponentCloudPolicyTest, FetchExtensionPolicy) { | 201 IN_PROC_BROWSER_TEST_F(ComponentCloudPolicyTest, FetchExtensionPolicy) { |
208 // Read the initial policy. | 202 // Read the initial policy. |
209 ExtensionTestMessageListener policy_listener(kTestPolicyJSON, true); | 203 ExtensionTestMessageListener policy_listener(kTestPolicyJSON, true); |
210 event_listener_->Reply("get-policy-Name"); | 204 event_listener_->Reply("get-policy-Name"); |
211 EXPECT_TRUE(policy_listener.WaitUntilSatisfied()); | 205 EXPECT_TRUE(policy_listener.WaitUntilSatisfied()); |
212 } | 206 } |
213 | 207 |
214 IN_PROC_BROWSER_TEST_F(ComponentCloudPolicyTest, UpdateExtensionPolicy) { | 208 IN_PROC_BROWSER_TEST_F(ComponentCloudPolicyTest, UpdateExtensionPolicy) { |
215 // Read the initial policy. | 209 // Read the initial policy. |
216 ExtensionTestMessageListener policy_listener(kTestPolicyJSON, true); | 210 ExtensionTestMessageListener policy_listener(kTestPolicyJSON, true); |
(...skipping 30 matching lines...) Expand all Loading... |
247 scoped_refptr<const extensions::Extension> extension2 = | 241 scoped_refptr<const extensions::Extension> extension2 = |
248 LoadExtension(kTestExtension2Path); | 242 LoadExtension(kTestExtension2Path); |
249 ASSERT_TRUE(extension2.get()); | 243 ASSERT_TRUE(extension2.get()); |
250 ASSERT_EQ(kTestExtension2, extension2->id()); | 244 ASSERT_EQ(kTestExtension2, extension2->id()); |
251 | 245 |
252 // This extension only sends the 'policy' signal once it receives the policy, | 246 // This extension only sends the 'policy' signal once it receives the policy, |
253 // and after verifying it has the expected value. Otherwise it sends 'fail'. | 247 // and after verifying it has the expected value. Otherwise it sends 'fail'. |
254 EXPECT_TRUE(result_listener.WaitUntilSatisfied()); | 248 EXPECT_TRUE(result_listener.WaitUntilSatisfied()); |
255 } | 249 } |
256 | 250 |
257 #endif // OS_CHROMEOS | |
258 | |
259 } // namespace policy | 251 } // namespace policy |
OLD | NEW |