OLD | NEW |
1 // Copyright (c) 2012 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 // This file defines a unit test for the profile's token service. | 5 // This file defines a unit test for the profile's token service. |
6 | 6 |
7 #include "chrome/browser/signin/token_service_unittest.h" | 7 #include "chrome/browser/signin/token_service_unittest.h" |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
12 #include "base/message_loop.h" | 12 #include "base/message_loop.h" |
13 #include "base/synchronization/waitable_event.h" | 13 #include "base/synchronization/waitable_event.h" |
14 #include "chrome/browser/password_manager/encryptor.h" | 14 #include "chrome/browser/password_manager/encryptor.h" |
15 #include "chrome/browser/signin/token_service_factory.h" | 15 #include "chrome/browser/signin/token_service_factory.h" |
16 #include "chrome/browser/webdata/web_data_service_factory.h" | 16 #include "chrome/browser/webdata/web_data_service_factory.h" |
17 #include "chrome/common/chrome_notification_types.h" | 17 #include "chrome/common/chrome_notification_types.h" |
18 #include "chrome/common/chrome_switches.h" | 18 #include "chrome/common/chrome_switches.h" |
| 19 #include "chrome/common/net/gaia/gaia_constants.h" |
19 #include "chrome/common/net/gaia/mock_url_fetcher_factory.h" | 20 #include "chrome/common/net/gaia/mock_url_fetcher_factory.h" |
20 #include "chrome/common/net/gaia/gaia_constants.h" | 21 #include "net/url_request/test_url_fetcher_factory.h" |
21 #include "content/public/test/test_url_fetcher_factory.h" | |
22 | 22 |
23 using content::BrowserThread; | 23 using content::BrowserThread; |
24 | 24 |
25 TokenAvailableTracker::TokenAvailableTracker() {} | 25 TokenAvailableTracker::TokenAvailableTracker() {} |
26 | 26 |
27 TokenAvailableTracker::~TokenAvailableTracker() {} | 27 TokenAvailableTracker::~TokenAvailableTracker() {} |
28 | 28 |
29 void TokenAvailableTracker::Observe( | 29 void TokenAvailableTracker::Observe( |
30 int type, | 30 int type, |
31 const content::NotificationSource& source, | 31 const content::NotificationSource& source, |
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
253 TEST_F(TokenServiceTest, OnTokenSuccess) { | 253 TEST_F(TokenServiceTest, OnTokenSuccess) { |
254 // Don't "start fetching", just go ahead and issue the callback. | 254 // Don't "start fetching", just go ahead and issue the callback. |
255 service_->OnIssueAuthTokenSuccess(GaiaConstants::kSyncService, "token"); | 255 service_->OnIssueAuthTokenSuccess(GaiaConstants::kSyncService, "token"); |
256 EXPECT_TRUE(service_->HasTokenForService(GaiaConstants::kSyncService)); | 256 EXPECT_TRUE(service_->HasTokenForService(GaiaConstants::kSyncService)); |
257 // Gaia returns the entire result as the token so while this is a shared | 257 // Gaia returns the entire result as the token so while this is a shared |
258 // result with ClientLogin, it doesn't matter, we should still get it back. | 258 // result with ClientLogin, it doesn't matter, we should still get it back. |
259 EXPECT_EQ(service_->GetTokenForService(GaiaConstants::kSyncService), "token"); | 259 EXPECT_EQ(service_->GetTokenForService(GaiaConstants::kSyncService), "token"); |
260 } | 260 } |
261 | 261 |
262 TEST_F(TokenServiceTest, Reset) { | 262 TEST_F(TokenServiceTest, Reset) { |
263 TestURLFetcherFactory factory; | 263 net::TestURLFetcherFactory factory; |
264 service_->StartFetchingTokens(); | 264 service_->StartFetchingTokens(); |
265 // You have to call delegates by hand with the test fetcher, | 265 // You have to call delegates by hand with the test fetcher, |
266 // Let's pretend only one returned. | 266 // Let's pretend only one returned. |
267 | 267 |
268 service_->OnIssueAuthTokenSuccess(GaiaConstants::kSyncService, "eraseme"); | 268 service_->OnIssueAuthTokenSuccess(GaiaConstants::kSyncService, "eraseme"); |
269 EXPECT_TRUE(service_->HasTokenForService(GaiaConstants::kSyncService)); | 269 EXPECT_TRUE(service_->HasTokenForService(GaiaConstants::kSyncService)); |
270 EXPECT_EQ(service_->GetTokenForService(GaiaConstants::kSyncService), | 270 EXPECT_EQ(service_->GetTokenForService(GaiaConstants::kSyncService), |
271 "eraseme"); | 271 "eraseme"); |
272 | 272 |
273 service_->ResetCredentialsInMemory(); | 273 service_->ResetCredentialsInMemory(); |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
421 | 421 |
422 *CommandLine::ForCurrentProcess() = original_cl; | 422 *CommandLine::ForCurrentProcess() = original_cl; |
423 } | 423 } |
424 }; | 424 }; |
425 | 425 |
426 TEST_F(TokenServiceCommandLineTest, TestValueOverride) { | 426 TEST_F(TokenServiceCommandLineTest, TestValueOverride) { |
427 EXPECT_TRUE(service_->HasTokenForService("my_service")); | 427 EXPECT_TRUE(service_->HasTokenForService("my_service")); |
428 EXPECT_EQ("my_value", service_->GetTokenForService("my_service")); | 428 EXPECT_EQ("my_value", service_->GetTokenForService("my_service")); |
429 } | 429 } |
430 #endif // ifndef NDEBUG | 430 #endif // ifndef NDEBUG |
OLD | NEW |