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 "chrome/browser/policy/cloud/component_cloud_policy_service.h" | 5 #include "chrome/browser/policy/cloud/component_cloud_policy_service.h" |
6 | 6 |
7 #include "base/callback.h" | 7 #include "base/callback.h" |
8 #include "base/files/scoped_temp_dir.h" | 8 #include "base/files/scoped_temp_dir.h" |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "base/pickle.h" | 10 #include "base/pickle.h" |
11 #include "base/run_loop.h" | 11 #include "base/run_loop.h" |
12 #include "base/sha1.h" | 12 #include "base/sha1.h" |
13 #include "base/single_thread_task_runner.h" | 13 #include "base/single_thread_task_runner.h" |
14 #include "base/stl_util.h" | 14 #include "base/stl_util.h" |
15 #include "base/values.h" | 15 #include "base/values.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/cloud/mock_cloud_policy_store.h" | 18 #include "chrome/browser/policy/cloud/mock_cloud_policy_store.h" |
19 #include "chrome/browser/policy/cloud/policy_builder.h" | 19 #include "chrome/browser/policy/cloud/policy_builder.h" |
20 #include "chrome/browser/policy/cloud/resource_cache.h" | 20 #include "chrome/browser/policy/cloud/resource_cache.h" |
21 #include "chrome/browser/policy/external_data_fetcher.h" | 21 #include "chrome/browser/policy/external_data_fetcher.h" |
22 #include "chrome/browser/policy/policy_domain_descriptor.h" | 22 #include "chrome/browser/policy/policy_domain_descriptor.h" |
23 #include "chrome/browser/policy/policy_map.h" | 23 #include "chrome/browser/policy/policy_map.h" |
24 #include "chrome/browser/policy/policy_types.h" | 24 #include "chrome/browser/policy/policy_types.h" |
25 #include "chrome/browser/policy/proto/cloud/chrome_extension_policy.pb.h" | 25 #include "chrome/browser/policy/proto/cloud/chrome_extension_policy.pb.h" |
26 #include "chrome/browser/policy/proto/cloud/device_management_backend.pb.h" | 26 #include "chrome/browser/policy/proto/cloud/device_management_backend.pb.h" |
27 #include "components/policy/core/common/policy_schema.h" | 27 #include "components/policy/core/common/schema.h" |
28 #include "content/public/browser/browser_thread.h" | 28 #include "content/public/browser/browser_thread.h" |
29 #include "content/public/test/test_browser_thread.h" | 29 #include "content/public/test/test_browser_thread.h" |
30 #include "net/url_request/test_url_fetcher_factory.h" | 30 #include "net/url_request/test_url_fetcher_factory.h" |
31 #include "net/url_request/url_fetcher_delegate.h" | 31 #include "net/url_request/url_fetcher_delegate.h" |
32 #include "net/url_request/url_request_context.h" | 32 #include "net/url_request/url_request_context.h" |
33 #include "net/url_request/url_request_context_getter.h" | 33 #include "net/url_request/url_request_context_getter.h" |
34 #include "testing/gmock/include/gmock/gmock.h" | 34 #include "testing/gmock/include/gmock/gmock.h" |
35 #include "testing/gtest/include/gtest/gtest.h" | 35 #include "testing/gtest/include/gtest/gtest.h" |
36 | 36 |
37 namespace em = enterprise_management; | 37 namespace em = enterprise_management; |
(...skipping 16 matching lines...) Expand all Loading... |
54 " \"Value\": \"disabled\"" | 54 " \"Value\": \"disabled\"" |
55 " }," | 55 " }," |
56 " \"Second\": {" | 56 " \"Second\": {" |
57 " \"Value\": \"maybe\"," | 57 " \"Value\": \"maybe\"," |
58 " \"Level\": \"Recommended\"" | 58 " \"Level\": \"Recommended\"" |
59 " }" | 59 " }" |
60 "}"; | 60 "}"; |
61 | 61 |
62 const char kTestSchema[] = | 62 const char kTestSchema[] = |
63 "{" | 63 "{" |
64 " \"$schema\": \"http://json-schema.org/draft-03/schema#\"," | |
65 " \"type\": \"object\"," | 64 " \"type\": \"object\"," |
66 " \"properties\": {" | 65 " \"properties\": {" |
67 " \"Name\": { \"type\": \"string\" }," | 66 " \"Name\": { \"type\": \"string\" }," |
68 " \"Second\": { \"type\": \"string\" }" | 67 " \"Second\": { \"type\": \"string\" }" |
69 " }" | 68 " }" |
70 "}"; | 69 "}"; |
71 | 70 |
72 class MockComponentCloudPolicyDelegate | 71 class MockComponentCloudPolicyDelegate |
73 : public ComponentCloudPolicyService::Delegate { | 72 : public ComponentCloudPolicyService::Delegate { |
74 public: | 73 public: |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
187 scoped_ptr<em::PolicyFetchResponse> CreateResponse() { | 186 scoped_ptr<em::PolicyFetchResponse> CreateResponse() { |
188 builder_.Build(); | 187 builder_.Build(); |
189 return make_scoped_ptr(new em::PolicyFetchResponse(builder_.policy())); | 188 return make_scoped_ptr(new em::PolicyFetchResponse(builder_.policy())); |
190 } | 189 } |
191 | 190 |
192 std::string CreateSerializedResponse() { | 191 std::string CreateSerializedResponse() { |
193 builder_.Build(); | 192 builder_.Build(); |
194 return builder_.GetBlob(); | 193 return builder_.GetBlob(); |
195 } | 194 } |
196 | 195 |
197 scoped_ptr<PolicySchema> CreateTestSchema() { | 196 scoped_ptr<SchemaOwner> CreateTestSchema() { |
198 std::string error; | 197 std::string error; |
199 scoped_ptr<PolicySchema> schema = PolicySchema::Parse(kTestSchema, &error); | 198 scoped_ptr<SchemaOwner> schema = SchemaOwner::Parse(kTestSchema, &error); |
200 EXPECT_TRUE(schema) << error; | 199 EXPECT_TRUE(schema) << error; |
201 return schema.Pass(); | 200 return schema.Pass(); |
202 } | 201 } |
203 | 202 |
204 base::MessageLoop loop_; | 203 base::MessageLoop loop_; |
205 content::TestBrowserThread ui_thread_; | 204 content::TestBrowserThread ui_thread_; |
206 content::TestBrowserThread file_thread_; | 205 content::TestBrowserThread file_thread_; |
207 base::ScopedTempDir temp_dir_; | 206 base::ScopedTempDir temp_dir_; |
208 scoped_refptr<TestURLRequestContextGetter> request_context_; | 207 scoped_refptr<TestURLRequestContextGetter> request_context_; |
209 net::TestURLFetcherFactory fetcher_factory_; | 208 net::TestURLFetcherFactory fetcher_factory_; |
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
518 Mock::VerifyAndClearExpectations(&delegate_); | 517 Mock::VerifyAndClearExpectations(&delegate_); |
519 | 518 |
520 // The policy is now being served. | 519 // The policy is now being served. |
521 PolicyNamespace ns(POLICY_DOMAIN_EXTENSIONS, kTestExtension); | 520 PolicyNamespace ns(POLICY_DOMAIN_EXTENSIONS, kTestExtension); |
522 PolicyBundle expected_bundle; | 521 PolicyBundle expected_bundle; |
523 expected_bundle.Get(ns).CopyFrom(expected_policy_); | 522 expected_bundle.Get(ns).CopyFrom(expected_policy_); |
524 EXPECT_TRUE(service_->policy().Equals(expected_bundle)); | 523 EXPECT_TRUE(service_->policy().Equals(expected_bundle)); |
525 } | 524 } |
526 | 525 |
527 } // namespace policy | 526 } // namespace policy |
OLD | NEW |