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/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
10 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
11 #include "base/message_loop/message_loop.h" | 12 #include "base/single_thread_task_runner.h" |
12 #include "base/strings/stringprintf.h" | 13 #include "base/strings/stringprintf.h" |
13 #include "base/test/histogram_tester.h" | 14 #include "base/test/histogram_tester.h" |
| 15 #include "base/thread_task_runner_handle.h" |
14 #include "components/signin/core/browser/gaia_cookie_manager_service.h" | 16 #include "components/signin/core/browser/gaia_cookie_manager_service.h" |
15 #include "components/signin/core/browser/test_signin_client.h" | 17 #include "components/signin/core/browser/test_signin_client.h" |
16 #include "google_apis/gaia/fake_oauth2_token_service.h" | 18 #include "google_apis/gaia/fake_oauth2_token_service.h" |
17 #include "google_apis/gaia/gaia_constants.h" | 19 #include "google_apis/gaia/gaia_constants.h" |
18 #include "google_apis/gaia/gaia_urls.h" | 20 #include "google_apis/gaia/gaia_urls.h" |
19 #include "net/url_request/test_url_fetcher_factory.h" | 21 #include "net/url_request/test_url_fetcher_factory.h" |
20 #include "net/url_request/url_request_test_util.h" | 22 #include "net/url_request/url_request_test_util.h" |
21 #include "testing/gmock/include/gmock/gmock.h" | 23 #include "testing/gmock/include/gmock/gmock.h" |
22 #include "testing/gtest/include/gtest/gtest.h" | 24 #include "testing/gtest/include/gtest/gtest.h" |
23 | 25 |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
198 | 200 |
199 EXPECT_CALL(helper, StartFetchingUbertoken()); | 201 EXPECT_CALL(helper, StartFetchingUbertoken()); |
200 EXPECT_CALL(helper, StartFetchingMergeSession()); | 202 EXPECT_CALL(helper, StartFetchingMergeSession()); |
201 EXPECT_CALL(observer, OnAddAccountToCookieCompleted("acc1@gmail.com", | 203 EXPECT_CALL(observer, OnAddAccountToCookieCompleted("acc1@gmail.com", |
202 no_error())); | 204 no_error())); |
203 | 205 |
204 helper.AddAccountToCookie("acc1@gmail.com"); | 206 helper.AddAccountToCookie("acc1@gmail.com"); |
205 SimulateMergeSessionFailure(&helper, canceled()); | 207 SimulateMergeSessionFailure(&helper, canceled()); |
206 DCHECK(helper.is_running()); | 208 DCHECK(helper.is_running()); |
207 // Transient error incurs a retry after 1 second. | 209 // Transient error incurs a retry after 1 second. |
208 base::MessageLoop::current()->PostDelayedTask( | 210 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
209 FROM_HERE, | 211 FROM_HERE, base::MessageLoop::QuitClosure(), |
210 base::MessageLoop::QuitClosure(), | |
211 base::TimeDelta::FromMilliseconds(1100)); | 212 base::TimeDelta::FromMilliseconds(1100)); |
212 base::MessageLoop::current()->Run(); | 213 base::MessageLoop::current()->Run(); |
213 SimulateMergeSessionSuccess(&helper, "token"); | 214 SimulateMergeSessionSuccess(&helper, "token"); |
214 DCHECK(!helper.is_running()); | 215 DCHECK(!helper.is_running()); |
215 } | 216 } |
216 | 217 |
217 TEST_F(GaiaCookieManagerServiceTest, MergeSessionRetriedTwice) { | 218 TEST_F(GaiaCookieManagerServiceTest, MergeSessionRetriedTwice) { |
218 InstrumentedGaiaCookieManagerService helper(token_service(), signin_client()); | 219 InstrumentedGaiaCookieManagerService helper(token_service(), signin_client()); |
219 MockObserver observer(&helper); | 220 MockObserver observer(&helper); |
220 base::HistogramTester histograms; | 221 base::HistogramTester histograms; |
221 | 222 |
222 EXPECT_CALL(helper, StartFetchingUbertoken()); | 223 EXPECT_CALL(helper, StartFetchingUbertoken()); |
223 EXPECT_CALL(helper, StartFetchingMergeSession()).Times(2); | 224 EXPECT_CALL(helper, StartFetchingMergeSession()).Times(2); |
224 EXPECT_CALL(observer, OnAddAccountToCookieCompleted("acc1@gmail.com", | 225 EXPECT_CALL(observer, OnAddAccountToCookieCompleted("acc1@gmail.com", |
225 no_error())); | 226 no_error())); |
226 | 227 |
227 helper.AddAccountToCookie("acc1@gmail.com"); | 228 helper.AddAccountToCookie("acc1@gmail.com"); |
228 SimulateMergeSessionFailure(&helper, canceled()); | 229 SimulateMergeSessionFailure(&helper, canceled()); |
229 DCHECK(helper.is_running()); | 230 DCHECK(helper.is_running()); |
230 // Transient error incurs a retry after 1 second. | 231 // Transient error incurs a retry after 1 second. |
231 base::MessageLoop::current()->PostDelayedTask( | 232 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
232 FROM_HERE, | 233 FROM_HERE, base::MessageLoop::QuitClosure(), |
233 base::MessageLoop::QuitClosure(), | |
234 base::TimeDelta::FromMilliseconds(1100)); | 234 base::TimeDelta::FromMilliseconds(1100)); |
235 base::MessageLoop::current()->Run(); | 235 base::MessageLoop::current()->Run(); |
236 SimulateMergeSessionFailure(&helper, canceled()); | 236 SimulateMergeSessionFailure(&helper, canceled()); |
237 DCHECK(helper.is_running()); | 237 DCHECK(helper.is_running()); |
238 // Next transient error incurs a retry after 3 seconds. | 238 // Next transient error incurs a retry after 3 seconds. |
239 base::MessageLoop::current()->PostDelayedTask( | 239 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
240 FROM_HERE, | 240 FROM_HERE, base::MessageLoop::QuitClosure(), |
241 base::MessageLoop::QuitClosure(), | |
242 base::TimeDelta::FromMilliseconds(3100)); | 241 base::TimeDelta::FromMilliseconds(3100)); |
243 base::MessageLoop::current()->Run(); | 242 base::MessageLoop::current()->Run(); |
244 SimulateMergeSessionSuccess(&helper, "token"); | 243 SimulateMergeSessionSuccess(&helper, "token"); |
245 DCHECK(!helper.is_running()); | 244 DCHECK(!helper.is_running()); |
246 histograms.ExpectUniqueSample("OAuth2Login.MergeSessionRetry", | 245 histograms.ExpectUniqueSample("OAuth2Login.MergeSessionRetry", |
247 GoogleServiceAuthError::REQUEST_CANCELED, 2); | 246 GoogleServiceAuthError::REQUEST_CANCELED, 2); |
248 } | 247 } |
249 | 248 |
250 TEST_F(GaiaCookieManagerServiceTest, FailedUbertoken) { | 249 TEST_F(GaiaCookieManagerServiceTest, FailedUbertoken) { |
251 InstrumentedGaiaCookieManagerService helper(token_service(), signin_client()); | 250 InstrumentedGaiaCookieManagerService helper(token_service(), signin_client()); |
(...skipping 403 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
655 | 654 |
656 helper.external_cc_result_fetcher_for_testing()->Start(); | 655 helper.external_cc_result_fetcher_for_testing()->Start(); |
657 | 656 |
658 EXPECT_CALL(helper, StartFetchingUbertoken()); | 657 EXPECT_CALL(helper, StartFetchingUbertoken()); |
659 helper.AddAccountToCookie("acc2@gmail.com"); | 658 helper.AddAccountToCookie("acc2@gmail.com"); |
660 // There is already a ExternalCCResultFetch underway. This will trigger | 659 // There is already a ExternalCCResultFetch underway. This will trigger |
661 // StartFetchingMergeSession. | 660 // StartFetchingMergeSession. |
662 EXPECT_CALL(helper, StartFetchingMergeSession()); | 661 EXPECT_CALL(helper, StartFetchingMergeSession()); |
663 SimulateUbertokenSuccess(&helper, "token3"); | 662 SimulateUbertokenSuccess(&helper, "token3"); |
664 } | 663 } |
OLD | NEW |