Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(717)

Side by Side Diff: chrome/browser/extensions/api/identity/identity_apitest.cc

Issue 12929014: Identity API: Pop-up a sign-in dialog if gaia credentials are bad (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@lkgr
Patch Set: fix signin browser test for chromeos Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "base/string_util.h" 5 #include "base/string_util.h"
6 #include "base/stringprintf.h" 6 #include "base/stringprintf.h"
7 #include "base/values.h" 7 #include "base/values.h"
8 #include "chrome/browser/extensions/api/identity/identity_api.h" 8 #include "chrome/browser/extensions/api/identity/identity_api.h"
9 #include "chrome/browser/extensions/api/identity/web_auth_flow.h" 9 #include "chrome/browser/extensions/api/identity/web_auth_flow.h"
10 #include "chrome/browser/extensions/extension_apitest.h" 10 #include "chrome/browser/extensions/extension_apitest.h"
11 #include "chrome/browser/extensions/extension_browsertest.h" 11 #include "chrome/browser/extensions/extension_browsertest.h"
12 #include "chrome/browser/extensions/extension_function_test_utils.h" 12 #include "chrome/browser/extensions/extension_function_test_utils.h"
13 #include "chrome/browser/ui/browser.h" 13 #include "chrome/browser/ui/browser.h"
14 #include "chrome/browser/ui/browser_window.h" 14 #include "chrome/browser/ui/browser_window.h"
15 #include "chrome/browser/ui/webui/signin/login_ui_service.h"
16 #include "chrome/common/chrome_switches.h" 15 #include "chrome/common/chrome_switches.h"
17 #include "chrome/common/chrome_notification_types.h" 16 #include "chrome/common/chrome_notification_types.h"
18 #include "chrome/common/extensions/api/identity/oauth2_manifest_handler.h" 17 #include "chrome/common/extensions/api/identity/oauth2_manifest_handler.h"
19 #include "chrome/test/base/in_process_browser_test.h" 18 #include "chrome/test/base/in_process_browser_test.h"
20 #include "content/public/browser/notification_service.h" 19 #include "content/public/browser/notification_service.h"
21 #include "content/public/browser/notification_source.h" 20 #include "content/public/browser/notification_source.h"
22 #include "content/public/test/test_utils.h" 21 #include "content/public/test/test_utils.h"
23 #include "google_apis/gaia/google_service_auth_error.h" 22 #include "google_apis/gaia/google_service_auth_error.h"
24 #include "google_apis/gaia/oauth2_mint_token_flow.h" 23 #include "google_apis/gaia/oauth2_mint_token_flow.h"
25 #include "googleurl/src/gurl.h" 24 #include "googleurl/src/gurl.h"
26 #include "testing/gmock/include/gmock/gmock.h" 25 #include "testing/gmock/include/gmock/gmock.h"
27 #include "testing/gtest/include/gtest/gtest.h" 26 #include "testing/gtest/include/gtest/gtest.h"
28 27
29 using testing::_; 28 using testing::_;
30 using testing::Return; 29 using testing::Return;
31 using testing::ReturnRef; 30 using testing::ReturnRef;
32 31
33 namespace extensions { 32 namespace extensions {
34 33
35 namespace { 34 namespace {
36 35
37 namespace errors = identity_constants; 36 namespace errors = identity_constants;
38 namespace utils = extension_function_test_utils; 37 namespace utils = extension_function_test_utils;
39 38
40 static const char kAccessToken[] = "auth_token"; 39 static const char kAccessToken[] = "auth_token";
41 40
42 class TestLoginUI : public LoginUIService::LoginUI {
43 public:
44 virtual void FocusUI() OVERRIDE {}
45 virtual void CloseUI() OVERRIDE {}
46 };
47
48 class TestOAuth2MintTokenFlow : public OAuth2MintTokenFlow { 41 class TestOAuth2MintTokenFlow : public OAuth2MintTokenFlow {
49 public: 42 public:
50 enum ResultType { 43 enum ResultType {
51 ISSUE_ADVICE_SUCCESS, 44 ISSUE_ADVICE_SUCCESS,
52 MINT_TOKEN_SUCCESS, 45 MINT_TOKEN_SUCCESS,
53 MINT_TOKEN_FAILURE 46 MINT_TOKEN_FAILURE,
47 MINT_TOKEN_BAD_CREDENTIALS
54 }; 48 };
55 49
56 TestOAuth2MintTokenFlow(ResultType result, 50 TestOAuth2MintTokenFlow(ResultType result,
57 OAuth2MintTokenFlow::Delegate* delegate) 51 OAuth2MintTokenFlow::Delegate* delegate)
58 : OAuth2MintTokenFlow(NULL, delegate, OAuth2MintTokenFlow::Parameters()), 52 : OAuth2MintTokenFlow(NULL, delegate, OAuth2MintTokenFlow::Parameters()),
59 result_(result), 53 result_(result),
60 delegate_(delegate) { 54 delegate_(delegate) {
61 } 55 }
62 56
63 virtual void Start() OVERRIDE { 57 virtual void Start() OVERRIDE {
64 switch (result_) { 58 switch (result_) {
65 case ISSUE_ADVICE_SUCCESS: { 59 case ISSUE_ADVICE_SUCCESS: {
66 IssueAdviceInfo info; 60 IssueAdviceInfo info;
67 delegate_->OnIssueAdviceSuccess(info); 61 delegate_->OnIssueAdviceSuccess(info);
68 break; 62 break;
69 } 63 }
70 case MINT_TOKEN_SUCCESS: { 64 case MINT_TOKEN_SUCCESS: {
71 delegate_->OnMintTokenSuccess(kAccessToken); 65 delegate_->OnMintTokenSuccess(kAccessToken);
72 break; 66 break;
73 } 67 }
74 case MINT_TOKEN_FAILURE: { 68 case MINT_TOKEN_FAILURE: {
69 GoogleServiceAuthError error(GoogleServiceAuthError::CONNECTION_FAILED);
70 delegate_->OnMintTokenFailure(error);
71 break;
72 }
73 case MINT_TOKEN_BAD_CREDENTIALS: {
75 GoogleServiceAuthError error( 74 GoogleServiceAuthError error(
76 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS); 75 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS);
77 delegate_->OnMintTokenFailure(error); 76 delegate_->OnMintTokenFailure(error);
78 break; 77 break;
79 } 78 }
80 } 79 }
81 } 80 }
82 81
83 private: 82 private:
84 ResultType result_; 83 ResultType result_;
85 OAuth2MintTokenFlow::Delegate* delegate_; 84 OAuth2MintTokenFlow::Delegate* delegate_;
86 }; 85 };
87 86
88 } // namespace 87 } // namespace
89 88
90 class MockGetAuthTokenFunction : public IdentityGetAuthTokenFunction { 89 class MockGetAuthTokenFunction : public IdentityGetAuthTokenFunction {
91 public: 90 public:
92 MockGetAuthTokenFunction() : install_ui_result_(false), 91 MockGetAuthTokenFunction() : login_ui_result_(true),
92 install_ui_result_(false),
93 login_ui_shown_(false), 93 login_ui_shown_(false),
94 install_ui_shown_(false) { 94 install_ui_shown_(false) {
95 } 95 }
96 96
97 void set_login_ui_result(bool result) {
98 login_ui_result_ = result;
99 }
100
97 void set_install_ui_result(bool result) { 101 void set_install_ui_result(bool result) {
98 install_ui_result_ = result; 102 install_ui_result_ = result;
99 } 103 }
100 104
101 bool login_ui_shown() const { 105 bool login_ui_shown() const {
102 return login_ui_shown_; 106 return login_ui_shown_;
103 } 107 }
104 108
105 bool install_ui_shown() const { 109 bool install_ui_shown() const {
106 return install_ui_shown_; 110 return install_ui_shown_;
107 } 111 }
108 112
109 virtual void StartObservingLoginService() OVERRIDE {
110 // Do nothing in tests.
111 }
112 virtual void StopObservingLoginService() OVERRIDE {
113 // Do nothing in tests.
114 }
115
116 virtual void ShowLoginPopup() OVERRIDE { 113 virtual void ShowLoginPopup() OVERRIDE {
114 EXPECT_FALSE(login_ui_shown_);
117 login_ui_shown_ = true; 115 login_ui_shown_ = true;
118 // Explicitly call OnLoginUIClosed. 116 if (login_ui_result_)
119 TestLoginUI login_ui;; 117 SigninSuccess("fake_refresh_token");
120 OnLoginUIClosed(&login_ui); 118 else
119 SigninFailed();
121 } 120 }
122 121
123 virtual void ShowOAuthApprovalDialog( 122 virtual void ShowOAuthApprovalDialog(
124 const IssueAdviceInfo& issue_advice) OVERRIDE { 123 const IssueAdviceInfo& issue_advice) OVERRIDE {
125 install_ui_shown_ = true; 124 install_ui_shown_ = true;
126 install_ui_->record_oauth2_grant_ = true; 125 install_ui_->record_oauth2_grant_ = true;
127 // Call InstallUIProceed or InstallUIAbort based on the flag. 126 // Call InstallUIProceed or InstallUIAbort based on the flag.
128 if (install_ui_result_) 127 if (install_ui_result_)
129 InstallUIProceed(); 128 InstallUIProceed();
130 else 129 else
131 InstallUIAbort(true); 130 InstallUIAbort(true);
132 } 131 }
133 132
134 MOCK_CONST_METHOD0(HasLoginToken, bool ()); 133 MOCK_CONST_METHOD0(HasLoginToken, bool());
135 MOCK_METHOD1(CreateMintTokenFlow, 134 MOCK_METHOD1(CreateMintTokenFlow,
136 OAuth2MintTokenFlow* (OAuth2MintTokenFlow::Mode mode)); 135 OAuth2MintTokenFlow* (OAuth2MintTokenFlow::Mode mode));
136
137 private: 137 private:
138 ~MockGetAuthTokenFunction() {} 138 ~MockGetAuthTokenFunction() {}
139 bool login_ui_result_;
139 bool install_ui_result_; 140 bool install_ui_result_;
140 bool login_ui_shown_; 141 bool login_ui_shown_;
141 bool install_ui_shown_; 142 bool install_ui_shown_;
142 }; 143 };
143 144
144 class GetAuthTokenFunctionTest : public ExtensionBrowserTest { 145 class GetAuthTokenFunctionTest : public ExtensionBrowserTest {
145 protected: 146 protected:
146 enum OAuth2Fields { 147 enum OAuth2Fields {
147 NONE = 0, 148 NONE = 0,
148 CLIENT_ID = 1, 149 CLIENT_ID = 1,
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 EXPECT_EQ(std::string(errors::kUserNotSignedIn), error); 201 EXPECT_EQ(std::string(errors::kUserNotSignedIn), error);
201 EXPECT_FALSE(func->login_ui_shown()); 202 EXPECT_FALSE(func->login_ui_shown());
202 EXPECT_FALSE(func->install_ui_shown()); 203 EXPECT_FALSE(func->install_ui_shown());
203 } 204 }
204 205
205 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, 206 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest,
206 NonInteractiveMintFailure) { 207 NonInteractiveMintFailure) {
207 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); 208 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction());
208 func->set_extension(CreateExtension(CLIENT_ID | SCOPES)); 209 func->set_extension(CreateExtension(CLIENT_ID | SCOPES));
209 EXPECT_CALL(*func.get(), HasLoginToken()) 210 EXPECT_CALL(*func.get(), HasLoginToken())
210 .WillOnce(Return(true))
211 .WillOnce(Return(true)); 211 .WillOnce(Return(true));
212 TestOAuth2MintTokenFlow* flow = new TestOAuth2MintTokenFlow( 212 TestOAuth2MintTokenFlow* flow = new TestOAuth2MintTokenFlow(
213 TestOAuth2MintTokenFlow::MINT_TOKEN_FAILURE, func.get()); 213 TestOAuth2MintTokenFlow::MINT_TOKEN_FAILURE, func.get());
214 EXPECT_CALL(*func.get(), CreateMintTokenFlow(_)).WillOnce(Return(flow)); 214 EXPECT_CALL(*func.get(), CreateMintTokenFlow(_)).WillOnce(Return(flow));
215 std::string error = utils::RunFunctionAndReturnError( 215 std::string error = utils::RunFunctionAndReturnError(
216 func.get(), "[{}]", browser()); 216 func.get(), "[{}]", browser());
217 EXPECT_TRUE(StartsWithASCII(error, errors::kAuthFailure, false)); 217 EXPECT_TRUE(StartsWithASCII(error, errors::kAuthFailure, false));
218 EXPECT_FALSE(func->login_ui_shown()); 218 EXPECT_FALSE(func->login_ui_shown());
219 EXPECT_FALSE(func->install_ui_shown()); 219 EXPECT_FALSE(func->install_ui_shown());
220 } 220 }
221 221
222 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, 222 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest,
223 NonInteractiveMintBadCredentials) {
224 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction());
225 func->set_extension(CreateExtension(CLIENT_ID | SCOPES));
226 EXPECT_CALL(*func.get(), HasLoginToken())
227 .WillOnce(Return(true));
228 TestOAuth2MintTokenFlow* flow = new TestOAuth2MintTokenFlow(
229 TestOAuth2MintTokenFlow::MINT_TOKEN_BAD_CREDENTIALS, func.get());
230 EXPECT_CALL(*func.get(), CreateMintTokenFlow(_)).WillOnce(Return(flow));
231 std::string error = utils::RunFunctionAndReturnError(
232 func.get(), "[{}]", browser());
233 EXPECT_TRUE(StartsWithASCII(error, errors::kAuthFailure, false));
234 EXPECT_FALSE(func->login_ui_shown());
235 EXPECT_FALSE(func->install_ui_shown());
236 }
237
238 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest,
223 NonInteractiveSuccess) { 239 NonInteractiveSuccess) {
224 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); 240 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction());
225 func->set_extension(CreateExtension(CLIENT_ID | SCOPES)); 241 func->set_extension(CreateExtension(CLIENT_ID | SCOPES));
226 EXPECT_CALL(*func.get(), HasLoginToken()) 242 EXPECT_CALL(*func.get(), HasLoginToken())
227 .WillOnce(Return(true))
228 .WillOnce(Return(true)); 243 .WillOnce(Return(true));
229 TestOAuth2MintTokenFlow* flow = new TestOAuth2MintTokenFlow( 244 TestOAuth2MintTokenFlow* flow = new TestOAuth2MintTokenFlow(
230 TestOAuth2MintTokenFlow::MINT_TOKEN_SUCCESS, func.get()); 245 TestOAuth2MintTokenFlow::MINT_TOKEN_SUCCESS, func.get());
231 EXPECT_CALL(*func.get(), CreateMintTokenFlow(_)).WillOnce(Return(flow)); 246 EXPECT_CALL(*func.get(), CreateMintTokenFlow(_)).WillOnce(Return(flow));
232 scoped_ptr<base::Value> value(utils::RunFunctionAndReturnSingleResult( 247 scoped_ptr<base::Value> value(utils::RunFunctionAndReturnSingleResult(
233 func.get(), "[{}]", browser())); 248 func.get(), "[{}]", browser()));
234 std::string access_token; 249 std::string access_token;
235 EXPECT_TRUE(value->GetAsString(&access_token)); 250 EXPECT_TRUE(value->GetAsString(&access_token));
236 EXPECT_EQ(std::string(kAccessToken), access_token); 251 EXPECT_EQ(std::string(kAccessToken), access_token);
237 EXPECT_FALSE(func->login_ui_shown()); 252 EXPECT_FALSE(func->login_ui_shown());
238 EXPECT_FALSE(func->install_ui_shown()); 253 EXPECT_FALSE(func->install_ui_shown());
239 } 254 }
240 255
241 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, 256 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest,
242 InteractiveLoginCanceled) { 257 InteractiveLoginCanceled) {
243 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); 258 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction());
244 func->set_extension(CreateExtension(CLIENT_ID | SCOPES)); 259 func->set_extension(CreateExtension(CLIENT_ID | SCOPES));
245 EXPECT_CALL(*func.get(), HasLoginToken()).WillRepeatedly(Return(false)); 260 EXPECT_CALL(*func.get(), HasLoginToken()).WillOnce(Return(false));
261 func->set_login_ui_result(false);
246 std::string error = utils::RunFunctionAndReturnError( 262 std::string error = utils::RunFunctionAndReturnError(
247 func.get(), "[{\"interactive\": true}]", browser()); 263 func.get(), "[{\"interactive\": true}]", browser());
248 EXPECT_EQ(std::string(errors::kUserNotSignedIn), error); 264 EXPECT_EQ(std::string(errors::kUserNotSignedIn), error);
249 EXPECT_TRUE(func->login_ui_shown()); 265 EXPECT_TRUE(func->login_ui_shown());
250 EXPECT_FALSE(func->install_ui_shown()); 266 EXPECT_FALSE(func->install_ui_shown());
251 } 267 }
252 268
253 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, 269 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest,
270 InteractiveMintBadCredentialsLoginCanceled) {
271 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction());
272 func->set_extension(CreateExtension(CLIENT_ID | SCOPES));
273 EXPECT_CALL(*func.get(), HasLoginToken())
274 .WillOnce(Return(true));
275 TestOAuth2MintTokenFlow* flow = new TestOAuth2MintTokenFlow(
276 TestOAuth2MintTokenFlow::MINT_TOKEN_BAD_CREDENTIALS, func.get());
277 EXPECT_CALL(*func.get(), CreateMintTokenFlow(_)).WillOnce(Return(flow));
278 func->set_login_ui_result(false);
279 std::string error = utils::RunFunctionAndReturnError(
280 func.get(), "[{\"interactive\": true}]", browser());
281 EXPECT_EQ(std::string(errors::kUserNotSignedIn), error);
282 EXPECT_TRUE(func->login_ui_shown());
283 EXPECT_FALSE(func->install_ui_shown());
284 }
285
286 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest,
287 InteractiveLoginSuccessNoToken) {
288 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction());
289 func->set_extension(CreateExtension(CLIENT_ID | SCOPES));
290 EXPECT_CALL(*func.get(), HasLoginToken()).WillOnce(Return(false));
291 func->set_login_ui_result(false);
292 std::string error = utils::RunFunctionAndReturnError(
293 func.get(), "[{\"interactive\": true}]", browser());
294 EXPECT_EQ(std::string(errors::kUserNotSignedIn), error);
295 EXPECT_TRUE(func->login_ui_shown());
296 EXPECT_FALSE(func->install_ui_shown());
297 }
298
299 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest,
254 InteractiveLoginSuccessMintFailure) { 300 InteractiveLoginSuccessMintFailure) {
255 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); 301 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction());
256 func->set_extension(CreateExtension(CLIENT_ID | SCOPES)); 302 func->set_extension(CreateExtension(CLIENT_ID | SCOPES));
257 EXPECT_CALL(*func.get(), HasLoginToken()) 303 EXPECT_CALL(*func.get(), HasLoginToken())
258 .WillOnce(Return(false)) 304 .WillOnce(Return(false));
259 .WillOnce(Return(true)); 305 func->set_login_ui_result(true);
260 TestOAuth2MintTokenFlow* flow = new TestOAuth2MintTokenFlow( 306 TestOAuth2MintTokenFlow* flow = new TestOAuth2MintTokenFlow(
261 TestOAuth2MintTokenFlow::MINT_TOKEN_FAILURE, func.get()); 307 TestOAuth2MintTokenFlow::MINT_TOKEN_FAILURE, func.get());
262 EXPECT_CALL(*func.get(), CreateMintTokenFlow(_)).WillOnce(Return(flow)); 308 EXPECT_CALL(*func.get(), CreateMintTokenFlow(_)).WillOnce(Return(flow));
263 std::string error = utils::RunFunctionAndReturnError( 309 std::string error = utils::RunFunctionAndReturnError(
264 func.get(), "[{\"interactive\": true}]", browser()); 310 func.get(), "[{\"interactive\": true}]", browser());
265 EXPECT_TRUE(StartsWithASCII(error, errors::kAuthFailure, false)); 311 EXPECT_TRUE(StartsWithASCII(error, errors::kAuthFailure, false));
266 EXPECT_TRUE(func->login_ui_shown()); 312 EXPECT_TRUE(func->login_ui_shown());
267 EXPECT_FALSE(func->install_ui_shown()); 313 EXPECT_FALSE(func->install_ui_shown());
268 } 314 }
269 315
270 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, 316 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest,
271 InteractiveLoginSuccessMintSuccess) { 317 InteractiveLoginSuccessMintSuccess) {
272 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); 318 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction());
273 func->set_extension(CreateExtension(CLIENT_ID | SCOPES)); 319 func->set_extension(CreateExtension(CLIENT_ID | SCOPES));
274 EXPECT_CALL(*func.get(), HasLoginToken()) 320 EXPECT_CALL(*func.get(), HasLoginToken())
275 .WillOnce(Return(false)) 321 .WillOnce(Return(false));
276 .WillOnce(Return(true)); 322 func->set_login_ui_result(true);
277 TestOAuth2MintTokenFlow* flow = new TestOAuth2MintTokenFlow( 323 TestOAuth2MintTokenFlow* flow = new TestOAuth2MintTokenFlow(
278 TestOAuth2MintTokenFlow::MINT_TOKEN_SUCCESS, func.get()); 324 TestOAuth2MintTokenFlow::MINT_TOKEN_SUCCESS, func.get());
279 EXPECT_CALL(*func.get(), CreateMintTokenFlow(_)).WillOnce(Return(flow)); 325 EXPECT_CALL(*func.get(), CreateMintTokenFlow(_)).WillOnce(Return(flow));
280 scoped_ptr<base::Value> value(utils::RunFunctionAndReturnSingleResult( 326 scoped_ptr<base::Value> value(utils::RunFunctionAndReturnSingleResult(
281 func.get(), "[{\"interactive\": true}]", browser())); 327 func.get(), "[{\"interactive\": true}]", browser()));
282 std::string access_token; 328 std::string access_token;
283 EXPECT_TRUE(value->GetAsString(&access_token)); 329 EXPECT_TRUE(value->GetAsString(&access_token));
284 EXPECT_EQ(std::string(kAccessToken), access_token); 330 EXPECT_EQ(std::string(kAccessToken), access_token);
285 EXPECT_TRUE(func->login_ui_shown()); 331 EXPECT_TRUE(func->login_ui_shown());
286 EXPECT_FALSE(func->install_ui_shown()); 332 EXPECT_FALSE(func->install_ui_shown());
287 } 333 }
288 334
289 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, 335 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest,
290 InteractiveLoginSuccessApprovalAborted) { 336 InteractiveLoginSuccessApprovalAborted) {
291 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); 337 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction());
292 func->set_extension(CreateExtension(CLIENT_ID | SCOPES)); 338 func->set_extension(CreateExtension(CLIENT_ID | SCOPES));
293 EXPECT_CALL(*func.get(), HasLoginToken()) 339 EXPECT_CALL(*func.get(), HasLoginToken())
294 .WillOnce(Return(false)) 340 .WillOnce(Return(false));
295 .WillOnce(Return(true)); 341 func->set_login_ui_result(true);
296 TestOAuth2MintTokenFlow* flow = new TestOAuth2MintTokenFlow( 342 TestOAuth2MintTokenFlow* flow = new TestOAuth2MintTokenFlow(
297 TestOAuth2MintTokenFlow::ISSUE_ADVICE_SUCCESS, func.get()); 343 TestOAuth2MintTokenFlow::ISSUE_ADVICE_SUCCESS, func.get());
298 EXPECT_CALL(*func.get(), CreateMintTokenFlow(_)).WillOnce(Return(flow)); 344 EXPECT_CALL(*func.get(), CreateMintTokenFlow(_)).WillOnce(Return(flow));
299 func->set_install_ui_result(false); 345 func->set_install_ui_result(false);
300 std::string error = utils::RunFunctionAndReturnError( 346 std::string error = utils::RunFunctionAndReturnError(
301 func.get(), "[{\"interactive\": true}]", browser()); 347 func.get(), "[{\"interactive\": true}]", browser());
302 EXPECT_EQ(std::string(errors::kUserRejected), error); 348 EXPECT_EQ(std::string(errors::kUserRejected), error);
303 EXPECT_TRUE(func->login_ui_shown()); 349 EXPECT_TRUE(func->login_ui_shown());
304 EXPECT_TRUE(func->install_ui_shown()); 350 EXPECT_TRUE(func->install_ui_shown());
305 } 351 }
306 352
307 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, 353 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest,
308 InteractiveLoginSuccessApprovalDoneMintFailure) { 354 InteractiveLoginSuccessApprovalDoneMintFailure) {
309 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); 355 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction());
310 func->set_extension(CreateExtension(CLIENT_ID | SCOPES)); 356 func->set_extension(CreateExtension(CLIENT_ID | SCOPES));
311 EXPECT_CALL(*func.get(), HasLoginToken()) 357 EXPECT_CALL(*func.get(), HasLoginToken())
312 .WillOnce(Return(false)) 358 .WillOnce(Return(false));
313 .WillOnce(Return(true)) 359 func->set_login_ui_result(true);
314 .WillOnce(Return(true));
315 TestOAuth2MintTokenFlow* flow1 = new TestOAuth2MintTokenFlow( 360 TestOAuth2MintTokenFlow* flow1 = new TestOAuth2MintTokenFlow(
316 TestOAuth2MintTokenFlow::ISSUE_ADVICE_SUCCESS, func.get()); 361 TestOAuth2MintTokenFlow::ISSUE_ADVICE_SUCCESS, func.get());
317 TestOAuth2MintTokenFlow* flow2 = new TestOAuth2MintTokenFlow( 362 TestOAuth2MintTokenFlow* flow2 = new TestOAuth2MintTokenFlow(
318 TestOAuth2MintTokenFlow::MINT_TOKEN_FAILURE, func.get()); 363 TestOAuth2MintTokenFlow::MINT_TOKEN_FAILURE, func.get());
319 EXPECT_CALL(*func.get(), CreateMintTokenFlow(_)) 364 EXPECT_CALL(*func.get(), CreateMintTokenFlow(_))
320 .WillOnce(Return(flow1)) 365 .WillOnce(Return(flow1))
321 .WillOnce(Return(flow2)); 366 .WillOnce(Return(flow2));
322 367
323 func->set_install_ui_result(true); 368 func->set_install_ui_result(true);
324 std::string error = utils::RunFunctionAndReturnError( 369 std::string error = utils::RunFunctionAndReturnError(
325 func.get(), "[{\"interactive\": true}]", browser()); 370 func.get(), "[{\"interactive\": true}]", browser());
326 EXPECT_TRUE(StartsWithASCII(error, errors::kAuthFailure, false)); 371 EXPECT_TRUE(StartsWithASCII(error, errors::kAuthFailure, false));
327 EXPECT_TRUE(func->login_ui_shown()); 372 EXPECT_TRUE(func->login_ui_shown());
328 EXPECT_TRUE(func->install_ui_shown()); 373 EXPECT_TRUE(func->install_ui_shown());
329 } 374 }
330 375
331 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, 376 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest,
332 InteractiveLoginSuccessApprovalDoneMintSuccess) { 377 InteractiveLoginSuccessApprovalDoneMintSuccess) {
333 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); 378 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction());
334 func->set_extension(CreateExtension(CLIENT_ID | SCOPES)); 379 func->set_extension(CreateExtension(CLIENT_ID | SCOPES));
335 EXPECT_CALL(*func.get(), HasLoginToken()) 380 EXPECT_CALL(*func.get(), HasLoginToken())
336 .WillOnce(Return(false)) 381 .WillOnce(Return(false));
337 .WillOnce(Return(true)) 382 func->set_login_ui_result(true);
338 .WillOnce(Return(true));
339 TestOAuth2MintTokenFlow* flow1 = new TestOAuth2MintTokenFlow( 383 TestOAuth2MintTokenFlow* flow1 = new TestOAuth2MintTokenFlow(
340 TestOAuth2MintTokenFlow::ISSUE_ADVICE_SUCCESS, func.get()); 384 TestOAuth2MintTokenFlow::ISSUE_ADVICE_SUCCESS, func.get());
341 TestOAuth2MintTokenFlow* flow2 = new TestOAuth2MintTokenFlow( 385 TestOAuth2MintTokenFlow* flow2 = new TestOAuth2MintTokenFlow(
342 TestOAuth2MintTokenFlow::MINT_TOKEN_SUCCESS, func.get()); 386 TestOAuth2MintTokenFlow::MINT_TOKEN_SUCCESS, func.get());
343 EXPECT_CALL(*func.get(), CreateMintTokenFlow(_)) 387 EXPECT_CALL(*func.get(), CreateMintTokenFlow(_))
344 .WillOnce(Return(flow1)) 388 .WillOnce(Return(flow1))
345 .WillOnce(Return(flow2)); 389 .WillOnce(Return(flow2));
346 390
347 func->set_install_ui_result(true); 391 func->set_install_ui_result(true);
348 scoped_ptr<base::Value> value(utils::RunFunctionAndReturnSingleResult( 392 scoped_ptr<base::Value> value(utils::RunFunctionAndReturnSingleResult(
349 func.get(), "[{\"interactive\": true}]", browser())); 393 func.get(), "[{\"interactive\": true}]", browser()));
350 std::string access_token; 394 std::string access_token;
351 EXPECT_TRUE(value->GetAsString(&access_token)); 395 EXPECT_TRUE(value->GetAsString(&access_token));
352 EXPECT_EQ(std::string(kAccessToken), access_token); 396 EXPECT_EQ(std::string(kAccessToken), access_token);
353 EXPECT_TRUE(func->login_ui_shown()); 397 EXPECT_TRUE(func->login_ui_shown());
354 EXPECT_TRUE(func->install_ui_shown()); 398 EXPECT_TRUE(func->install_ui_shown());
355 } 399 }
356 400
357 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, 401 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest,
358 InteractiveApprovalAborted) { 402 InteractiveApprovalAborted) {
359 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); 403 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction());
360 func->set_extension(CreateExtension(CLIENT_ID | SCOPES)); 404 func->set_extension(CreateExtension(CLIENT_ID | SCOPES));
361 EXPECT_CALL(*func.get(), HasLoginToken()) 405 EXPECT_CALL(*func.get(), HasLoginToken())
362 .WillOnce(Return(true))
363 .WillOnce(Return(true)); 406 .WillOnce(Return(true));
364 TestOAuth2MintTokenFlow* flow = new TestOAuth2MintTokenFlow( 407 TestOAuth2MintTokenFlow* flow = new TestOAuth2MintTokenFlow(
365 TestOAuth2MintTokenFlow::ISSUE_ADVICE_SUCCESS, func.get()); 408 TestOAuth2MintTokenFlow::ISSUE_ADVICE_SUCCESS, func.get());
366 EXPECT_CALL(*func.get(), CreateMintTokenFlow(_)).WillOnce(Return(flow)); 409 EXPECT_CALL(*func.get(), CreateMintTokenFlow(_)).WillOnce(Return(flow));
367 func->set_install_ui_result(false); 410 func->set_install_ui_result(false);
368 std::string error = utils::RunFunctionAndReturnError( 411 std::string error = utils::RunFunctionAndReturnError(
369 func.get(), "[{\"interactive\": true}]", browser()); 412 func.get(), "[{\"interactive\": true}]", browser());
370 EXPECT_EQ(std::string(errors::kUserRejected), error); 413 EXPECT_EQ(std::string(errors::kUserRejected), error);
371 EXPECT_FALSE(func->login_ui_shown()); 414 EXPECT_FALSE(func->login_ui_shown());
372 EXPECT_TRUE(func->install_ui_shown()); 415 EXPECT_TRUE(func->install_ui_shown());
373 } 416 }
374 417
375 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, 418 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest,
376 InteractiveApprovalDoneMintSuccess) { 419 InteractiveApprovalDoneMintSuccess) {
377 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); 420 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction());
378 func->set_extension(CreateExtension(CLIENT_ID | SCOPES)); 421 func->set_extension(CreateExtension(CLIENT_ID | SCOPES));
379 EXPECT_CALL(*func.get(), HasLoginToken()) 422 EXPECT_CALL(*func.get(), HasLoginToken())
380 .WillOnce(Return(true))
381 .WillOnce(Return(true))
382 .WillOnce(Return(true)); 423 .WillOnce(Return(true));
383 TestOAuth2MintTokenFlow* flow1 = new TestOAuth2MintTokenFlow( 424 TestOAuth2MintTokenFlow* flow1 = new TestOAuth2MintTokenFlow(
384 TestOAuth2MintTokenFlow::ISSUE_ADVICE_SUCCESS, func.get()); 425 TestOAuth2MintTokenFlow::ISSUE_ADVICE_SUCCESS, func.get());
385 TestOAuth2MintTokenFlow* flow2 = new TestOAuth2MintTokenFlow( 426 TestOAuth2MintTokenFlow* flow2 = new TestOAuth2MintTokenFlow(
386 TestOAuth2MintTokenFlow::MINT_TOKEN_SUCCESS, func.get()); 427 TestOAuth2MintTokenFlow::MINT_TOKEN_SUCCESS, func.get());
387 EXPECT_CALL(*func.get(), CreateMintTokenFlow(_)) 428 EXPECT_CALL(*func.get(), CreateMintTokenFlow(_))
388 .WillOnce(Return(flow1)) 429 .WillOnce(Return(flow1))
389 .WillOnce(Return(flow2)); 430 .WillOnce(Return(flow2));
390 431
391 func->set_install_ui_result(true); 432 func->set_install_ui_result(true);
392 scoped_ptr<base::Value> value(utils::RunFunctionAndReturnSingleResult( 433 scoped_ptr<base::Value> value(utils::RunFunctionAndReturnSingleResult(
393 func.get(), "[{\"interactive\": true}]", browser())); 434 func.get(), "[{\"interactive\": true}]", browser()));
394 std::string access_token; 435 std::string access_token;
395 EXPECT_TRUE(value->GetAsString(&access_token)); 436 EXPECT_TRUE(value->GetAsString(&access_token));
396 EXPECT_EQ(std::string(kAccessToken), access_token); 437 EXPECT_EQ(std::string(kAccessToken), access_token);
397 EXPECT_FALSE(func->login_ui_shown()); 438 EXPECT_FALSE(func->login_ui_shown());
398 EXPECT_TRUE(func->install_ui_shown()); 439 EXPECT_TRUE(func->install_ui_shown());
399 } 440 }
400 441
442 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest,
443 InteractiveApprovalDoneMintBadCredentials) {
444 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction());
445 func->set_extension(CreateExtension(CLIENT_ID | SCOPES));
446 EXPECT_CALL(*func.get(), HasLoginToken())
447 .WillOnce(Return(true));
448 TestOAuth2MintTokenFlow* flow1 = new TestOAuth2MintTokenFlow(
449 TestOAuth2MintTokenFlow::ISSUE_ADVICE_SUCCESS, func.get());
450 TestOAuth2MintTokenFlow* flow2 = new TestOAuth2MintTokenFlow(
451 TestOAuth2MintTokenFlow::MINT_TOKEN_BAD_CREDENTIALS, func.get());
452 EXPECT_CALL(*func.get(), CreateMintTokenFlow(_))
453 .WillOnce(Return(flow1))
454 .WillOnce(Return(flow2));
455
456 func->set_install_ui_result(true);
457 std::string error = utils::RunFunctionAndReturnError(
458 func.get(), "[{\"interactive\": true}]", browser());
459 EXPECT_TRUE(StartsWithASCII(error, errors::kAuthFailure, false));
460 EXPECT_FALSE(func->login_ui_shown());
461 EXPECT_TRUE(func->install_ui_shown());
462 }
463
401 class LaunchWebAuthFlowFunctionTest : public ExtensionBrowserTest { 464 class LaunchWebAuthFlowFunctionTest : public ExtensionBrowserTest {
402 protected: 465 protected:
403 void RunAndCheckBounds( 466 void RunAndCheckBounds(
404 const std::string& extra_params, 467 const std::string& extra_params,
405 int expected_x, 468 int expected_x,
406 int expected_y, 469 int expected_y,
407 int expected_width, 470 int expected_width,
408 int expected_height) { 471 int expected_height) {
409 content::WindowedNotificationObserver observer( 472 content::WindowedNotificationObserver observer(
410 chrome::NOTIFICATION_BROWSER_WINDOW_READY, 473 chrome::NOTIFICATION_BROWSER_WINDOW_READY,
411 content::NotificationService::AllSources()); 474 content::NotificationService::AllSources());
412 475
413 scoped_refptr<IdentityLaunchWebAuthFlowFunction> function( 476 scoped_refptr<IdentityLaunchWebAuthFlowFunction> function(
414 new IdentityLaunchWebAuthFlowFunction()); 477 new IdentityLaunchWebAuthFlowFunction());
415 scoped_refptr<Extension> empty_extension( 478 scoped_refptr<Extension> empty_extension(
416 utils::CreateEmptyExtension()); 479 utils::CreateEmptyExtension());
417 function->set_extension(empty_extension.get()); 480 function->set_extension(empty_extension.get());
418 std::string args = base::StringPrintf( 481 std::string args = base::StringPrintf(
419 "[{\"interactive\": true, \"url\": \"data:text/html,auth\"%s%s}]", 482 "[{\"interactive\": true, \"url\": \"data:text/html,auth\"%s%s}]",
420 extra_params.length() ? "," : "", 483 extra_params.length() ? "," : "",
421 extra_params.c_str()); 484 extra_params.c_str());
422 scoped_ptr<base::ListValue> parsed_args(utils::ParseList(args)); 485 scoped_ptr<base::ListValue> parsed_args(utils::ParseList(args));
423 EXPECT_TRUE(parsed_args.get()) << 486 EXPECT_TRUE(parsed_args.get()) <<
(...skipping 23 matching lines...) Expand all
447 IN_PROC_BROWSER_TEST_F(LaunchWebAuthFlowFunctionTest, Bounds) { 510 IN_PROC_BROWSER_TEST_F(LaunchWebAuthFlowFunctionTest, Bounds) {
448 RunAndCheckBounds("", 0, 0, 0, 0); 511 RunAndCheckBounds("", 0, 0, 0, 0);
449 RunAndCheckBounds("\"width\": 100, \"height\": 200", 0, 0, 100, 200); 512 RunAndCheckBounds("\"width\": 100, \"height\": 200", 0, 0, 100, 200);
450 RunAndCheckBounds("\"left\": 100, \"top\": 200", 100, 200, 0, 0); 513 RunAndCheckBounds("\"left\": 100, \"top\": 200", 100, 200, 0, 0);
451 RunAndCheckBounds( 514 RunAndCheckBounds(
452 "\"left\": 100, \"top\": 200, \"width\": 300, \"height\": 400", 515 "\"left\": 100, \"top\": 200, \"width\": 300, \"height\": 400",
453 100, 200, 300, 400); 516 100, 200, 300, 400);
454 } 517 }
455 518
456 } // namespace extensions 519 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/api/identity/identity_api.cc ('k') | chrome/browser/extensions/api/identity/identity_signin_flow.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698