| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 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 <string> | 5 #include <string> |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
| 9 #include "base/prefs/pref_registry_simple.h" | 9 #include "base/prefs/pref_registry_simple.h" |
| 10 #include "base/prefs/testing_pref_service.h" | 10 #include "base/prefs/testing_pref_service.h" |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 ui_thread_(content::BrowserThread::UI, &message_loop_), | 123 ui_thread_(content::BrowserThread::UI, &message_loop_), |
| 124 certificate_success_(true), | 124 certificate_success_(true), |
| 125 sign_challenge_success_(true), | 125 sign_challenge_success_(true), |
| 126 result_(PlatformVerificationFlow::INTERNAL_ERROR) {} | 126 result_(PlatformVerificationFlow::INTERNAL_ERROR) {} |
| 127 | 127 |
| 128 void SetUp() { | 128 void SetUp() { |
| 129 // Configure a user for the mock user manager. | 129 // Configure a user for the mock user manager. |
| 130 mock_user_manager_.SetActiveUser(kTestEmail); | 130 mock_user_manager_.SetActiveUser(kTestEmail); |
| 131 | 131 |
| 132 // Create a verifier for tests to call. | 132 // Create a verifier for tests to call. |
| 133 verifier_.reset(new PlatformVerificationFlow(&mock_attestation_flow_, | 133 verifier_ = new PlatformVerificationFlow(&mock_attestation_flow_, |
| 134 &mock_async_caller_, | 134 &mock_async_caller_, |
| 135 &fake_cryptohome_client_, | 135 &fake_cryptohome_client_, |
| 136 &mock_user_manager_, | 136 &mock_user_manager_, |
| 137 &fake_delegate_)); | 137 &fake_delegate_); |
| 138 | 138 |
| 139 // Create callbacks for tests to use with verifier_. | 139 // Create callbacks for tests to use with verifier_. |
| 140 callback_ = base::Bind(&PlatformVerificationFlowTest::FakeChallengeCallback, | 140 callback_ = base::Bind(&PlatformVerificationFlowTest::FakeChallengeCallback, |
| 141 base::Unretained(this)); | 141 base::Unretained(this)); |
| 142 | 142 |
| 143 // Configure the test pref service. | 143 // Configure the test pref service. |
| 144 pref_service_.registry()->RegisterBooleanPref(prefs::kEnableDRM, true); | 144 pref_service_.registry()->RegisterBooleanPref(prefs::kEnableDRM, true); |
| 145 pref_service_.registry()->RegisterBooleanPref(prefs::kRAConsentFirstTime, | 145 pref_service_.registry()->RegisterBooleanPref(prefs::kRAConsentFirstTime, |
| 146 true); | 146 true); |
| 147 pref_service_.registry()->RegisterBooleanPref(prefs::kRAConsentAlways, | 147 pref_service_.registry()->RegisterBooleanPref(prefs::kRAConsentAlways, |
| 148 false); | 148 false); |
| 149 pref_service_.registry()->RegisterDictionaryPref(prefs::kRAConsentDomains); | 149 pref_service_.registry()->RegisterDictionaryPref(prefs::kRAConsentDomains); |
| 150 verifier_->set_testing_prefs(&pref_service_); | 150 verifier_->set_testing_prefs(&pref_service_); |
| 151 | 151 |
| 152 // Configure the global cros_settings. | 152 // Configure the global cros_settings. |
| 153 CrosSettings* cros_settings = CrosSettings::Get(); | 153 CrosSettings* cros_settings = CrosSettings::Get(); |
| 154 device_settings_provider_ = | 154 device_settings_provider_ = |
| 155 cros_settings->GetProvider(kAttestationForContentProtectionEnabled); | 155 cros_settings->GetProvider(kAttestationForContentProtectionEnabled); |
| 156 cros_settings->RemoveSettingsProvider(device_settings_provider_); | 156 cros_settings->RemoveSettingsProvider(device_settings_provider_); |
| 157 cros_settings->AddSettingsProvider(&stub_settings_provider_); | 157 cros_settings->AddSettingsProvider(&stub_settings_provider_); |
| 158 cros_settings->SetBoolean(kAttestationForContentProtectionEnabled, true); | 158 cros_settings->SetBoolean(kAttestationForContentProtectionEnabled, true); |
| 159 | 159 |
| 160 // Configure a test URL to shortcut the dependency on WebContents. | 160 // Configure a test URL to shortcut the dependency on WebContents. |
| 161 verifier_->set_testing_url(GURL(kTestURL)); | 161 verifier_->set_testing_url(GURL(kTestURL)); |
| 162 } | 162 } |
| 163 | 163 |
| 164 void TearDown() { | 164 void TearDown() { |
| 165 verifier_.reset(); | |
| 166 // Restore the real DeviceSettingsProvider. | 165 // Restore the real DeviceSettingsProvider. |
| 167 CrosSettings* cros_settings = CrosSettings::Get(); | 166 CrosSettings* cros_settings = CrosSettings::Get(); |
| 168 cros_settings->RemoveSettingsProvider(&stub_settings_provider_); | 167 cros_settings->RemoveSettingsProvider(&stub_settings_provider_); |
| 169 cros_settings->AddSettingsProvider(device_settings_provider_); | 168 cros_settings->AddSettingsProvider(device_settings_provider_); |
| 170 } | 169 } |
| 171 | 170 |
| 172 void ExpectAttestationFlow() { | 171 void ExpectAttestationFlow() { |
| 173 // When consent is not given or the feature is disabled, it is important | 172 // When consent is not given or the feature is disabled, it is important |
| 174 // that there are no calls to the attestation service. Thus, a test must | 173 // that there are no calls to the attestation service. Thus, a test must |
| 175 // explicitly expect these calls or the mocks will fail the test. | 174 // explicitly expect these calls or the mocks will fail the test. |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 234 StrictMock<MockAttestationFlow> mock_attestation_flow_; | 233 StrictMock<MockAttestationFlow> mock_attestation_flow_; |
| 235 cryptohome::MockAsyncMethodCaller mock_async_caller_; | 234 cryptohome::MockAsyncMethodCaller mock_async_caller_; |
| 236 CustomFakeCryptohomeClient fake_cryptohome_client_; | 235 CustomFakeCryptohomeClient fake_cryptohome_client_; |
| 237 MockUserManager mock_user_manager_; | 236 MockUserManager mock_user_manager_; |
| 238 FakeDelegate fake_delegate_; | 237 FakeDelegate fake_delegate_; |
| 239 TestingPrefServiceSimple pref_service_; | 238 TestingPrefServiceSimple pref_service_; |
| 240 CrosSettingsProvider* device_settings_provider_; | 239 CrosSettingsProvider* device_settings_provider_; |
| 241 StubCrosSettingsProvider stub_settings_provider_; | 240 StubCrosSettingsProvider stub_settings_provider_; |
| 242 ScopedTestDeviceSettingsService test_device_settings_service_; | 241 ScopedTestDeviceSettingsService test_device_settings_service_; |
| 243 ScopedTestCrosSettings test_cros_settings_; | 242 ScopedTestCrosSettings test_cros_settings_; |
| 244 scoped_ptr<PlatformVerificationFlow> verifier_; | 243 scoped_refptr<PlatformVerificationFlow> verifier_; |
| 245 | 244 |
| 246 // Controls result of FakeGetCertificate. | 245 // Controls result of FakeGetCertificate. |
| 247 bool certificate_success_; | 246 bool certificate_success_; |
| 248 | 247 |
| 249 // Controls result of FakeSignChallenge. | 248 // Controls result of FakeSignChallenge. |
| 250 bool sign_challenge_success_; | 249 bool sign_challenge_success_; |
| 251 | 250 |
| 252 // Callback functions and data. | 251 // Callback functions and data. |
| 253 PlatformVerificationFlow::ChallengeCallback callback_; | 252 PlatformVerificationFlow::ChallengeCallback callback_; |
| 254 PlatformVerificationFlow::Result result_; | 253 PlatformVerificationFlow::Result result_; |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 371 | 370 |
| 372 TEST_F(PlatformVerificationFlowTest, ConsentNoResponse) { | 371 TEST_F(PlatformVerificationFlowTest, ConsentNoResponse) { |
| 373 fake_delegate_.set_response(PlatformVerificationFlow::CONSENT_RESPONSE_NONE); | 372 fake_delegate_.set_response(PlatformVerificationFlow::CONSENT_RESPONSE_NONE); |
| 374 pref_service_.SetUserPref(prefs::kRAConsentAlways, | 373 pref_service_.SetUserPref(prefs::kRAConsentAlways, |
| 375 new base::FundamentalValue(true)); | 374 new base::FundamentalValue(true)); |
| 376 verifier_->ChallengePlatformKey(NULL, kTestID, kTestChallenge, callback_); | 375 verifier_->ChallengePlatformKey(NULL, kTestID, kTestChallenge, callback_); |
| 377 base::RunLoop().RunUntilIdle(); | 376 base::RunLoop().RunUntilIdle(); |
| 378 EXPECT_EQ(PlatformVerificationFlow::USER_REJECTED, result_); | 377 EXPECT_EQ(PlatformVerificationFlow::USER_REJECTED, result_); |
| 379 } | 378 } |
| 380 | 379 |
| 380 TEST_F(PlatformVerificationFlowTest, Timeout) { |
| 381 verifier_->set_timeout_delay(0); |
| 382 ExpectAttestationFlow(); |
| 383 verifier_->ChallengePlatformKey(NULL, kTestID, kTestChallenge, callback_); |
| 384 base::RunLoop().RunUntilIdle(); |
| 385 EXPECT_EQ(PlatformVerificationFlow::TIMEOUT, result_); |
| 386 } |
| 387 |
| 381 } // namespace attestation | 388 } // namespace attestation |
| 382 } // namespace chromeos | 389 } // namespace chromeos |
| OLD | NEW |