| 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/message_loop/message_loop.h" | 10 #include "base/message_loop/message_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 "components/arc/test/fake_arc_bridge_service.h" | 13 #include "components/arc/arc_bridge_service.h" |
| 14 #include "components/arc/test/fake_policy_instance.h" | 14 #include "components/arc/test/fake_policy_instance.h" |
| 15 #include "components/policy/core/common/mock_policy_service.h" | 15 #include "components/policy/core/common/mock_policy_service.h" |
| 16 #include "components/policy/core/common/policy_map.h" | 16 #include "components/policy/core/common/policy_map.h" |
| 17 #include "components/policy/core/common/policy_namespace.h" | 17 #include "components/policy/core/common/policy_namespace.h" |
| 18 #include "components/policy/core/common/policy_types.h" | 18 #include "components/policy/core/common/policy_types.h" |
| 19 #include "components/policy/policy_constants.h" | 19 #include "components/policy/policy_constants.h" |
| 20 #include "mojo/public/cpp/bindings/string.h" | 20 #include "mojo/public/cpp/bindings/string.h" |
| 21 #include "testing/gmock/include/gmock/gmock.h" | 21 #include "testing/gmock/include/gmock/gmock.h" |
| 22 #include "testing/gtest/include/gtest/gtest.h" | 22 #include "testing/gtest/include/gtest/gtest.h" |
| 23 | 23 |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 using testing::_; | 94 using testing::_; |
| 95 using testing::ReturnRef; | 95 using testing::ReturnRef; |
| 96 | 96 |
| 97 namespace arc { | 97 namespace arc { |
| 98 | 98 |
| 99 class ArcPolicyBridgeTest : public testing::Test { | 99 class ArcPolicyBridgeTest : public testing::Test { |
| 100 public: | 100 public: |
| 101 ArcPolicyBridgeTest() {} | 101 ArcPolicyBridgeTest() {} |
| 102 | 102 |
| 103 void SetUp() override { | 103 void SetUp() override { |
| 104 bridge_service_.reset(new FakeArcBridgeService()); | 104 bridge_service_ = base::MakeUnique<ArcBridgeService>(); |
| 105 policy_bridge_.reset( | 105 policy_bridge_ = base::MakeUnique<ArcPolicyBridge>(bridge_service_.get(), |
| 106 new ArcPolicyBridge(bridge_service_.get(), &policy_service_)); | 106 &policy_service_); |
| 107 policy_bridge_->OverrideIsManagedForTesting(true); | 107 policy_bridge_->OverrideIsManagedForTesting(true); |
| 108 | 108 |
| 109 EXPECT_CALL(policy_service_, | 109 EXPECT_CALL(policy_service_, |
| 110 GetPolicies(policy::PolicyNamespace( | 110 GetPolicies(policy::PolicyNamespace( |
| 111 policy::POLICY_DOMAIN_CHROME, std::string()))) | 111 policy::POLICY_DOMAIN_CHROME, std::string()))) |
| 112 .WillRepeatedly(ReturnRef(policy_map_)); | 112 .WillRepeatedly(ReturnRef(policy_map_)); |
| 113 EXPECT_CALL(policy_service_, AddObserver(policy::POLICY_DOMAIN_CHROME, _)) | 113 EXPECT_CALL(policy_service_, AddObserver(policy::POLICY_DOMAIN_CHROME, _)) |
| 114 .Times(1); | 114 .Times(1); |
| 115 | 115 |
| 116 policy_instance_.reset(new FakePolicyInstance); | 116 policy_instance_ = base::MakeUnique<FakePolicyInstance>(); |
| 117 bridge_service_->policy()->SetInstance(policy_instance_.get()); | 117 bridge_service_->policy()->SetInstance(policy_instance_.get()); |
| 118 } | 118 } |
| 119 | 119 |
| 120 protected: | 120 protected: |
| 121 ArcPolicyBridge* policy_bridge() { return policy_bridge_.get(); } | 121 ArcPolicyBridge* policy_bridge() { return policy_bridge_.get(); } |
| 122 FakePolicyInstance* policy_instance() { return policy_instance_.get(); } | 122 FakePolicyInstance* policy_instance() { return policy_instance_.get(); } |
| 123 policy::PolicyMap& policy_map() { return policy_map_; } | 123 policy::PolicyMap& policy_map() { return policy_map_; } |
| 124 | 124 |
| 125 private: | 125 private: |
| 126 // Not an unused variable. Unit tests do not have a message loop by themselves | 126 // Not an unused variable. Unit tests do not have a message loop by themselves |
| 127 // and mojo needs a message loop for communication. | 127 // and mojo needs a message loop for communication. |
| 128 base::MessageLoop loop_; | 128 base::MessageLoop loop_; |
| 129 std::unique_ptr<FakeArcBridgeService> bridge_service_; | 129 std::unique_ptr<ArcBridgeService> bridge_service_; |
| 130 std::unique_ptr<ArcPolicyBridge> policy_bridge_; | 130 std::unique_ptr<ArcPolicyBridge> policy_bridge_; |
| 131 // Always keep policy_instance_ below bridge_service_, so that | 131 // Always keep policy_instance_ below bridge_service_, so that |
| 132 // policy_instance_ is destructed first. It needs to remove itself as | 132 // policy_instance_ is destructed first. It needs to remove itself as |
| 133 // observer. | 133 // observer. |
| 134 std::unique_ptr<FakePolicyInstance> policy_instance_; | 134 std::unique_ptr<FakePolicyInstance> policy_instance_; |
| 135 policy::PolicyMap policy_map_; | 135 policy::PolicyMap policy_map_; |
| 136 policy::MockPolicyService policy_service_; | 136 policy::MockPolicyService policy_service_; |
| 137 | 137 |
| 138 DISALLOW_COPY_AND_ASSIGN(ArcPolicyBridgeTest); | 138 DISALLOW_COPY_AND_ASSIGN(ArcPolicyBridgeTest); |
| 139 }; | 139 }; |
| (...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 369 TEST_F(ArcPolicyBridgeTest, PolicyInstanceUnmanagedTest) { | 369 TEST_F(ArcPolicyBridgeTest, PolicyInstanceUnmanagedTest) { |
| 370 policy_bridge()->OverrideIsManagedForTesting(false); | 370 policy_bridge()->OverrideIsManagedForTesting(false); |
| 371 policy_instance()->CallGetPolicies(PolicyStringCallback("")); | 371 policy_instance()->CallGetPolicies(PolicyStringCallback("")); |
| 372 } | 372 } |
| 373 | 373 |
| 374 TEST_F(ArcPolicyBridgeTest, PolicyInstanceManagedTest) { | 374 TEST_F(ArcPolicyBridgeTest, PolicyInstanceManagedTest) { |
| 375 policy_instance()->CallGetPolicies(PolicyStringCallback("{}")); | 375 policy_instance()->CallGetPolicies(PolicyStringCallback("{}")); |
| 376 } | 376 } |
| 377 | 377 |
| 378 } // namespace arc | 378 } // namespace arc |
| OLD | NEW |