OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
9 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
10 #include "chrome/browser/chromeos/login/auth/auth_attempt_state.h" | 10 #include "chrome/browser/chromeos/login/auth/auth_attempt_state.h" |
(...skipping 15 matching lines...) Expand all Loading... |
26 using ::testing::Invoke; | 26 using ::testing::Invoke; |
27 using ::testing::Return; | 27 using ::testing::Return; |
28 using ::testing::_; | 28 using ::testing::_; |
29 using content::BrowserThread; | 29 using content::BrowserThread; |
30 | 30 |
31 namespace chromeos { | 31 namespace chromeos { |
32 | 32 |
33 class OnlineAttemptTest : public testing::Test { | 33 class OnlineAttemptTest : public testing::Test { |
34 public: | 34 public: |
35 OnlineAttemptTest() | 35 OnlineAttemptTest() |
36 : state_(UserContext(), "", "", User::USER_TYPE_REGULAR, false), | 36 : state_(UserContext(), false), |
37 attempt_(new OnlineAttempt(&state_, &resolver_)) { | 37 attempt_(new OnlineAttempt(&state_, &resolver_)) { |
38 } | 38 } |
39 | 39 |
40 void RunFailureTest(const GoogleServiceAuthError& error) { | 40 void RunFailureTest(const GoogleServiceAuthError& error) { |
41 EXPECT_CALL(resolver_, Resolve()) | 41 EXPECT_CALL(resolver_, Resolve()) |
42 .Times(1) | 42 .Times(1) |
43 .RetiresOnSaturation(); | 43 .RetiresOnSaturation(); |
44 | 44 |
45 BrowserThread::PostTask( | 45 BrowserThread::PostTask( |
46 BrowserThread::UI, FROM_HERE, | 46 BrowserThread::UI, FROM_HERE, |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
134 TestingProfile profile; | 134 TestingProfile profile; |
135 | 135 |
136 base::RunLoop run_loop; | 136 base::RunLoop run_loop; |
137 EXPECT_CALL(resolver_, Resolve()) | 137 EXPECT_CALL(resolver_, Resolve()) |
138 .WillOnce(Invoke(&run_loop, &base::RunLoop::Quit)) | 138 .WillOnce(Invoke(&run_loop, &base::RunLoop::Quit)) |
139 .RetiresOnSaturation(); | 139 .RetiresOnSaturation(); |
140 | 140 |
141 // This is how we inject fake URLFetcher objects, with a factory. | 141 // This is how we inject fake URLFetcher objects, with a factory. |
142 MockURLFetcherFactory<HostedFetcher> factory; | 142 MockURLFetcherFactory<HostedFetcher> factory; |
143 | 143 |
144 TestAttemptState local_state(UserContext(), "", "", | 144 TestAttemptState local_state(UserContext(), true); |
145 User::USER_TYPE_REGULAR, true); | |
146 attempt_.reset(new OnlineAttempt(&local_state, &resolver_)); | 145 attempt_.reset(new OnlineAttempt(&local_state, &resolver_)); |
147 attempt_->Initiate(&profile); | 146 attempt_->Initiate(&profile); |
148 | 147 |
149 run_loop.Run(); | 148 run_loop.Run(); |
150 | 149 |
151 EXPECT_EQ(error, local_state.online_outcome()); | 150 EXPECT_EQ(error, local_state.online_outcome()); |
152 EXPECT_EQ(LoginFailure::NETWORK_AUTH_FAILED, | 151 EXPECT_EQ(LoginFailure::NETWORK_AUTH_FAILED, |
153 local_state.online_outcome().reason()); | 152 local_state.online_outcome().reason()); |
154 } | 153 } |
155 | 154 |
156 TEST_F(OnlineAttemptTest, FullLogin) { | 155 TEST_F(OnlineAttemptTest, FullLogin) { |
157 TestingProfile profile; | 156 TestingProfile profile; |
158 | 157 |
159 base::RunLoop run_loop; | 158 base::RunLoop run_loop; |
160 EXPECT_CALL(resolver_, Resolve()) | 159 EXPECT_CALL(resolver_, Resolve()) |
161 .WillOnce(Invoke(&run_loop, &base::RunLoop::Quit)) | 160 .WillOnce(Invoke(&run_loop, &base::RunLoop::Quit)) |
162 .RetiresOnSaturation(); | 161 .RetiresOnSaturation(); |
163 | 162 |
164 // This is how we inject fake URLFetcher objects, with a factory. | 163 // This is how we inject fake URLFetcher objects, with a factory. |
165 MockURLFetcherFactory<SuccessFetcher> factory; | 164 MockURLFetcherFactory<SuccessFetcher> factory; |
166 | 165 |
167 TestAttemptState local_state(UserContext(), "", "", | 166 TestAttemptState local_state(UserContext(), true); |
168 User::USER_TYPE_REGULAR, true); | |
169 attempt_.reset(new OnlineAttempt(&local_state, &resolver_)); | 167 attempt_.reset(new OnlineAttempt(&local_state, &resolver_)); |
170 attempt_->Initiate(&profile); | 168 attempt_->Initiate(&profile); |
171 | 169 |
172 run_loop.Run(); | 170 run_loop.Run(); |
173 | 171 |
174 EXPECT_EQ(LoginFailure::LoginFailureNone(), local_state.online_outcome()); | 172 EXPECT_EQ(LoginFailure::LoginFailureNone(), local_state.online_outcome()); |
175 } | 173 } |
176 | 174 |
177 TEST_F(OnlineAttemptTest, LoginNetFailure) { | 175 TEST_F(OnlineAttemptTest, LoginNetFailure) { |
178 RunFailureTest( | 176 RunFailureTest( |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
219 attempt_->weak_factory_.GetWeakPtr(), | 217 attempt_->weak_factory_.GetWeakPtr(), |
220 error)); | 218 error)); |
221 | 219 |
222 // Force UI thread to finish tasks so I can verify |state_|. | 220 // Force UI thread to finish tasks so I can verify |state_|. |
223 base::RunLoop().RunUntilIdle(); | 221 base::RunLoop().RunUntilIdle(); |
224 EXPECT_TRUE(GoogleServiceAuthError::AuthErrorNone() == | 222 EXPECT_TRUE(GoogleServiceAuthError::AuthErrorNone() == |
225 state_.online_outcome().error()); | 223 state_.online_outcome().error()); |
226 } | 224 } |
227 | 225 |
228 } // namespace chromeos | 226 } // namespace chromeos |
OLD | NEW |