OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "ios/chrome/test/app/signin_test_util.h" | 5 #include "ios/chrome/test/app/signin_test_util.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/strings/stringprintf.h" | 8 #include "base/strings/stringprintf.h" |
9 #import "base/test/ios/wait_util.h" | 9 #import "base/test/ios/wait_util.h" |
10 #include "components/prefs/pref_service.h" | 10 #include "components/prefs/pref_service.h" |
11 #include "components/signin/core/browser/account_tracker_service.h" | 11 #include "components/signin/core/browser/account_tracker_service.h" |
12 #include "components/signin/core/common/signin_pref_names.h" | 12 #include "components/signin/core/common/signin_pref_names.h" |
13 #include "google_apis/gaia/gaia_constants.h" | 13 #include "google_apis/gaia/gaia_constants.h" |
14 #include "ios/chrome/browser/browser_state/chrome_browser_state.h" | 14 #include "ios/chrome/browser/browser_state/chrome_browser_state.h" |
15 #include "ios/chrome/browser/signin/account_tracker_service_factory.h" | 15 #include "ios/chrome/browser/signin/account_tracker_service_factory.h" |
16 #import "ios/chrome/browser/signin/authentication_service.h" | 16 #import "ios/chrome/browser/signin/authentication_service.h" |
17 #include "ios/chrome/browser/signin/authentication_service_factory.h" | 17 #include "ios/chrome/browser/signin/authentication_service_factory.h" |
18 #include "ios/chrome/browser/signin/gaia_auth_fetcher_ios.h" | 18 #include "ios/chrome/browser/signin/gaia_auth_fetcher_ios.h" |
19 #import "ios/chrome/test/app/chrome_test_util.h" | 19 #import "ios/chrome/test/app/chrome_test_util.h" |
20 #import "ios/public/provider/chrome/browser/chrome_browser_provider.h" | 20 #import "ios/public/provider/chrome/browser/chrome_browser_provider.h" |
21 #import "ios/public/provider/chrome/browser/signin/fake_chrome_identity_service.
h" | 21 #import "ios/public/provider/chrome/browser/signin/fake_chrome_identity_service.
h" |
22 #include "net/http/http_status_code.h" | 22 #include "net/http/http_status_code.h" |
| 23 #include "net/traffic_annotation/network_traffic_annotation_test_helper.h" |
23 #include "net/url_request/test_url_fetcher_factory.h" | 24 #include "net/url_request/test_url_fetcher_factory.h" |
24 #include "net/url_request/url_fetcher_delegate.h" | 25 #include "net/url_request/url_fetcher_delegate.h" |
25 #include "net/url_request/url_request_status.h" | 26 #include "net/url_request/url_request_status.h" |
26 | 27 |
27 namespace { | 28 namespace { |
28 | 29 |
29 net::FakeURLFetcherFactory* gFakeURLFetcherFactory = nullptr; | 30 net::FakeURLFetcherFactory* gFakeURLFetcherFactory = nullptr; |
30 | 31 |
31 // Specialization of the FakeURLFetcherFactory that will recognize GET requests | 32 // Specialization of the FakeURLFetcherFactory that will recognize GET requests |
32 // for MergeSession and answer those requests correctly. | 33 // for MergeSession and answer those requests correctly. |
33 class MergeSessionFakeURLFetcherFactory : public net::FakeURLFetcherFactory { | 34 class MergeSessionFakeURLFetcherFactory : public net::FakeURLFetcherFactory { |
34 public: | 35 public: |
35 explicit MergeSessionFakeURLFetcherFactory(URLFetcherFactory* default_factory) | 36 explicit MergeSessionFakeURLFetcherFactory(URLFetcherFactory* default_factory) |
36 : net::FakeURLFetcherFactory(default_factory) {} | 37 : net::FakeURLFetcherFactory(default_factory) {} |
37 std::unique_ptr<net::URLFetcher> CreateURLFetcher( | 38 std::unique_ptr<net::URLFetcher> CreateURLFetcher( |
38 int id, | 39 int id, |
39 const GURL& url, | 40 const GURL& url, |
40 net::URLFetcher::RequestType request_type, | 41 net::URLFetcher::RequestType request_type, |
41 net::URLFetcherDelegate* d) override { | 42 net::URLFetcherDelegate* d, |
| 43 net::NetworkTrafficAnnotationTag traffic_annotation) override { |
42 const GURL kMergeSessionURL = | 44 const GURL kMergeSessionURL = |
43 GURL("https://accounts.google.com/MergeSession"); | 45 GURL("https://accounts.google.com/MergeSession"); |
44 url::Replacements<char> replacements; | 46 url::Replacements<char> replacements; |
45 replacements.ClearRef(); | 47 replacements.ClearRef(); |
46 replacements.ClearQuery(); | 48 replacements.ClearQuery(); |
47 if (url.ReplaceComponents(replacements) != kMergeSessionURL) { | 49 if (url.ReplaceComponents(replacements) != kMergeSessionURL) { |
48 // URL is not a MergeSession GET. Use the default method. | 50 // URL is not a MergeSession GET. Use the default method. |
49 return net::FakeURLFetcherFactory::CreateURLFetcher(id, url, request_type, | 51 return net::FakeURLFetcherFactory::CreateURLFetcher( |
50 d); | 52 id, url, request_type, d, traffic_annotation); |
51 } | 53 } |
52 // Actual MergeSession request. Answer is ignored by the AccountReconcilor, | 54 // Actual MergeSession request. Answer is ignored by the AccountReconcilor, |
53 // so it can also be empty. | 55 // so it can also be empty. |
54 return std::unique_ptr<net::FakeURLFetcher>(new net::FakeURLFetcher( | 56 return std::unique_ptr<net::FakeURLFetcher>(new net::FakeURLFetcher( |
55 url, d, "", net::HTTP_OK, net::URLRequestStatus::SUCCESS)); | 57 url, d, "", net::HTTP_OK, net::URLRequestStatus::SUCCESS)); |
56 } | 58 } |
57 }; | 59 }; |
58 | 60 |
59 } // namespace | 61 } // namespace |
60 | 62 |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
161 NSDate* deadline = [NSDate dateWithTimeIntervalSinceNow:10.0]; | 163 NSDate* deadline = [NSDate dateWithTimeIntervalSinceNow:10.0]; |
162 while (identity_service->HasIdentities() && | 164 while (identity_service->HasIdentities() && |
163 [[NSDate date] compare:deadline] != NSOrderedDescending) { | 165 [[NSDate date] compare:deadline] != NSOrderedDescending) { |
164 base::test::ios::SpinRunLoopWithMaxDelay( | 166 base::test::ios::SpinRunLoopWithMaxDelay( |
165 base::TimeDelta::FromSecondsD(0.01)); | 167 base::TimeDelta::FromSecondsD(0.01)); |
166 } | 168 } |
167 return !identity_service->HasIdentities(); | 169 return !identity_service->HasIdentities(); |
168 } | 170 } |
169 | 171 |
170 } // namespace chrome_test_util | 172 } // namespace chrome_test_util |
OLD | NEW |