OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <vector> | 5 #include <vector> |
6 | 6 |
7 #include "base/message_loop.h" | 7 #include "base/message_loop.h" |
8 #include "base/scoped_temp_dir.h" | 8 #include "base/scoped_temp_dir.h" |
9 #include "base/values.h" | 9 #include "base/values.h" |
10 #include "chrome/browser/browser_process.h" | 10 #include "chrome/browser/browser_process.h" |
11 #include "chrome/browser/policy/cloud_policy_identity_strategy.h" | 11 #include "chrome/browser/policy/cloud_policy_identity_strategy.h" |
12 #include "chrome/browser/policy/logging_work_scheduler.h" | 12 #include "chrome/browser/policy/logging_work_scheduler.h" |
13 #include "chrome/browser/policy/mock_configuration_policy_store.h" | 13 #include "chrome/browser/policy/mock_configuration_policy_store.h" |
14 #include "chrome/browser/policy/proto/cloud_policy.pb.h" | 14 #include "chrome/browser/policy/proto/cloud_policy.pb.h" |
15 #include "chrome/browser/policy/proto/device_management_backend.pb.h" | 15 #include "chrome/browser/policy/proto/device_management_backend.pb.h" |
16 #include "chrome/browser/policy/testing_cloud_policy_subsystem.h" | 16 #include "chrome/browser/policy/testing_cloud_policy_subsystem.h" |
17 #include "chrome/browser/policy/testing_policy_url_fetcher_factory.h" | 17 #include "chrome/browser/policy/testing_policy_url_fetcher_factory.h" |
18 #include "chrome/browser/policy/user_policy_cache.h" | 18 #include "chrome/browser/policy/user_policy_cache.h" |
19 #include "chrome/common/pref_names.h" | 19 #include "chrome/common/pref_names.h" |
20 #include "chrome/test/testing_browser_process.h" | 20 #include "chrome/test/testing_browser_process.h" |
21 #include "chrome/test/testing_pref_service.h" | 21 #include "chrome/test/testing_pref_service.h" |
| 22 #include "content/browser/browser_thread.h" |
22 #include "content/common/url_fetcher.h" | 23 #include "content/common/url_fetcher.h" |
23 #include "policy/policy_constants.h" | 24 #include "policy/policy_constants.h" |
24 #include "testing/gmock/include/gmock/gmock.h" | 25 #include "testing/gmock/include/gmock/gmock.h" |
25 #include "testing/gtest/include/gtest/gtest.h" | 26 #include "testing/gtest/include/gtest/gtest.h" |
26 | 27 |
27 namespace policy { | 28 namespace policy { |
28 | 29 |
29 using ::testing::_; | 30 using ::testing::_; |
30 using ::testing::AtLeast; | 31 using ::testing::AtLeast; |
31 using ::testing::AtMost; | 32 using ::testing::AtMost; |
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
236 | 237 |
237 void ExpectSuccessfulPolicy(int n, const std::string& homepage) { | 238 void ExpectSuccessfulPolicy(int n, const std::string& homepage) { |
238 EXPECT_CALL(*(factory_.get()), Intercept(kDMAuthHeader, "policy", _)) | 239 EXPECT_CALL(*(factory_.get()), Intercept(kDMAuthHeader, "policy", _)) |
239 .Times(n) | 240 .Times(n) |
240 .WillRepeatedly(CreateSuccessfulPolicyResponse(homepage)); | 241 .WillRepeatedly(CreateSuccessfulPolicyResponse(homepage)); |
241 } | 242 } |
242 | 243 |
243 private: | 244 private: |
244 // Verifies for a given policy that it is provided by the subsystem. | 245 // Verifies for a given policy that it is provided by the subsystem. |
245 void VerifyPolicy(enum ConfigurationPolicyType type, Value* expected) { | 246 void VerifyPolicy(enum ConfigurationPolicyType type, Value* expected) { |
246 MockConfigurationPolicyStore store; | 247 const PolicyMap* policy_map = cache_->policy( |
247 EXPECT_CALL(store, Apply(_, _)).Times(AtLeast(1)); | 248 CloudPolicyCacheBase::POLICY_LEVEL_MANDATORY); |
248 cache_->GetManagedPolicyProvider()->Provide(&store); | 249 ASSERT_TRUE(Value::Equals(expected, policy_map->Get(type))); |
249 ASSERT_TRUE(Value::Equals(expected, store.Get(type))); | |
250 } | 250 } |
251 | 251 |
252 // Verifies that the last recorded run of the subsystem did not issue | 252 // Verifies that the last recorded run of the subsystem did not issue |
253 // too frequent requests: | 253 // too frequent requests: |
254 // - no more than 10 requests in the first 10 minutes | 254 // - no more than 10 requests in the first 10 minutes |
255 // - no more then 12 requests per hour in the next 10 hours | 255 // - no more then 12 requests per hour in the next 10 hours |
256 // TODO(gfeher): Thighten these conditions further. This will require | 256 // TODO(gfeher): Thighten these conditions further. This will require |
257 // fine-tuning of the subsystem. See: http://crosbug.com/16637 | 257 // fine-tuning of the subsystem. See: http://crosbug.com/16637 |
258 void VerifyServerLoad() { | 258 void VerifyServerLoad() { |
259 std::vector<int64> events; | 259 std::vector<int64> events; |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
436 ExecuteTest(); | 436 ExecuteTest(); |
437 VerifyTest("http://www.youtube.com"); | 437 VerifyTest("http://www.youtube.com"); |
438 } | 438 } |
439 | 439 |
440 INSTANTIATE_TEST_CASE_P( | 440 INSTANTIATE_TEST_CASE_P( |
441 CloudPolicySubsystemPolicyReregisterTestInstance, | 441 CloudPolicySubsystemPolicyReregisterTestInstance, |
442 CloudPolicySubsystemPolicyReregisterTest, | 442 CloudPolicySubsystemPolicyReregisterTest, |
443 testing::Values(401, 403, 410)); | 443 testing::Values(401, 403, 410)); |
444 | 444 |
445 } // policy | 445 } // policy |
OLD | NEW |