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 <algorithm> | 5 #include <algorithm> |
6 #include <string> | 6 #include <string> |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/location.h" | 9 #include "base/location.h" |
10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
214 EXPECT_CALL(helper, StartFetchingUbertoken()); | 214 EXPECT_CALL(helper, StartFetchingUbertoken()); |
215 EXPECT_CALL(helper, StartFetchingMergeSession()); | 215 EXPECT_CALL(helper, StartFetchingMergeSession()); |
216 EXPECT_CALL(observer, OnAddAccountToCookieCompleted("acc1@gmail.com", | 216 EXPECT_CALL(observer, OnAddAccountToCookieCompleted("acc1@gmail.com", |
217 no_error())); | 217 no_error())); |
218 | 218 |
219 helper.AddAccountToCookie("acc1@gmail.com"); | 219 helper.AddAccountToCookie("acc1@gmail.com"); |
220 SimulateMergeSessionFailure(&helper, canceled()); | 220 SimulateMergeSessionFailure(&helper, canceled()); |
221 DCHECK(helper.is_running()); | 221 DCHECK(helper.is_running()); |
222 // Transient error incurs a retry after 1 second. | 222 // Transient error incurs a retry after 1 second. |
223 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 223 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
224 FROM_HERE, base::MessageLoop::QuitClosure(), | 224 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure(), |
225 base::TimeDelta::FromMilliseconds(1100)); | 225 base::TimeDelta::FromMilliseconds(1100)); |
226 base::MessageLoop::current()->Run(); | 226 base::MessageLoop::current()->Run(); |
227 SimulateMergeSessionSuccess(&helper, "token"); | 227 SimulateMergeSessionSuccess(&helper, "token"); |
228 DCHECK(!helper.is_running()); | 228 DCHECK(!helper.is_running()); |
229 } | 229 } |
230 | 230 |
231 TEST_F(GaiaCookieManagerServiceTest, MergeSessionRetriedTwice) { | 231 TEST_F(GaiaCookieManagerServiceTest, MergeSessionRetriedTwice) { |
232 InstrumentedGaiaCookieManagerService helper(token_service(), signin_client()); | 232 InstrumentedGaiaCookieManagerService helper(token_service(), signin_client()); |
233 MockObserver observer(&helper); | 233 MockObserver observer(&helper); |
234 base::HistogramTester histograms; | 234 base::HistogramTester histograms; |
235 | 235 |
236 EXPECT_CALL(helper, StartFetchingUbertoken()); | 236 EXPECT_CALL(helper, StartFetchingUbertoken()); |
237 EXPECT_CALL(helper, StartFetchingMergeSession()).Times(2); | 237 EXPECT_CALL(helper, StartFetchingMergeSession()).Times(2); |
238 EXPECT_CALL(observer, OnAddAccountToCookieCompleted("acc1@gmail.com", | 238 EXPECT_CALL(observer, OnAddAccountToCookieCompleted("acc1@gmail.com", |
239 no_error())); | 239 no_error())); |
240 | 240 |
241 helper.AddAccountToCookie("acc1@gmail.com"); | 241 helper.AddAccountToCookie("acc1@gmail.com"); |
242 SimulateMergeSessionFailure(&helper, canceled()); | 242 SimulateMergeSessionFailure(&helper, canceled()); |
243 DCHECK(helper.is_running()); | 243 DCHECK(helper.is_running()); |
244 // Transient error incurs a retry after 1 second. | 244 // Transient error incurs a retry after 1 second. |
245 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 245 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
246 FROM_HERE, base::MessageLoop::QuitClosure(), | 246 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure(), |
247 base::TimeDelta::FromMilliseconds(1100)); | 247 base::TimeDelta::FromMilliseconds(1100)); |
248 base::MessageLoop::current()->Run(); | 248 base::MessageLoop::current()->Run(); |
249 SimulateMergeSessionFailure(&helper, canceled()); | 249 SimulateMergeSessionFailure(&helper, canceled()); |
250 DCHECK(helper.is_running()); | 250 DCHECK(helper.is_running()); |
251 // Next transient error incurs a retry after 3 seconds. | 251 // Next transient error incurs a retry after 3 seconds. |
252 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 252 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
253 FROM_HERE, base::MessageLoop::QuitClosure(), | 253 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure(), |
254 base::TimeDelta::FromMilliseconds(3100)); | 254 base::TimeDelta::FromMilliseconds(3100)); |
255 base::MessageLoop::current()->Run(); | 255 base::MessageLoop::current()->Run(); |
256 SimulateMergeSessionSuccess(&helper, "token"); | 256 SimulateMergeSessionSuccess(&helper, "token"); |
257 DCHECK(!helper.is_running()); | 257 DCHECK(!helper.is_running()); |
258 histograms.ExpectUniqueSample("OAuth2Login.MergeSessionRetry", | 258 histograms.ExpectUniqueSample("OAuth2Login.MergeSessionRetry", |
259 GoogleServiceAuthError::REQUEST_CANCELED, 2); | 259 GoogleServiceAuthError::REQUEST_CANCELED, 2); |
260 } | 260 } |
261 | 261 |
262 TEST_F(GaiaCookieManagerServiceTest, FailedUbertoken) { | 262 TEST_F(GaiaCookieManagerServiceTest, FailedUbertoken) { |
263 InstrumentedGaiaCookieManagerService helper(token_service(), signin_client()); | 263 InstrumentedGaiaCookieManagerService helper(token_service(), signin_client()); |
(...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
671 | 671 |
672 helper.external_cc_result_fetcher_for_testing()->Start(); | 672 helper.external_cc_result_fetcher_for_testing()->Start(); |
673 | 673 |
674 EXPECT_CALL(helper, StartFetchingUbertoken()); | 674 EXPECT_CALL(helper, StartFetchingUbertoken()); |
675 helper.AddAccountToCookie("acc2@gmail.com"); | 675 helper.AddAccountToCookie("acc2@gmail.com"); |
676 // There is already a ExternalCCResultFetch underway. This will trigger | 676 // There is already a ExternalCCResultFetch underway. This will trigger |
677 // StartFetchingMergeSession. | 677 // StartFetchingMergeSession. |
678 EXPECT_CALL(helper, StartFetchingMergeSession()); | 678 EXPECT_CALL(helper, StartFetchingMergeSession()); |
679 SimulateUbertokenSuccess(&helper, "token3"); | 679 SimulateUbertokenSuccess(&helper, "token3"); |
680 } | 680 } |
OLD | NEW |