Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(520)

Side by Side Diff: chrome/browser/policy/cloud/component_cloud_policy_browsertest.cc

Issue 79023002: Support cloud policy for extensions on the desktop platforms. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fixed stub, again Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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"
11 #include "base/run_loop.h" 11 #include "base/run_loop.h"
12 #include "chrome/browser/browser_process.h" 12 #include "chrome/browser/browser_process.h"
13 #include "chrome/browser/extensions/extension_browsertest.h" 13 #include "chrome/browser/extensions/extension_browsertest.h"
14 #include "chrome/browser/extensions/extension_test_message_listener.h" 14 #include "chrome/browser/extensions/extension_test_message_listener.h"
15 #include "chrome/browser/policy/browser_policy_connector.h" 15 #include "chrome/browser/policy/browser_policy_connector.h"
16 #include "chrome/browser/policy/cloud/cloud_policy_constants.h" 16 #include "chrome/browser/policy/cloud/cloud_policy_constants.h"
17 #include "chrome/browser/policy/cloud/mock_cloud_policy_client.h" 17 #include "chrome/browser/policy/cloud/mock_cloud_policy_client.h"
18 #include "chrome/browser/policy/policy_service.h" 18 #include "chrome/browser/policy/policy_service.h"
19 #include "chrome/browser/policy/profile_policy_connector.h" 19 #include "chrome/browser/policy/profile_policy_connector.h"
20 #include "chrome/browser/policy/profile_policy_connector_factory.h" 20 #include "chrome/browser/policy/profile_policy_connector_factory.h"
21 #include "chrome/browser/policy/proto/cloud/chrome_extension_policy.pb.h" 21 #include "chrome/browser/policy/proto/cloud/chrome_extension_policy.pb.h"
22 #include "chrome/browser/policy/test/local_policy_test_server.h" 22 #include "chrome/browser/policy/test/local_policy_test_server.h"
23 #include "chrome/browser/policy/test/policy_test_utils.h" 23 #include "chrome/browser/policy/test/policy_test_utils.h"
24 #include "chrome/browser/profiles/profile.h" 24 #include "chrome/browser/profiles/profile.h"
25 #include "chrome/common/chrome_paths.h" 25 #include "chrome/common/chrome_paths.h"
26 #include "chrome/common/chrome_switches.h" 26 #include "chrome/common/chrome_switches.h"
27 #include "components/policy/core/common/policy_switches.h"
28 #include "extensions/common/extension.h" 27 #include "extensions/common/extension.h"
29 #include "net/url_request/url_request_context_getter.h" 28 #include "net/url_request/url_request_context_getter.h"
30 #include "policy/proto/cloud_policy.pb.h" 29 #include "policy/proto/cloud_policy.pb.h"
31 #include "testing/gmock/include/gmock/gmock.h" 30 #include "testing/gmock/include/gmock/gmock.h"
32 #include "testing/gtest/include/gtest/gtest.h" 31 #include "testing/gtest/include/gtest/gtest.h"
33 32
34 #if defined(OS_CHROMEOS) 33 #if defined(OS_CHROMEOS)
35 #include "chrome/browser/chromeos/policy/user_cloud_policy_manager_chromeos.h" 34 #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" 35 #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" 36 #include "chromeos/chromeos_switches.h"
39 #else 37 #else
40 #include "chrome/browser/policy/cloud/user_cloud_policy_manager.h" 38 #include "chrome/browser/policy/cloud/user_cloud_policy_manager.h"
41 #include "chrome/browser/policy/cloud/user_cloud_policy_manager_factory.h" 39 #include "chrome/browser/policy/cloud/user_cloud_policy_manager_factory.h"
42 #include "chrome/browser/signin/signin_manager.h" 40 #include "chrome/browser/signin/signin_manager.h"
43 #include "chrome/browser/signin/signin_manager_factory.h" 41 #include "chrome/browser/signin/signin_manager_factory.h"
44 #endif 42 #endif
45 43
46 using testing::InvokeWithoutArgs; 44 using testing::InvokeWithoutArgs;
47 using testing::Mock; 45 using testing::Mock;
(...skipping 12 matching lines...) Expand all
60 const base::FilePath::CharType kTestExtensionPath[] = 58 const base::FilePath::CharType kTestExtensionPath[] =
61 FILE_PATH_LITERAL("extensions/managed_extension"); 59 FILE_PATH_LITERAL("extensions/managed_extension");
62 60
63 const char kTestPolicy[] = 61 const char kTestPolicy[] =
64 "{" 62 "{"
65 " \"Name\": {" 63 " \"Name\": {"
66 " \"Value\": \"disable_all_the_things\"" 64 " \"Value\": \"disable_all_the_things\""
67 " }" 65 " }"
68 "}"; 66 "}";
69 67
70 #if defined(OS_CHROMEOS)
71 const char kTestExtension2[] = "behllobkkfkfnphdnhnkndlbkcpglgmj"; 68 const char kTestExtension2[] = "behllobkkfkfnphdnhnkndlbkcpglgmj";
72 const base::FilePath::CharType kTestExtension2Path[] = 69 const base::FilePath::CharType kTestExtension2Path[] =
73 FILE_PATH_LITERAL("extensions/managed_extension2"); 70 FILE_PATH_LITERAL("extensions/managed_extension2");
74 71
75 const char kTestPolicyJSON[] = "{\"Name\":\"disable_all_the_things\"}"; 72 const char kTestPolicyJSON[] = "{\"Name\":\"disable_all_the_things\"}";
76 73
77 const char kTestPolicy2[] = 74 const char kTestPolicy2[] =
78 "{" 75 "{"
79 " \"Another\": {" 76 " \"Another\": {"
80 " \"Value\": \"turn_it_off\"" 77 " \"Value\": \"turn_it_off\""
81 " }" 78 " }"
82 "}"; 79 "}";
83 80
84 const char kTestPolicy2JSON[] = "{\"Another\":\"turn_it_off\"}"; 81 const char kTestPolicy2JSON[] = "{\"Another\":\"turn_it_off\"}";
85 #endif // defined(OS_CHROMEOS)
86 82
87 class ComponentCloudPolicyTest : public ExtensionBrowserTest { 83 class ComponentCloudPolicyTest : public ExtensionBrowserTest {
88 protected: 84 protected:
89 ComponentCloudPolicyTest() {} 85 ComponentCloudPolicyTest() {}
90 virtual ~ComponentCloudPolicyTest() {} 86 virtual ~ComponentCloudPolicyTest() {}
91 87
92 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { 88 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
93 ExtensionBrowserTest::SetUpCommandLine(command_line); 89 ExtensionBrowserTest::SetUpCommandLine(command_line);
94 #if defined(OS_CHROMEOS) 90 #if defined(OS_CHROMEOS)
95 // ExtensionBrowserTest sets the login users to a non-managed value; 91 // ExtensionBrowserTest sets the login users to a non-managed value;
96 // replace it. This is the default username sent in policy blobs from the 92 // replace it. This is the default username sent in policy blobs from the
97 // testserver. 93 // testserver.
98 command_line->AppendSwitchASCII( 94 command_line->AppendSwitchASCII(
99 ::chromeos::switches::kLoginUser, "user@example.com"); 95 ::chromeos::switches::kLoginUser, "user@example.com");
100 #endif 96 #endif
101 } 97 }
102 98
103 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { 99 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE {
104 test_server_.RegisterClient(kDMToken, kDeviceID); 100 test_server_.RegisterClient(kDMToken, kDeviceID);
105 EXPECT_TRUE(test_server_.UpdatePolicyData( 101 EXPECT_TRUE(test_server_.UpdatePolicyData(
106 dm_protocol::kChromeExtensionPolicyType, kTestExtension, kTestPolicy)); 102 dm_protocol::kChromeExtensionPolicyType, kTestExtension, kTestPolicy));
107 ASSERT_TRUE(test_server_.Start()); 103 ASSERT_TRUE(test_server_.Start());
108 104
109 std::string url = test_server_.GetServiceURL().spec(); 105 std::string url = test_server_.GetServiceURL().spec();
110 CommandLine* command_line = CommandLine::ForCurrentProcess(); 106 CommandLine* command_line = CommandLine::ForCurrentProcess();
111 command_line->AppendSwitchASCII(::switches::kDeviceManagementUrl, url); 107 command_line->AppendSwitchASCII(::switches::kDeviceManagementUrl, url);
112 command_line->AppendSwitch(switches::kEnableComponentCloudPolicy);
113 108
114 ExtensionBrowserTest::SetUpInProcessBrowserTestFixture(); 109 ExtensionBrowserTest::SetUpInProcessBrowserTestFixture();
115 } 110 }
116 111
117 virtual void SetUpOnMainThread() OVERRIDE { 112 virtual void SetUpOnMainThread() OVERRIDE {
118 ASSERT_TRUE(PolicyServiceIsEmpty(g_browser_process->policy_service())) 113 ASSERT_TRUE(PolicyServiceIsEmpty(g_browser_process->policy_service()))
119 << "Pre-existing policies in this machine will make this test fail."; 114 << "Pre-existing policies in this machine will make this test fail.";
120 115
121 // Install the initial extension. 116 // Install the initial extension.
122 ExtensionTestMessageListener ready_listener("ready", true); 117 ExtensionTestMessageListener ready_listener("ready", true);
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 base::RunLoop run_loop; 189 base::RunLoop run_loop;
195 policy_service->RefreshPolicies(run_loop.QuitClosure()); 190 policy_service->RefreshPolicies(run_loop.QuitClosure());
196 run_loop.Run(); 191 run_loop.Run();
197 } 192 }
198 193
199 LocalPolicyTestServer test_server_; 194 LocalPolicyTestServer test_server_;
200 scoped_refptr<const extensions::Extension> extension_; 195 scoped_refptr<const extensions::Extension> extension_;
201 scoped_ptr<ExtensionTestMessageListener> event_listener_; 196 scoped_ptr<ExtensionTestMessageListener> event_listener_;
202 }; 197 };
203 198
204 // TODO(joaodasilva): enable these for other platforms once ready.
205 #if defined(OS_CHROMEOS)
206
207 IN_PROC_BROWSER_TEST_F(ComponentCloudPolicyTest, FetchExtensionPolicy) { 199 IN_PROC_BROWSER_TEST_F(ComponentCloudPolicyTest, FetchExtensionPolicy) {
208 // Read the initial policy. 200 // Read the initial policy.
209 ExtensionTestMessageListener policy_listener(kTestPolicyJSON, true); 201 ExtensionTestMessageListener policy_listener(kTestPolicyJSON, true);
210 event_listener_->Reply("get-policy-Name"); 202 event_listener_->Reply("get-policy-Name");
211 EXPECT_TRUE(policy_listener.WaitUntilSatisfied()); 203 EXPECT_TRUE(policy_listener.WaitUntilSatisfied());
212 } 204 }
213 205
214 IN_PROC_BROWSER_TEST_F(ComponentCloudPolicyTest, UpdateExtensionPolicy) { 206 IN_PROC_BROWSER_TEST_F(ComponentCloudPolicyTest, UpdateExtensionPolicy) {
215 // Read the initial policy. 207 // Read the initial policy.
216 ExtensionTestMessageListener policy_listener(kTestPolicyJSON, true); 208 ExtensionTestMessageListener policy_listener(kTestPolicyJSON, true);
(...skipping 30 matching lines...) Expand all
247 scoped_refptr<const extensions::Extension> extension2 = 239 scoped_refptr<const extensions::Extension> extension2 =
248 LoadExtension(kTestExtension2Path); 240 LoadExtension(kTestExtension2Path);
249 ASSERT_TRUE(extension2.get()); 241 ASSERT_TRUE(extension2.get());
250 ASSERT_EQ(kTestExtension2, extension2->id()); 242 ASSERT_EQ(kTestExtension2, extension2->id());
251 243
252 // This extension only sends the 'policy' signal once it receives the policy, 244 // 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'. 245 // and after verifying it has the expected value. Otherwise it sends 'fail'.
254 EXPECT_TRUE(result_listener.WaitUntilSatisfied()); 246 EXPECT_TRUE(result_listener.WaitUntilSatisfied());
255 } 247 }
256 248
257 #endif // OS_CHROMEOS
258
259 } // namespace policy 249 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698