OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/browser/signin/gaia_auth_fetcher_ios.h" | 5 #include "ios/chrome/browser/signin/gaia_auth_fetcher_ios.h" |
6 | 6 |
| 7 #include <memory> |
| 8 |
7 #import "base/mac/scoped_nsobject.h" | 9 #import "base/mac/scoped_nsobject.h" |
8 #include "base/memory/scoped_ptr.h" | |
9 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
10 #include "google_apis/gaia/gaia_urls.h" | 11 #include "google_apis/gaia/gaia_urls.h" |
11 #include "ios/chrome/browser/signin/gaia_auth_fetcher_ios_private.h" | 12 #include "ios/chrome/browser/signin/gaia_auth_fetcher_ios_private.h" |
12 #include "ios/web/public/test/test_browser_state.h" | 13 #include "ios/web/public/test/test_browser_state.h" |
13 #include "ios/web/public/test/test_web_thread_bundle.h" | 14 #include "ios/web/public/test/test_web_thread_bundle.h" |
14 #include "net/url_request/test_url_fetcher_factory.h" | 15 #include "net/url_request/test_url_fetcher_factory.h" |
15 #include "testing/gmock/include/gmock/gmock.h" | 16 #include "testing/gmock/include/gmock/gmock.h" |
16 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
17 #import "testing/gtest_mac.h" | 18 #import "testing/gtest_mac.h" |
18 #include "testing/platform_test.h" | 19 #include "testing/platform_test.h" |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 GaiaAuthFetcherIOSBridge* GetBridge() { | 71 GaiaAuthFetcherIOSBridge* GetBridge() { |
71 return gaia_auth_fetcher_->bridge_.get(); | 72 return gaia_auth_fetcher_->bridge_.get(); |
72 } | 73 } |
73 | 74 |
74 id GetMockWKWebView() { return gaia_auth_fetcher_->bridge_->GetWKWebView(); } | 75 id GetMockWKWebView() { return gaia_auth_fetcher_->bridge_->GetWKWebView(); } |
75 | 76 |
76 web::TestWebThreadBundle thread_bundle_; | 77 web::TestWebThreadBundle thread_bundle_; |
77 // BrowserState, required for WKWebView creation. | 78 // BrowserState, required for WKWebView creation. |
78 web::TestBrowserState browser_state_; | 79 web::TestBrowserState browser_state_; |
79 MockGaiaConsumer consumer_; | 80 MockGaiaConsumer consumer_; |
80 scoped_ptr<GaiaAuthFetcherIOS> gaia_auth_fetcher_; | 81 std::unique_ptr<GaiaAuthFetcherIOS> gaia_auth_fetcher_; |
81 }; | 82 }; |
82 | 83 |
83 // Tests that the cancel mechanism works properly by cancelling an OAuthLogin | 84 // Tests that the cancel mechanism works properly by cancelling an OAuthLogin |
84 // request and controlling that the consumer is properly called. | 85 // request and controlling that the consumer is properly called. |
85 TEST_F(GaiaAuthFetcherIOSTest, StartOAuthLoginCancelled) { | 86 TEST_F(GaiaAuthFetcherIOSTest, StartOAuthLoginCancelled) { |
86 GoogleServiceAuthError expected_error = | 87 GoogleServiceAuthError expected_error = |
87 GoogleServiceAuthError(GoogleServiceAuthError::REQUEST_CANCELED); | 88 GoogleServiceAuthError(GoogleServiceAuthError::REQUEST_CANCELED); |
88 EXPECT_CALL(consumer_, OnClientLoginFailure(expected_error)).Times(1); | 89 EXPECT_CALL(consumer_, OnClientLoginFailure(expected_error)).Times(1); |
89 | 90 |
90 [static_cast<WKWebView*>([GetMockWKWebView() expect]) | 91 [static_cast<WKWebView*>([GetMockWKWebView() expect]) |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 } | 128 } |
128 | 129 |
129 // Tests that requests that do not require cookies are using the original | 130 // Tests that requests that do not require cookies are using the original |
130 // GaiaAuthFetcher and not the GaiaAuthFetcherIOS specialization. | 131 // GaiaAuthFetcher and not the GaiaAuthFetcherIOS specialization. |
131 TEST_F(GaiaAuthFetcherIOSTest, StartGetCheckConnectionInfo) { | 132 TEST_F(GaiaAuthFetcherIOSTest, StartGetCheckConnectionInfo) { |
132 std::string data( | 133 std::string data( |
133 "[{\"carryBackToken\": \"token1\", \"url\": \"http://www.google.com\"}]"); | 134 "[{\"carryBackToken\": \"token1\", \"url\": \"http://www.google.com\"}]"); |
134 EXPECT_CALL(consumer_, OnGetCheckConnectionInfoSuccess(data)).Times(1); | 135 EXPECT_CALL(consumer_, OnGetCheckConnectionInfoSuccess(data)).Times(1); |
135 | 136 |
136 // Set up the fake URL Fetcher. | 137 // Set up the fake URL Fetcher. |
137 scoped_ptr<net::FakeURLFetcherFactory> fake_url_fetcher_factory( | 138 std::unique_ptr<net::FakeURLFetcherFactory> fake_url_fetcher_factory( |
138 new net::FakeURLFetcherFactory(new net::URLFetcherImplFactory())); | 139 new net::FakeURLFetcherFactory(new net::URLFetcherImplFactory())); |
139 fake_url_fetcher_factory->SetFakeResponse( | 140 fake_url_fetcher_factory->SetFakeResponse( |
140 GaiaUrls::GetInstance()->GetCheckConnectionInfoURLWithSource( | 141 GaiaUrls::GetInstance()->GetCheckConnectionInfoURLWithSource( |
141 std::string()), | 142 std::string()), |
142 data, net::HTTP_OK, net::URLRequestStatus::SUCCESS); | 143 data, net::HTTP_OK, net::URLRequestStatus::SUCCESS); |
143 | 144 |
144 gaia_auth_fetcher_->StartGetCheckConnectionInfo(); | 145 gaia_auth_fetcher_->StartGetCheckConnectionInfo(); |
145 base::RunLoop().RunUntilIdle(); | 146 base::RunLoop().RunUntilIdle(); |
146 } | 147 } |
147 | 148 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 [[GetMockWKWebView() expect] setNavigationDelegate:[OCMArg isNotNil]]; | 183 [[GetMockWKWebView() expect] setNavigationDelegate:[OCMArg isNotNil]]; |
183 [static_cast<WKWebView*>([[GetMockWKWebView() expect] andDo:^(NSInvocation*) { | 184 [static_cast<WKWebView*>([[GetMockWKWebView() expect] andDo:^(NSInvocation*) { |
184 GetBridge()->URLFetchSuccess("data"); | 185 GetBridge()->URLFetchSuccess("data"); |
185 }]) loadRequest:[OCMArg any]]; | 186 }]) loadRequest:[OCMArg any]]; |
186 | 187 |
187 gaia_auth_fetcher_->StartMergeSession("uber_token", ""); | 188 gaia_auth_fetcher_->StartMergeSession("uber_token", ""); |
188 web::BrowserState::GetActiveStateManager(&browser_state_)->SetActive(false); | 189 web::BrowserState::GetActiveStateManager(&browser_state_)->SetActive(false); |
189 web::BrowserState::GetActiveStateManager(&browser_state_)->SetActive(true); | 190 web::BrowserState::GetActiveStateManager(&browser_state_)->SetActive(true); |
190 EXPECT_OCMOCK_VERIFY(GetMockWKWebView()); | 191 EXPECT_OCMOCK_VERIFY(GetMockWKWebView()); |
191 } | 192 } |
OLD | NEW |