| 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 "chrome/browser/chromeos/settings/device_oauth2_token_service.h" | 5 #include "chrome/browser/chromeos/settings/device_oauth2_token_service.h" |
| 6 | 6 |
| 7 #include "base/message_loop/message_loop.h" | 7 #include "base/message_loop/message_loop.h" |
| 8 #include "base/prefs/testing_pref_service.h" | 8 #include "base/prefs/testing_pref_service.h" |
| 9 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
| 10 #include "chrome/browser/chromeos/policy/device_policy_builder.h" | 10 #include "chrome/browser/chromeos/policy/device_policy_builder.h" |
| 11 #include "chrome/browser/chromeos/settings/cros_settings.h" | 11 #include "chrome/browser/chromeos/settings/cros_settings.h" |
| 12 #include "chrome/browser/chromeos/settings/device_settings_service.h" | 12 #include "chrome/browser/chromeos/settings/device_settings_service.h" |
| 13 #include "chrome/browser/chromeos/settings/device_settings_test_helper.h" | 13 #include "chrome/browser/chromeos/settings/device_settings_test_helper.h" |
| 14 #include "chrome/browser/chromeos/settings/token_encryptor.h" | 14 #include "chrome/browser/chromeos/settings/token_encryptor.h" |
| 15 #include "chrome/common/pref_names.h" | 15 #include "chrome/common/pref_names.h" |
| 16 #include "chrome/test/base/scoped_testing_local_state.h" | 16 #include "chrome/test/base/scoped_testing_local_state.h" |
| 17 #include "chrome/test/base/testing_browser_process.h" | 17 #include "chrome/test/base/testing_browser_process.h" |
| 18 #include "chromeos/cryptohome/system_salt_getter.h" | 18 #include "chromeos/cryptohome/system_salt_getter.h" |
| 19 #include "chromeos/dbus/dbus_thread_manager.h" |
| 19 #include "chromeos/dbus/fake_cryptohome_client.h" | 20 #include "chromeos/dbus/fake_cryptohome_client.h" |
| 20 #include "chromeos/dbus/fake_dbus_thread_manager.h" | |
| 21 #include "content/public/browser/browser_thread.h" | 21 #include "content/public/browser/browser_thread.h" |
| 22 #include "content/public/test/test_browser_thread.h" | 22 #include "content/public/test/test_browser_thread.h" |
| 23 #include "google_apis/gaia/gaia_oauth_client.h" | 23 #include "google_apis/gaia/gaia_oauth_client.h" |
| 24 #include "google_apis/gaia/oauth2_token_service_test_util.h" | 24 #include "google_apis/gaia/oauth2_token_service_test_util.h" |
| 25 #include "net/http/http_status_code.h" | 25 #include "net/http/http_status_code.h" |
| 26 #include "net/url_request/test_url_fetcher_factory.h" | 26 #include "net/url_request/test_url_fetcher_factory.h" |
| 27 #include "net/url_request/url_fetcher_delegate.h" | 27 #include "net/url_request/url_fetcher_delegate.h" |
| 28 #include "net/url_request/url_request_test_util.h" | 28 #include "net/url_request/url_request_test_util.h" |
| 29 #include "testing/gtest/include/gtest/gtest.h" | 29 #include "testing/gtest/include/gtest/gtest.h" |
| 30 | 30 |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 device_settings_test_helper_.Flush(); | 66 device_settings_test_helper_.Flush(); |
| 67 } | 67 } |
| 68 | 68 |
| 69 scoped_ptr<OAuth2TokenService::Request> StartTokenRequest() { | 69 scoped_ptr<OAuth2TokenService::Request> StartTokenRequest() { |
| 70 return oauth2_service_->StartRequest(oauth2_service_->GetRobotAccountId(), | 70 return oauth2_service_->StartRequest(oauth2_service_->GetRobotAccountId(), |
| 71 std::set<std::string>(), | 71 std::set<std::string>(), |
| 72 &consumer_); | 72 &consumer_); |
| 73 } | 73 } |
| 74 | 74 |
| 75 virtual void SetUp() OVERRIDE { | 75 virtual void SetUp() OVERRIDE { |
| 76 scoped_ptr<FakeDBusThreadManager> fake_dbus_thread_manager( | |
| 77 new FakeDBusThreadManager); | |
| 78 fake_cryptohome_client_ = new FakeCryptohomeClient; | 76 fake_cryptohome_client_ = new FakeCryptohomeClient; |
| 79 fake_cryptohome_client_->SetServiceIsAvailable(true); | 77 fake_cryptohome_client_->SetServiceIsAvailable(true); |
| 80 fake_cryptohome_client_->set_system_salt( | 78 fake_cryptohome_client_->set_system_salt( |
| 81 FakeCryptohomeClient::GetStubSystemSalt()); | 79 FakeCryptohomeClient::GetStubSystemSalt()); |
| 82 fake_dbus_thread_manager->SetCryptohomeClient( | 80 chromeos::DBusThreadManager::InitializeForTesting()->SetCryptohomeClient( |
| 83 scoped_ptr<CryptohomeClient>(fake_cryptohome_client_)); | 81 scoped_ptr<CryptohomeClient>(fake_cryptohome_client_)); |
| 84 | 82 |
| 85 DBusThreadManager::InitializeForTesting(fake_dbus_thread_manager.release()); | |
| 86 | |
| 87 SystemSaltGetter::Initialize(); | 83 SystemSaltGetter::Initialize(); |
| 88 | 84 |
| 89 DeviceSettingsService::Initialize(); | 85 DeviceSettingsService::Initialize(); |
| 90 scoped_refptr<MockOwnerKeyUtil> owner_key_util_(new MockOwnerKeyUtil()); | 86 scoped_refptr<MockOwnerKeyUtil> owner_key_util_(new MockOwnerKeyUtil()); |
| 91 owner_key_util_->SetPublicKeyFromPrivateKey( | 87 owner_key_util_->SetPublicKeyFromPrivateKey( |
| 92 *device_policy_.GetSigningKey()); | 88 *device_policy_.GetSigningKey()); |
| 93 DeviceSettingsService::Get()->SetSessionManager( | 89 DeviceSettingsService::Get()->SetSessionManager( |
| 94 &device_settings_test_helper_, owner_key_util_); | 90 &device_settings_test_helper_, owner_key_util_); |
| 95 | 91 |
| 96 CrosSettings::Initialize(); | 92 CrosSettings::Initialize(); |
| (...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 424 | 420 |
| 425 AssertConsumerTokensAndErrors(0, 1); | 421 AssertConsumerTokensAndErrors(0, 1); |
| 426 | 422 |
| 427 // Retry should succeed. | 423 // Retry should succeed. |
| 428 request = StartTokenRequest(); | 424 request = StartTokenRequest(); |
| 429 PerformURLFetches(); | 425 PerformURLFetches(); |
| 430 AssertConsumerTokensAndErrors(1, 1); | 426 AssertConsumerTokensAndErrors(1, 1); |
| 431 } | 427 } |
| 432 | 428 |
| 433 } // namespace chromeos | 429 } // namespace chromeos |
| OLD | NEW |