OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "base/scoped_temp_dir.h" | |
8 #include "chrome/browser/net/gaia/token_service.h" | 7 #include "chrome/browser/net/gaia/token_service.h" |
9 #include "chrome/browser/password_manager/encryptor.h" | 8 #include "chrome/browser/password_manager/encryptor.h" |
10 #include "chrome/browser/webdata/web_data_service.h" | 9 #include "chrome/browser/webdata/web_data_service.h" |
11 #include "chrome/common/net/gaia/gaia_auth_consumer.h" | 10 #include "chrome/common/net/gaia/gaia_auth_consumer.h" |
12 #include "chrome/common/net/gaia/gaia_authenticator2_unittest.h" | 11 #include "chrome/common/net/gaia/gaia_authenticator2_unittest.h" |
13 #include "chrome/common/net/gaia/gaia_constants.h" | 12 #include "chrome/common/net/gaia/gaia_constants.h" |
14 #include "chrome/common/net/test_url_fetcher_factory.h" | 13 #include "chrome/common/net/test_url_fetcher_factory.h" |
15 #include "chrome/test/signaling_task.h" | 14 #include "chrome/test/signaling_task.h" |
16 #include "chrome/test/test_notification_tracker.h" | 15 #include "chrome/test/test_notification_tracker.h" |
17 #include "chrome/test/testing_profile.h" | 16 #include "chrome/test/testing_profile.h" |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 | 68 |
70 virtual void SetUp() { | 69 virtual void SetUp() { |
71 #if defined(OS_MACOSX) | 70 #if defined(OS_MACOSX) |
72 Encryptor::UseMockKeychain(true); | 71 Encryptor::UseMockKeychain(true); |
73 #endif | 72 #endif |
74 credentials_.sid = "sid"; | 73 credentials_.sid = "sid"; |
75 credentials_.lsid = "lsid"; | 74 credentials_.lsid = "lsid"; |
76 credentials_.token = "token"; | 75 credentials_.token = "token"; |
77 credentials_.data = "data"; | 76 credentials_.data = "data"; |
78 | 77 |
79 ASSERT_TRUE(temp_.CreateUniqueTempDir()); | |
80 ASSERT_TRUE(db_thread_.Start()); | 78 ASSERT_TRUE(db_thread_.Start()); |
81 | 79 |
82 // Testing profile responsible for deleting the temp dir. | 80 profile_.reset(new TestingProfile()); |
83 profile_.reset(new TestingProfile(temp_.Take())); | |
84 profile_->CreateWebDataService(false); | 81 profile_->CreateWebDataService(false); |
85 WaitForDBLoadCompletion(); | 82 WaitForDBLoadCompletion(); |
86 | 83 |
87 success_tracker_.ListenFor(NotificationType::TOKEN_AVAILABLE, | 84 success_tracker_.ListenFor(NotificationType::TOKEN_AVAILABLE, |
88 Source<TokenService>(&service_)); | 85 Source<TokenService>(&service_)); |
89 failure_tracker_.ListenFor(NotificationType::TOKEN_REQUEST_FAILED, | 86 failure_tracker_.ListenFor(NotificationType::TOKEN_REQUEST_FAILED, |
90 Source<TokenService>(&service_)); | 87 Source<TokenService>(&service_)); |
91 | 88 |
92 service_.Initialize("test", profile_.get()); | 89 service_.Initialize("test", profile_.get()); |
93 service_.UpdateCredentials(credentials_); | 90 service_.UpdateCredentials(credentials_); |
(...skipping 27 matching lines...) Expand all Loading... |
121 | 118 |
122 MessageLoopForUI message_loop_; | 119 MessageLoopForUI message_loop_; |
123 ChromeThread ui_thread_; // Mostly so DCHECKS pass. | 120 ChromeThread ui_thread_; // Mostly so DCHECKS pass. |
124 ChromeThread db_thread_; // WDS on here | 121 ChromeThread db_thread_; // WDS on here |
125 | 122 |
126 TokenService service_; | 123 TokenService service_; |
127 TokenAvailableTracker success_tracker_; | 124 TokenAvailableTracker success_tracker_; |
128 TokenFailedTracker failure_tracker_; | 125 TokenFailedTracker failure_tracker_; |
129 GaiaAuthConsumer::ClientLoginResult credentials_; | 126 GaiaAuthConsumer::ClientLoginResult credentials_; |
130 scoped_ptr<TestingProfile> profile_; | 127 scoped_ptr<TestingProfile> profile_; |
131 ScopedTempDir temp_; | |
132 }; | 128 }; |
133 | 129 |
134 TEST_F(TokenServiceTest, SanityCheck) { | 130 TEST_F(TokenServiceTest, SanityCheck) { |
135 EXPECT_TRUE(service_.HasLsid()); | 131 EXPECT_TRUE(service_.HasLsid()); |
136 EXPECT_EQ(service_.GetLsid(), "lsid"); | 132 EXPECT_EQ(service_.GetLsid(), "lsid"); |
137 EXPECT_FALSE(service_.HasTokenForService("nonexistant service")); | 133 EXPECT_FALSE(service_.HasTokenForService("nonexistant service")); |
138 } | 134 } |
139 | 135 |
140 TEST_F(TokenServiceTest, NoToken) { | 136 TEST_F(TokenServiceTest, NoToken) { |
141 EXPECT_FALSE(service_.HasTokenForService("nonexistant service")); | 137 EXPECT_FALSE(service_.HasTokenForService("nonexistant service")); |
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
365 // Reset it one more time so there's no surprises. | 361 // Reset it one more time so there's no surprises. |
366 service_.ResetCredentialsInMemory(); | 362 service_.ResetCredentialsInMemory(); |
367 success_tracker_.Reset(); | 363 success_tracker_.Reset(); |
368 | 364 |
369 service_.LoadTokensFromDB(); | 365 service_.LoadTokensFromDB(); |
370 WaitForDBLoadCompletion(); | 366 WaitForDBLoadCompletion(); |
371 | 367 |
372 EXPECT_EQ(1U, success_tracker_.size()); | 368 EXPECT_EQ(1U, success_tracker_.size()); |
373 EXPECT_TRUE(service_.HasTokenForService(GaiaConstants::kSyncService)); | 369 EXPECT_TRUE(service_.HasTokenForService(GaiaConstants::kSyncService)); |
374 } | 370 } |
OLD | NEW |