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 "base/threading/sequenced_worker_pool.h" | 10 #include "base/threading/sequenced_worker_pool.h" |
(...skipping 23 matching lines...) Expand all Loading... |
34 | 34 |
35 static const int kOAuthTokenServiceUrlFetcherId = 0; | 35 static const int kOAuthTokenServiceUrlFetcherId = 0; |
36 static const int kValidatorUrlFetcherId = gaia::GaiaOAuthClient::kUrlFetcherId; | 36 static const int kValidatorUrlFetcherId = gaia::GaiaOAuthClient::kUrlFetcherId; |
37 | 37 |
38 class DeviceOAuth2TokenServiceTest : public testing::Test { | 38 class DeviceOAuth2TokenServiceTest : public testing::Test { |
39 public: | 39 public: |
40 DeviceOAuth2TokenServiceTest() | 40 DeviceOAuth2TokenServiceTest() |
41 : scoped_testing_local_state_(TestingBrowserProcess::GetGlobal()), | 41 : scoped_testing_local_state_(TestingBrowserProcess::GetGlobal()), |
42 request_context_getter_(new net::TestURLRequestContextGetter( | 42 request_context_getter_(new net::TestURLRequestContextGetter( |
43 message_loop_.message_loop_proxy())) {} | 43 message_loop_.message_loop_proxy())) {} |
44 virtual ~DeviceOAuth2TokenServiceTest() {} | 44 ~DeviceOAuth2TokenServiceTest() override {} |
45 | 45 |
46 // Most tests just want a noop crypto impl with a dummy refresh token value in | 46 // Most tests just want a noop crypto impl with a dummy refresh token value in |
47 // Local State (if the value is an empty string, it will be ignored). | 47 // Local State (if the value is an empty string, it will be ignored). |
48 void SetUpDefaultValues() { | 48 void SetUpDefaultValues() { |
49 SetDeviceRefreshTokenInLocalState("device_refresh_token_4_test"); | 49 SetDeviceRefreshTokenInLocalState("device_refresh_token_4_test"); |
50 SetRobotAccountId("service_acct@g.com"); | 50 SetRobotAccountId("service_acct@g.com"); |
51 CreateService(); | 51 CreateService(); |
52 AssertConsumerTokensAndErrors(0, 0); | 52 AssertConsumerTokensAndErrors(0, 0); |
53 | 53 |
54 base::RunLoop().RunUntilIdle(); | 54 base::RunLoop().RunUntilIdle(); |
(...skipping 12 matching lines...) Expand all Loading... |
67 DeviceSettingsService::Get()->Load(); | 67 DeviceSettingsService::Get()->Load(); |
68 device_settings_test_helper_.Flush(); | 68 device_settings_test_helper_.Flush(); |
69 } | 69 } |
70 | 70 |
71 scoped_ptr<OAuth2TokenService::Request> StartTokenRequest() { | 71 scoped_ptr<OAuth2TokenService::Request> StartTokenRequest() { |
72 return oauth2_service_->StartRequest(oauth2_service_->GetRobotAccountId(), | 72 return oauth2_service_->StartRequest(oauth2_service_->GetRobotAccountId(), |
73 std::set<std::string>(), | 73 std::set<std::string>(), |
74 &consumer_); | 74 &consumer_); |
75 } | 75 } |
76 | 76 |
77 virtual void SetUp() override { | 77 void SetUp() override { |
78 fake_cryptohome_client_ = new FakeCryptohomeClient; | 78 fake_cryptohome_client_ = new FakeCryptohomeClient; |
79 fake_cryptohome_client_->SetServiceIsAvailable(true); | 79 fake_cryptohome_client_->SetServiceIsAvailable(true); |
80 fake_cryptohome_client_->set_system_salt( | 80 fake_cryptohome_client_->set_system_salt( |
81 FakeCryptohomeClient::GetStubSystemSalt()); | 81 FakeCryptohomeClient::GetStubSystemSalt()); |
82 chromeos::DBusThreadManager::GetSetterForTesting()->SetCryptohomeClient( | 82 chromeos::DBusThreadManager::GetSetterForTesting()->SetCryptohomeClient( |
83 scoped_ptr<CryptohomeClient>(fake_cryptohome_client_)); | 83 scoped_ptr<CryptohomeClient>(fake_cryptohome_client_)); |
84 | 84 |
85 SystemSaltGetter::Initialize(); | 85 SystemSaltGetter::Initialize(); |
86 | 86 |
87 DeviceSettingsService::Initialize(); | 87 DeviceSettingsService::Initialize(); |
88 scoped_refptr<ownership::MockOwnerKeyUtil> owner_key_util_( | 88 scoped_refptr<ownership::MockOwnerKeyUtil> owner_key_util_( |
89 new ownership::MockOwnerKeyUtil()); | 89 new ownership::MockOwnerKeyUtil()); |
90 owner_key_util_->SetPublicKeyFromPrivateKey( | 90 owner_key_util_->SetPublicKeyFromPrivateKey( |
91 *device_policy_.GetSigningKey()); | 91 *device_policy_.GetSigningKey()); |
92 DeviceSettingsService::Get()->SetSessionManager( | 92 DeviceSettingsService::Get()->SetSessionManager( |
93 &device_settings_test_helper_, owner_key_util_); | 93 &device_settings_test_helper_, owner_key_util_); |
94 | 94 |
95 CrosSettings::Initialize(); | 95 CrosSettings::Initialize(); |
96 } | 96 } |
97 | 97 |
98 virtual void TearDown() override { | 98 void TearDown() override { |
99 CrosSettings::Shutdown(); | 99 CrosSettings::Shutdown(); |
100 TestingBrowserProcess::GetGlobal()->SetBrowserPolicyConnector(NULL); | 100 TestingBrowserProcess::GetGlobal()->SetBrowserPolicyConnector(NULL); |
101 content::BrowserThread::GetBlockingPool()->FlushForTesting(); | 101 content::BrowserThread::GetBlockingPool()->FlushForTesting(); |
102 DeviceSettingsService::Get()->UnsetSessionManager(); | 102 DeviceSettingsService::Get()->UnsetSessionManager(); |
103 DeviceSettingsService::Shutdown(); | 103 DeviceSettingsService::Shutdown(); |
104 SystemSaltGetter::Shutdown(); | 104 SystemSaltGetter::Shutdown(); |
105 DBusThreadManager::Shutdown(); | 105 DBusThreadManager::Shutdown(); |
106 base::RunLoop().RunUntilIdle(); | 106 base::RunLoop().RunUntilIdle(); |
107 } | 107 } |
108 | 108 |
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
424 | 424 |
425 AssertConsumerTokensAndErrors(0, 1); | 425 AssertConsumerTokensAndErrors(0, 1); |
426 | 426 |
427 // Retry should succeed. | 427 // Retry should succeed. |
428 request = StartTokenRequest(); | 428 request = StartTokenRequest(); |
429 PerformURLFetches(); | 429 PerformURLFetches(); |
430 AssertConsumerTokensAndErrors(1, 1); | 430 AssertConsumerTokensAndErrors(1, 1); |
431 } | 431 } |
432 | 432 |
433 } // namespace chromeos | 433 } // namespace chromeos |
OLD | NEW |