OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 <memory> | 5 #include <memory> |
6 #include <string> | 6 #include <string> |
7 | 7 |
8 #include "base/macros.h" | 8 #include "base/macros.h" |
9 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
11 #include "base/values.h" | 11 #include "base/values.h" |
12 #include "chrome/browser/chromeos/arc/policy/arc_policy_bridge.h" | 12 #include "chrome/browser/chromeos/arc/policy/arc_policy_bridge.h" |
13 #include "chrome/browser/chromeos/login/users/fake_chrome_user_manager.h" | 13 #include "chrome/browser/chromeos/login/users/fake_chrome_user_manager.h" |
14 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h" | 14 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h" |
| 15 #include "chrome/common/pref_names.h" |
15 #include "chrome/test/base/testing_browser_process.h" | 16 #include "chrome/test/base/testing_browser_process.h" |
16 #include "chrome/test/base/testing_profile_manager.h" | 17 #include "chrome/test/base/testing_profile_manager.h" |
17 #include "components/arc/arc_bridge_service.h" | 18 #include "components/arc/arc_bridge_service.h" |
18 #include "components/arc/test/fake_policy_instance.h" | 19 #include "components/arc/test/fake_policy_instance.h" |
19 #include "components/policy/core/common/mock_policy_service.h" | 20 #include "components/policy/core/common/mock_policy_service.h" |
20 #include "components/policy/core/common/policy_map.h" | 21 #include "components/policy/core/common/policy_map.h" |
21 #include "components/policy/core/common/policy_namespace.h" | 22 #include "components/policy/core/common/policy_namespace.h" |
22 #include "components/policy/core/common/policy_types.h" | 23 #include "components/policy/core/common/policy_types.h" |
23 #include "components/policy/policy_constants.h" | 24 #include "components/policy/policy_constants.h" |
24 #include "components/safe_json/testing_json_parser.h" | 25 #include "components/safe_json/testing_json_parser.h" |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 new chromeos::FakeChromeUserManager(); | 137 new chromeos::FakeChromeUserManager(); |
137 user_manager_enabler_ = | 138 user_manager_enabler_ = |
138 base::MakeUnique<chromeos::ScopedUserManagerEnabler>(fake_user_manager); | 139 base::MakeUnique<chromeos::ScopedUserManagerEnabler>(fake_user_manager); |
139 const AccountId account_id( | 140 const AccountId account_id( |
140 AccountId::FromUserEmailGaiaId("user@gmail.com", "1111111111")); | 141 AccountId::FromUserEmailGaiaId("user@gmail.com", "1111111111")); |
141 fake_user_manager->AddUser(account_id); | 142 fake_user_manager->AddUser(account_id); |
142 fake_user_manager->LoginUser(account_id); | 143 fake_user_manager->LoginUser(account_id); |
143 testing_profile_manager_ = base::MakeUnique<TestingProfileManager>( | 144 testing_profile_manager_ = base::MakeUnique<TestingProfileManager>( |
144 TestingBrowserProcess::GetGlobal()); | 145 TestingBrowserProcess::GetGlobal()); |
145 ASSERT_TRUE(testing_profile_manager_->SetUp()); | 146 ASSERT_TRUE(testing_profile_manager_->SetUp()); |
146 ASSERT_TRUE( | 147 profile_ = testing_profile_manager_->CreateTestingProfile("user@gmail.com"); |
147 testing_profile_manager_->CreateTestingProfile("user@gmail.com")); | 148 ASSERT_TRUE(profile_); |
148 } | 149 } |
149 | 150 |
150 protected: | 151 protected: |
151 ArcPolicyBridge* policy_bridge() { return policy_bridge_.get(); } | 152 ArcPolicyBridge* policy_bridge() { return policy_bridge_.get(); } |
152 FakePolicyInstance* policy_instance() { return policy_instance_.get(); } | 153 FakePolicyInstance* policy_instance() { return policy_instance_.get(); } |
153 policy::PolicyMap& policy_map() { return policy_map_; } | 154 policy::PolicyMap& policy_map() { return policy_map_; } |
154 base::RunLoop& run_loop() { return run_loop_; } | 155 base::RunLoop& run_loop() { return run_loop_; } |
| 156 Profile* profile() { return profile_; } |
155 | 157 |
156 private: | 158 private: |
157 safe_json::TestingJsonParser::ScopedFactoryOverride factory_override_; | 159 safe_json::TestingJsonParser::ScopedFactoryOverride factory_override_; |
158 content::TestBrowserThreadBundle thread_bundle_; | 160 content::TestBrowserThreadBundle thread_bundle_; |
159 std::unique_ptr<chromeos::ScopedUserManagerEnabler> user_manager_enabler_; | 161 std::unique_ptr<chromeos::ScopedUserManagerEnabler> user_manager_enabler_; |
160 std::unique_ptr<TestingProfileManager> testing_profile_manager_; | 162 std::unique_ptr<TestingProfileManager> testing_profile_manager_; |
161 base::RunLoop run_loop_; | 163 base::RunLoop run_loop_; |
| 164 TestingProfile* profile_; |
162 | 165 |
163 std::unique_ptr<ArcBridgeService> bridge_service_; | 166 std::unique_ptr<ArcBridgeService> bridge_service_; |
164 std::unique_ptr<ArcPolicyBridge> policy_bridge_; | 167 std::unique_ptr<ArcPolicyBridge> policy_bridge_; |
165 // Always keep policy_instance_ below bridge_service_, so that | 168 // Always keep policy_instance_ below bridge_service_, so that |
166 // policy_instance_ is destructed first. It needs to remove itself as | 169 // policy_instance_ is destructed first. It needs to remove itself as |
167 // observer. | 170 // observer. |
168 std::unique_ptr<FakePolicyInstance> policy_instance_; | 171 std::unique_ptr<FakePolicyInstance> policy_instance_; |
169 policy::PolicyMap policy_map_; | 172 policy::PolicyMap policy_map_; |
170 policy::MockPolicyService policy_service_; | 173 policy::MockPolicyService policy_service_; |
171 | 174 |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
358 "\"lockTaskAllowed\":false," | 361 "\"lockTaskAllowed\":false," |
359 "\"packageName\":\"com.google.android.apps.youtube.kids\"," | 362 "\"packageName\":\"com.google.android.apps.youtube.kids\"," |
360 "\"permissionGrants\":[]" | 363 "\"permissionGrants\":[]" |
361 "}]," | 364 "}]," |
362 "\"cameraDisabled\":true," | 365 "\"cameraDisabled\":true," |
363 "\"defaultPermissionPolicy\":\"GRANT\"" | 366 "\"defaultPermissionPolicy\":\"GRANT\"" |
364 "}")); | 367 "}")); |
365 } | 368 } |
366 | 369 |
367 TEST_F(ArcPolicyBridgeTest, EmptyReportComplianceTest) { | 370 TEST_F(ArcPolicyBridgeTest, EmptyReportComplianceTest) { |
| 371 ASSERT_FALSE( |
| 372 profile()->GetPrefs()->GetBoolean(prefs::kArcPolicyComplianceReported)); |
368 policy_bridge()->ReportCompliance( | 373 policy_bridge()->ReportCompliance( |
369 "{}", PolicyComplianceCallback(run_loop().QuitClosure(), | 374 "{}", PolicyComplianceCallback(run_loop().QuitClosure(), |
370 kPolicyCompliantResponse)); | 375 kPolicyCompliantResponse)); |
371 run_loop().Run(); | 376 run_loop().Run(); |
| 377 ASSERT_TRUE( |
| 378 profile()->GetPrefs()->GetBoolean(prefs::kArcPolicyComplianceReported)); |
372 } | 379 } |
373 | 380 |
374 TEST_F(ArcPolicyBridgeTest, ParsableReportComplianceTest) { | 381 TEST_F(ArcPolicyBridgeTest, ParsableReportComplianceTest) { |
| 382 ASSERT_FALSE( |
| 383 profile()->GetPrefs()->GetBoolean(prefs::kArcPolicyComplianceReported)); |
375 policy_bridge()->ReportCompliance( | 384 policy_bridge()->ReportCompliance( |
376 "{\"nonComplianceDetails\" : []}", | 385 "{\"nonComplianceDetails\" : []}", |
377 PolicyComplianceCallback(run_loop().QuitClosure(), | 386 PolicyComplianceCallback(run_loop().QuitClosure(), |
378 kPolicyCompliantResponse)); | 387 kPolicyCompliantResponse)); |
379 run_loop().Run(); | 388 run_loop().Run(); |
| 389 ASSERT_TRUE( |
| 390 profile()->GetPrefs()->GetBoolean(prefs::kArcPolicyComplianceReported)); |
380 } | 391 } |
381 | 392 |
382 TEST_F(ArcPolicyBridgeTest, NonParsableReportComplianceTest) { | 393 TEST_F(ArcPolicyBridgeTest, NonParsableReportComplianceTest) { |
| 394 ASSERT_FALSE( |
| 395 profile()->GetPrefs()->GetBoolean(prefs::kArcPolicyComplianceReported)); |
383 policy_bridge()->ReportCompliance( | 396 policy_bridge()->ReportCompliance( |
384 "\"nonComplianceDetails\" : [}", | 397 "\"nonComplianceDetails\" : [}", |
385 PolicyComplianceCallback(run_loop().QuitClosure(), | 398 PolicyComplianceCallback(run_loop().QuitClosure(), |
386 kPolicyCompliantResponse)); | 399 kPolicyCompliantResponse)); |
387 run_loop().Run(); | 400 run_loop().Run(); |
| 401 ASSERT_FALSE( |
| 402 profile()->GetPrefs()->GetBoolean(prefs::kArcPolicyComplianceReported)); |
388 } | 403 } |
389 | 404 |
390 TEST_F(ArcPolicyBridgeTest, ReportComplianceTest_WithNonCompliantDetails) { | 405 TEST_F(ArcPolicyBridgeTest, ReportComplianceTest_WithNonCompliantDetails) { |
| 406 ASSERT_FALSE( |
| 407 profile()->GetPrefs()->GetBoolean(prefs::kArcPolicyComplianceReported)); |
391 policy_bridge()->ReportCompliance( | 408 policy_bridge()->ReportCompliance( |
392 "{\"nonComplianceDetails\" : " | 409 "{\"nonComplianceDetails\" : " |
393 "[{\"fieldPath\":\"\",\"nonComplianceReason\":0,\"packageName\":\"\"," | 410 "[{\"fieldPath\":\"\",\"nonComplianceReason\":0,\"packageName\":\"\"," |
394 "\"settingName\":\"someSetting\",\"cachedSize\":-1}]}", | 411 "\"settingName\":\"someSetting\",\"cachedSize\":-1}]}", |
395 PolicyComplianceCallback(run_loop().QuitClosure(), | 412 PolicyComplianceCallback(run_loop().QuitClosure(), |
396 kPolicyCompliantResponse)); | 413 kPolicyCompliantResponse)); |
397 run_loop().Run(); | 414 run_loop().Run(); |
| 415 ASSERT_TRUE( |
| 416 profile()->GetPrefs()->GetBoolean(prefs::kArcPolicyComplianceReported)); |
398 } | 417 } |
399 | 418 |
400 // This and the following test send the policies through a mojo connection | 419 // This and the following test send the policies through a mojo connection |
401 // between a PolicyInstance and the PolicyBridge. | 420 // between a PolicyInstance and the PolicyBridge. |
402 TEST_F(ArcPolicyBridgeTest, PolicyInstanceUnmanagedTest) { | 421 TEST_F(ArcPolicyBridgeTest, PolicyInstanceUnmanagedTest) { |
403 policy_bridge()->OverrideIsManagedForTesting(false); | 422 policy_bridge()->OverrideIsManagedForTesting(false); |
404 policy_instance()->CallGetPolicies(PolicyStringCallback("")); | 423 policy_instance()->CallGetPolicies(PolicyStringCallback("")); |
405 } | 424 } |
406 | 425 |
407 TEST_F(ArcPolicyBridgeTest, PolicyInstanceManagedTest) { | 426 TEST_F(ArcPolicyBridgeTest, PolicyInstanceManagedTest) { |
408 policy_instance()->CallGetPolicies(PolicyStringCallback("{}")); | 427 policy_instance()->CallGetPolicies(PolicyStringCallback("{}")); |
409 } | 428 } |
410 | 429 |
411 } // namespace arc | 430 } // namespace arc |
OLD | NEW |