| 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/base64url.h" | 7 #include "base/base64url.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
| 10 #include "base/files/file_util.h" | 10 #include "base/files/file_util.h" |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 command_line->AppendSwitchASCII(switches::kDeviceManagementUrl, url); | 115 command_line->AppendSwitchASCII(switches::kDeviceManagementUrl, url); |
| 116 | 116 |
| 117 ExtensionBrowserTest::SetUpInProcessBrowserTestFixture(); | 117 ExtensionBrowserTest::SetUpInProcessBrowserTestFixture(); |
| 118 } | 118 } |
| 119 | 119 |
| 120 void SetUpOnMainThread() override { | 120 void SetUpOnMainThread() override { |
| 121 ASSERT_TRUE(PolicyServiceIsEmpty(g_browser_process->policy_service())) | 121 ASSERT_TRUE(PolicyServiceIsEmpty(g_browser_process->policy_service())) |
| 122 << "Pre-existing policies in this machine will make this test fail."; | 122 << "Pre-existing policies in this machine will make this test fail."; |
| 123 | 123 |
| 124 // Install the initial extension. | 124 // Install the initial extension. |
| 125 ExtensionTestMessageListener ready_listener("ready", true); | 125 ExtensionTestMessageListener ready_listener("ready", false); |
| 126 event_listener_.reset(new ExtensionTestMessageListener("event", true)); | 126 event_listener_.reset(new ExtensionTestMessageListener("event", true)); |
| 127 extension_ = LoadExtension(kTestExtensionPath); | 127 extension_ = LoadExtension(kTestExtensionPath); |
| 128 ASSERT_TRUE(extension_.get()); | 128 ASSERT_TRUE(extension_.get()); |
| 129 ASSERT_EQ(kTestExtension, extension_->id()); | 129 ASSERT_EQ(kTestExtension, extension_->id()); |
| 130 EXPECT_TRUE(ready_listener.WaitUntilSatisfied()); | 130 EXPECT_TRUE(ready_listener.WaitUntilSatisfied()); |
| 131 | 131 |
| 132 // And start with a signed-in user. | 132 // And start with a signed-in user. |
| 133 SignInAndRegister(); | 133 SignInAndRegister(); |
| 134 | 134 |
| 135 // The extension will receive an update event. | 135 // The extension will receive an update event. |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 216 run_loop.Run(); | 216 run_loop.Run(); |
| 217 } | 217 } |
| 218 | 218 |
| 219 LocalPolicyTestServer test_server_; | 219 LocalPolicyTestServer test_server_; |
| 220 scoped_refptr<const extensions::Extension> extension_; | 220 scoped_refptr<const extensions::Extension> extension_; |
| 221 std::unique_ptr<ExtensionTestMessageListener> event_listener_; | 221 std::unique_ptr<ExtensionTestMessageListener> event_listener_; |
| 222 }; | 222 }; |
| 223 | 223 |
| 224 IN_PROC_BROWSER_TEST_F(ComponentCloudPolicyTest, FetchExtensionPolicy) { | 224 IN_PROC_BROWSER_TEST_F(ComponentCloudPolicyTest, FetchExtensionPolicy) { |
| 225 // Read the initial policy. | 225 // Read the initial policy. |
| 226 ExtensionTestMessageListener policy_listener(kTestPolicyJSON, true); | 226 ExtensionTestMessageListener policy_listener(kTestPolicyJSON, false); |
| 227 event_listener_->Reply("get-policy-Name"); | 227 event_listener_->Reply("get-policy-Name"); |
| 228 EXPECT_TRUE(policy_listener.WaitUntilSatisfied()); | 228 EXPECT_TRUE(policy_listener.WaitUntilSatisfied()); |
| 229 } | 229 } |
| 230 | 230 |
| 231 IN_PROC_BROWSER_TEST_F(ComponentCloudPolicyTest, UpdateExtensionPolicy) { | 231 IN_PROC_BROWSER_TEST_F(ComponentCloudPolicyTest, UpdateExtensionPolicy) { |
| 232 // Read the initial policy. | 232 // Read the initial policy. |
| 233 ExtensionTestMessageListener policy_listener(kTestPolicyJSON, true); | 233 ExtensionTestMessageListener policy_listener(kTestPolicyJSON, true); |
| 234 event_listener_->Reply("get-policy-Name"); | 234 event_listener_->Reply("get-policy-Name"); |
| 235 EXPECT_TRUE(policy_listener.WaitUntilSatisfied()); | 235 EXPECT_TRUE(policy_listener.WaitUntilSatisfied()); |
| 236 | 236 |
| 237 // Update the policy at the server and reload policy. | 237 // Update the policy at the server and reload policy. |
| 238 event_listener_.reset(new ExtensionTestMessageListener("event", true)); | 238 event_listener_.reset(new ExtensionTestMessageListener("event", true)); |
| 239 policy_listener.Reply("idle"); | 239 policy_listener.Reply("idle"); |
| 240 EXPECT_TRUE(test_server_.UpdatePolicyData( | 240 EXPECT_TRUE(test_server_.UpdatePolicyData( |
| 241 dm_protocol::kChromeExtensionPolicyType, kTestExtension, kTestPolicy2)); | 241 dm_protocol::kChromeExtensionPolicyType, kTestExtension, kTestPolicy2)); |
| 242 RefreshPolicies(); | 242 RefreshPolicies(); |
| 243 | 243 |
| 244 // Check that the update event was received, and verify the new policy | 244 // Check that the update event was received, and verify the new policy |
| 245 // values. | 245 // values. |
| 246 EXPECT_TRUE(event_listener_->WaitUntilSatisfied()); | 246 EXPECT_TRUE(event_listener_->WaitUntilSatisfied()); |
| 247 | 247 |
| 248 // This policy was removed. | 248 // This policy was removed. |
| 249 ExtensionTestMessageListener policy_listener1("{}", true); | 249 ExtensionTestMessageListener policy_listener1("{}", true); |
| 250 event_listener_->Reply("get-policy-Name"); | 250 event_listener_->Reply("get-policy-Name"); |
| 251 EXPECT_TRUE(policy_listener1.WaitUntilSatisfied()); | 251 EXPECT_TRUE(policy_listener1.WaitUntilSatisfied()); |
| 252 | 252 |
| 253 ExtensionTestMessageListener policy_listener2(kTestPolicy2JSON, true); | 253 ExtensionTestMessageListener policy_listener2(kTestPolicy2JSON, false); |
| 254 policy_listener1.Reply("get-policy-Another"); | 254 policy_listener1.Reply("get-policy-Another"); |
| 255 EXPECT_TRUE(policy_listener2.WaitUntilSatisfied()); | 255 EXPECT_TRUE(policy_listener2.WaitUntilSatisfied()); |
| 256 } | 256 } |
| 257 | 257 |
| 258 IN_PROC_BROWSER_TEST_F(ComponentCloudPolicyTest, InstallNewExtension) { | 258 IN_PROC_BROWSER_TEST_F(ComponentCloudPolicyTest, InstallNewExtension) { |
| 259 EXPECT_TRUE(test_server_.UpdatePolicyData( | 259 EXPECT_TRUE(test_server_.UpdatePolicyData( |
| 260 dm_protocol::kChromeExtensionPolicyType, kTestExtension2, kTestPolicy2)); | 260 dm_protocol::kChromeExtensionPolicyType, kTestExtension2, kTestPolicy2)); |
| 261 // Installing a new extension doesn't trigger another policy fetch because | 261 // Installing a new extension doesn't trigger another policy fetch because |
| 262 // the server always sends down the list of all extensions that have policy. | 262 // the server always sends down the list of all extensions that have policy. |
| 263 // Fetch now that the configuration has been updated and before installing | 263 // Fetch now that the configuration has been updated and before installing |
| 264 // the extension. | 264 // the extension. |
| 265 RefreshPolicies(); | 265 RefreshPolicies(); |
| 266 | 266 |
| 267 ExtensionTestMessageListener result_listener("ok", true); | 267 ExtensionTestMessageListener result_listener("ok", false); |
| 268 result_listener.set_failure_message("fail"); | 268 result_listener.set_failure_message("fail"); |
| 269 scoped_refptr<const extensions::Extension> extension2 = | 269 scoped_refptr<const extensions::Extension> extension2 = |
| 270 LoadExtension(kTestExtension2Path); | 270 LoadExtension(kTestExtension2Path); |
| 271 ASSERT_TRUE(extension2.get()); | 271 ASSERT_TRUE(extension2.get()); |
| 272 ASSERT_EQ(kTestExtension2, extension2->id()); | 272 ASSERT_EQ(kTestExtension2, extension2->id()); |
| 273 | 273 |
| 274 // This extension only sends the 'policy' signal once it receives the policy, | 274 // This extension only sends the 'policy' signal once it receives the policy, |
| 275 // and after verifying it has the expected value. Otherwise it sends 'fail'. | 275 // and after verifying it has the expected value. Otherwise it sends 'fail'. |
| 276 EXPECT_TRUE(result_listener.WaitUntilSatisfied()); | 276 EXPECT_TRUE(result_listener.WaitUntilSatisfied()); |
| 277 } | 277 } |
| (...skipping 30 matching lines...) Expand all Loading... |
| 308 EXPECT_TRUE(base::PathExists(cache_path)); | 308 EXPECT_TRUE(base::PathExists(cache_path)); |
| 309 | 309 |
| 310 // Now sign-out. The policy cache should be removed, and the extension should | 310 // Now sign-out. The policy cache should be removed, and the extension should |
| 311 // get an empty policy update. | 311 // get an empty policy update. |
| 312 ExtensionTestMessageListener event_listener("event", true); | 312 ExtensionTestMessageListener event_listener("event", true); |
| 313 initial_policy_listener.Reply("idle"); | 313 initial_policy_listener.Reply("idle"); |
| 314 SignOut(); | 314 SignOut(); |
| 315 EXPECT_TRUE(event_listener.WaitUntilSatisfied()); | 315 EXPECT_TRUE(event_listener.WaitUntilSatisfied()); |
| 316 | 316 |
| 317 // The extension got an update event; verify that the policy was empty. | 317 // The extension got an update event; verify that the policy was empty. |
| 318 ExtensionTestMessageListener signout_policy_listener("{}", true); | 318 ExtensionTestMessageListener signout_policy_listener("{}", false); |
| 319 event_listener.Reply("get-policy-Name"); | 319 event_listener.Reply("get-policy-Name"); |
| 320 EXPECT_TRUE(signout_policy_listener.WaitUntilSatisfied()); | 320 EXPECT_TRUE(signout_policy_listener.WaitUntilSatisfied()); |
| 321 | 321 |
| 322 // Verify that the cache is gone. | 322 // Verify that the cache is gone. |
| 323 EXPECT_FALSE(base::PathExists(cache_path)); | 323 EXPECT_FALSE(base::PathExists(cache_path)); |
| 324 | 324 |
| 325 // Verify that the policy is fetched again if the user signs back in. | 325 // Verify that the policy is fetched again if the user signs back in. |
| 326 ExtensionTestMessageListener event_listener2("event", true); | 326 ExtensionTestMessageListener event_listener2("event", true); |
| 327 SignInAndRegister(); | 327 SignInAndRegister(); |
| 328 EXPECT_TRUE(event_listener2.WaitUntilSatisfied()); | 328 EXPECT_TRUE(event_listener2.WaitUntilSatisfied()); |
| 329 | 329 |
| 330 // The extension got updated policy; verify it. | 330 // The extension got updated policy; verify it. |
| 331 ExtensionTestMessageListener signin_policy_listener(kTestPolicyJSON, true); | 331 ExtensionTestMessageListener signin_policy_listener(kTestPolicyJSON, false); |
| 332 event_listener2.Reply("get-policy-Name"); | 332 event_listener2.Reply("get-policy-Name"); |
| 333 EXPECT_TRUE(signin_policy_listener.WaitUntilSatisfied()); | 333 EXPECT_TRUE(signin_policy_listener.WaitUntilSatisfied()); |
| 334 | 334 |
| 335 // And the cache is back. | 335 // And the cache is back. |
| 336 EXPECT_TRUE(base::PathExists(cache_path)); | 336 EXPECT_TRUE(base::PathExists(cache_path)); |
| 337 } | 337 } |
| 338 #endif | 338 #endif |
| 339 | 339 |
| 340 } // namespace policy | 340 } // namespace policy |
| OLD | NEW |