| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
| 8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
| 9 #include "base/scoped_temp_dir.h" | 9 #include "base/scoped_temp_dir.h" |
| 10 #include "base/values.h" | 10 #include "base/values.h" |
| 11 #include "chrome/browser/browser_process.h" | 11 #include "chrome/browser/browser_process.h" |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 160 data_store_->set_user_name(kUsername); | 160 data_store_->set_user_name(kUsername); |
| 161 data_store_->SetGaiaToken(kAuthToken); | 161 data_store_->SetGaiaToken(kAuthToken); |
| 162 data_store_->SetDeviceToken("", true); | 162 data_store_->SetDeviceToken("", true); |
| 163 loop_.RunAllPending(); | 163 loop_.RunAllPending(); |
| 164 } | 164 } |
| 165 | 165 |
| 166 void VerifyTest(const std::string& homepage_location) { | 166 void VerifyTest(const std::string& homepage_location) { |
| 167 // Test conditions. | 167 // Test conditions. |
| 168 EXPECT_EQ(CloudPolicySubsystem::SUCCESS, cloud_policy_subsystem_->state()); | 168 EXPECT_EQ(CloudPolicySubsystem::SUCCESS, cloud_policy_subsystem_->state()); |
| 169 StringValue homepage_value(homepage_location); | 169 StringValue homepage_value(homepage_location); |
| 170 VerifyPolicy(kPolicyHomepageLocation, &homepage_value); | 170 VerifyPolicy(key::kHomepageLocation, &homepage_value); |
| 171 VerifyServerLoad(); | 171 VerifyServerLoad(); |
| 172 } | 172 } |
| 173 | 173 |
| 174 void VerifyState(CloudPolicySubsystem::PolicySubsystemState state) { | 174 void VerifyState(CloudPolicySubsystem::PolicySubsystemState state) { |
| 175 EXPECT_EQ(state, cloud_policy_subsystem_->state()); | 175 EXPECT_EQ(state, cloud_policy_subsystem_->state()); |
| 176 } | 176 } |
| 177 | 177 |
| 178 void ExpectSuccessfulRegistration() { | 178 void ExpectSuccessfulRegistration() { |
| 179 EXPECT_CALL(factory(), Intercept(kGaiaAuthHeader, "register", _, _)) | 179 EXPECT_CALL(factory(), Intercept(kGaiaAuthHeader, "register", _, _)) |
| 180 .WillOnce(CreateSuccessfulRegisterResponse(kDMToken)); | 180 .WillOnce(CreateSuccessfulRegisterResponse(kDMToken)); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 197 EXPECT_CALL(factory(), Intercept(kDMAuthHeader, "policy", _, _)) | 197 EXPECT_CALL(factory(), Intercept(kDMAuthHeader, "policy", _, _)) |
| 198 .Times(n) | 198 .Times(n) |
| 199 .WillRepeatedly(CreateSuccessfulPolicyResponse(homepage, false, false)); | 199 .WillRepeatedly(CreateSuccessfulPolicyResponse(homepage, false, false)); |
| 200 } | 200 } |
| 201 | 201 |
| 202 TestingPolicyURLFetcherFactory& factory() { return *factory_; } | 202 TestingPolicyURLFetcherFactory& factory() { return *factory_; } |
| 203 CloudPolicyDataStore* data_store() { return data_store_.get(); } | 203 CloudPolicyDataStore* data_store() { return data_store_.get(); } |
| 204 | 204 |
| 205 private: | 205 private: |
| 206 // Verifies for a given policy that it is provided by the subsystem. | 206 // Verifies for a given policy that it is provided by the subsystem. |
| 207 void VerifyPolicy(enum ConfigurationPolicyType type, Value* expected) { | 207 void VerifyPolicy(const char* policy_name, Value* expected) { |
| 208 const PolicyMap* policy_map = cache_->policy( | 208 const PolicyMap* policy_map = cache_->policy(); |
| 209 CloudPolicyCacheBase::POLICY_LEVEL_MANDATORY); | 209 ASSERT_TRUE(Value::Equals(expected, policy_map->GetValue(policy_name))); |
| 210 ASSERT_TRUE(Value::Equals(expected, policy_map->Get(type))); | |
| 211 } | 210 } |
| 212 | 211 |
| 213 // Verifies that the last recorded run of the subsystem did not issue | 212 // Verifies that the last recorded run of the subsystem did not issue |
| 214 // too frequent requests: | 213 // too frequent requests: |
| 215 // - no more than 10 requests in the first 10 minutes | 214 // - no more than 10 requests in the first 10 minutes |
| 216 // - no more then 12 requests per hour in the next 10 hours | 215 // - no more then 12 requests per hour in the next 10 hours |
| 217 // TODO(gfeher): Thighten these conditions further. This will require | 216 // TODO(gfeher): Thighten these conditions further. This will require |
| 218 // fine-tuning of the subsystem. See: http://crosbug.com/16637 | 217 // fine-tuning of the subsystem. See: http://crosbug.com/16637 |
| 219 void VerifyServerLoad() { | 218 void VerifyServerLoad() { |
| 220 std::vector<int64> events; | 219 std::vector<int64> events; |
| (...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 452 TEST_F(CloudPolicySubsystemSerialNumberRecoveryTest, SerialRequested) { | 451 TEST_F(CloudPolicySubsystemSerialNumberRecoveryTest, SerialRequested) { |
| 453 InSequence s; | 452 InSequence s; |
| 454 ExpectSuccessfulRegistration(); | 453 ExpectSuccessfulRegistration(); |
| 455 ExpectPolicyRequest("", true, true); | 454 ExpectPolicyRequest("", true, true); |
| 456 ExpectPolicyRequest(kMachineId, false, false); | 455 ExpectPolicyRequest(kMachineId, false, false); |
| 457 ExpectPolicyRequest("", false, false); | 456 ExpectPolicyRequest("", false, false); |
| 458 ExecuteTest(); | 457 ExecuteTest(); |
| 459 } | 458 } |
| 460 | 459 |
| 461 } // policy | 460 } // policy |
| OLD | NEW |