Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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)); | |
|
Pete Williamson
2013/03/27 18:03:55
This seems like we are just testing that the retur
Michael Courage
2013/03/27 18:40:11
StartsWithASCII verifies that error starts with er
| |
| 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); |
| 265 EXPECT_TRUE(func->login_ui_shown()); | |
| 266 EXPECT_FALSE(func->install_ui_shown()); | |
| 267 } | |
| 268 | |
| 269 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, | |
| 270 InteractiveLoginSuccessNoToken) { | |
| 271 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); | |
| 272 func->set_extension(CreateExtension(CLIENT_ID | SCOPES)); | |
| 273 EXPECT_CALL(*func.get(), HasLoginToken()).WillOnce(Return(false)); | |
| 274 func->set_login_ui_result(false); | |
| 275 std::string error = utils::RunFunctionAndReturnError( | |
| 276 func.get(), "[{\"interactive\": true}]", browser()); | |
| 277 EXPECT_EQ(std::string(errors::kUserNotSignedIn), error); | |
| 249 EXPECT_TRUE(func->login_ui_shown()); | 278 EXPECT_TRUE(func->login_ui_shown()); |
| 250 EXPECT_FALSE(func->install_ui_shown()); | 279 EXPECT_FALSE(func->install_ui_shown()); |
| 251 } | 280 } |
| 252 | 281 |
| 253 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, | 282 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, |
| 254 InteractiveLoginSuccessMintFailure) { | 283 InteractiveLoginSuccessMintFailure) { |
| 255 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); | 284 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); |
| 256 func->set_extension(CreateExtension(CLIENT_ID | SCOPES)); | 285 func->set_extension(CreateExtension(CLIENT_ID | SCOPES)); |
| 257 EXPECT_CALL(*func.get(), HasLoginToken()) | 286 EXPECT_CALL(*func.get(), HasLoginToken()) |
| 258 .WillOnce(Return(false)) | 287 .WillOnce(Return(false)); |
| 259 .WillOnce(Return(true)); | 288 func->set_login_ui_result(true); |
| 260 TestOAuth2MintTokenFlow* flow = new TestOAuth2MintTokenFlow( | 289 TestOAuth2MintTokenFlow* flow = new TestOAuth2MintTokenFlow( |
| 261 TestOAuth2MintTokenFlow::MINT_TOKEN_FAILURE, func.get()); | 290 TestOAuth2MintTokenFlow::MINT_TOKEN_FAILURE, func.get()); |
| 262 EXPECT_CALL(*func.get(), CreateMintTokenFlow(_)).WillOnce(Return(flow)); | 291 EXPECT_CALL(*func.get(), CreateMintTokenFlow(_)).WillOnce(Return(flow)); |
| 263 std::string error = utils::RunFunctionAndReturnError( | 292 std::string error = utils::RunFunctionAndReturnError( |
| 264 func.get(), "[{\"interactive\": true}]", browser()); | 293 func.get(), "[{\"interactive\": true}]", browser()); |
| 265 EXPECT_TRUE(StartsWithASCII(error, errors::kAuthFailure, false)); | 294 EXPECT_TRUE(StartsWithASCII(error, errors::kAuthFailure, false)); |
| 266 EXPECT_TRUE(func->login_ui_shown()); | 295 EXPECT_TRUE(func->login_ui_shown()); |
| 267 EXPECT_FALSE(func->install_ui_shown()); | 296 EXPECT_FALSE(func->install_ui_shown()); |
| 268 } | 297 } |
| 269 | 298 |
| 270 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, | 299 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, |
| 271 InteractiveLoginSuccessMintSuccess) { | 300 InteractiveLoginSuccessMintSuccess) { |
| 272 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); | 301 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); |
| 273 func->set_extension(CreateExtension(CLIENT_ID | SCOPES)); | 302 func->set_extension(CreateExtension(CLIENT_ID | SCOPES)); |
| 274 EXPECT_CALL(*func.get(), HasLoginToken()) | 303 EXPECT_CALL(*func.get(), HasLoginToken()) |
| 275 .WillOnce(Return(false)) | 304 .WillOnce(Return(false)); |
| 276 .WillOnce(Return(true)); | 305 func->set_login_ui_result(true); |
| 277 TestOAuth2MintTokenFlow* flow = new TestOAuth2MintTokenFlow( | 306 TestOAuth2MintTokenFlow* flow = new TestOAuth2MintTokenFlow( |
| 278 TestOAuth2MintTokenFlow::MINT_TOKEN_SUCCESS, func.get()); | 307 TestOAuth2MintTokenFlow::MINT_TOKEN_SUCCESS, func.get()); |
| 279 EXPECT_CALL(*func.get(), CreateMintTokenFlow(_)).WillOnce(Return(flow)); | 308 EXPECT_CALL(*func.get(), CreateMintTokenFlow(_)).WillOnce(Return(flow)); |
| 280 scoped_ptr<base::Value> value(utils::RunFunctionAndReturnSingleResult( | 309 scoped_ptr<base::Value> value(utils::RunFunctionAndReturnSingleResult( |
| 281 func.get(), "[{\"interactive\": true}]", browser())); | 310 func.get(), "[{\"interactive\": true}]", browser())); |
| 282 std::string access_token; | 311 std::string access_token; |
| 283 EXPECT_TRUE(value->GetAsString(&access_token)); | 312 EXPECT_TRUE(value->GetAsString(&access_token)); |
| 284 EXPECT_EQ(std::string(kAccessToken), access_token); | 313 EXPECT_EQ(std::string(kAccessToken), access_token); |
| 285 EXPECT_TRUE(func->login_ui_shown()); | 314 EXPECT_TRUE(func->login_ui_shown()); |
| 286 EXPECT_FALSE(func->install_ui_shown()); | 315 EXPECT_FALSE(func->install_ui_shown()); |
| 287 } | 316 } |
| 288 | 317 |
| 289 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, | 318 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, |
| 290 InteractiveLoginSuccessApprovalAborted) { | 319 InteractiveLoginSuccessApprovalAborted) { |
| 291 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); | 320 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); |
| 292 func->set_extension(CreateExtension(CLIENT_ID | SCOPES)); | 321 func->set_extension(CreateExtension(CLIENT_ID | SCOPES)); |
| 293 EXPECT_CALL(*func.get(), HasLoginToken()) | 322 EXPECT_CALL(*func.get(), HasLoginToken()) |
| 294 .WillOnce(Return(false)) | 323 .WillOnce(Return(false)); |
| 295 .WillOnce(Return(true)); | 324 func->set_login_ui_result(true); |
| 296 TestOAuth2MintTokenFlow* flow = new TestOAuth2MintTokenFlow( | 325 TestOAuth2MintTokenFlow* flow = new TestOAuth2MintTokenFlow( |
| 297 TestOAuth2MintTokenFlow::ISSUE_ADVICE_SUCCESS, func.get()); | 326 TestOAuth2MintTokenFlow::ISSUE_ADVICE_SUCCESS, func.get()); |
| 298 EXPECT_CALL(*func.get(), CreateMintTokenFlow(_)).WillOnce(Return(flow)); | 327 EXPECT_CALL(*func.get(), CreateMintTokenFlow(_)).WillOnce(Return(flow)); |
| 299 func->set_install_ui_result(false); | 328 func->set_install_ui_result(false); |
| 300 std::string error = utils::RunFunctionAndReturnError( | 329 std::string error = utils::RunFunctionAndReturnError( |
| 301 func.get(), "[{\"interactive\": true}]", browser()); | 330 func.get(), "[{\"interactive\": true}]", browser()); |
| 302 EXPECT_EQ(std::string(errors::kUserRejected), error); | 331 EXPECT_EQ(std::string(errors::kUserRejected), error); |
| 303 EXPECT_TRUE(func->login_ui_shown()); | 332 EXPECT_TRUE(func->login_ui_shown()); |
| 304 EXPECT_TRUE(func->install_ui_shown()); | 333 EXPECT_TRUE(func->install_ui_shown()); |
| 305 } | 334 } |
| 306 | 335 |
| 307 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, | 336 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, |
| 308 InteractiveLoginSuccessApprovalDoneMintFailure) { | 337 InteractiveLoginSuccessApprovalDoneMintFailure) { |
| 309 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); | 338 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); |
| 310 func->set_extension(CreateExtension(CLIENT_ID | SCOPES)); | 339 func->set_extension(CreateExtension(CLIENT_ID | SCOPES)); |
| 311 EXPECT_CALL(*func.get(), HasLoginToken()) | 340 EXPECT_CALL(*func.get(), HasLoginToken()) |
| 312 .WillOnce(Return(false)) | 341 .WillOnce(Return(false)); |
| 313 .WillOnce(Return(true)) | 342 func->set_login_ui_result(true); |
| 314 .WillOnce(Return(true)); | |
| 315 TestOAuth2MintTokenFlow* flow1 = new TestOAuth2MintTokenFlow( | 343 TestOAuth2MintTokenFlow* flow1 = new TestOAuth2MintTokenFlow( |
| 316 TestOAuth2MintTokenFlow::ISSUE_ADVICE_SUCCESS, func.get()); | 344 TestOAuth2MintTokenFlow::ISSUE_ADVICE_SUCCESS, func.get()); |
| 317 TestOAuth2MintTokenFlow* flow2 = new TestOAuth2MintTokenFlow( | 345 TestOAuth2MintTokenFlow* flow2 = new TestOAuth2MintTokenFlow( |
| 318 TestOAuth2MintTokenFlow::MINT_TOKEN_FAILURE, func.get()); | 346 TestOAuth2MintTokenFlow::MINT_TOKEN_FAILURE, func.get()); |
| 319 EXPECT_CALL(*func.get(), CreateMintTokenFlow(_)) | 347 EXPECT_CALL(*func.get(), CreateMintTokenFlow(_)) |
| 320 .WillOnce(Return(flow1)) | 348 .WillOnce(Return(flow1)) |
| 321 .WillOnce(Return(flow2)); | 349 .WillOnce(Return(flow2)); |
| 322 | 350 |
| 323 func->set_install_ui_result(true); | 351 func->set_install_ui_result(true); |
| 324 std::string error = utils::RunFunctionAndReturnError( | 352 std::string error = utils::RunFunctionAndReturnError( |
| 325 func.get(), "[{\"interactive\": true}]", browser()); | 353 func.get(), "[{\"interactive\": true}]", browser()); |
| 326 EXPECT_TRUE(StartsWithASCII(error, errors::kAuthFailure, false)); | 354 EXPECT_TRUE(StartsWithASCII(error, errors::kAuthFailure, false)); |
| 327 EXPECT_TRUE(func->login_ui_shown()); | 355 EXPECT_TRUE(func->login_ui_shown()); |
| 328 EXPECT_TRUE(func->install_ui_shown()); | 356 EXPECT_TRUE(func->install_ui_shown()); |
| 329 } | 357 } |
| 330 | 358 |
| 331 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, | 359 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, |
| 332 InteractiveLoginSuccessApprovalDoneMintSuccess) { | 360 InteractiveLoginSuccessApprovalDoneMintSuccess) { |
| 333 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); | 361 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); |
| 334 func->set_extension(CreateExtension(CLIENT_ID | SCOPES)); | 362 func->set_extension(CreateExtension(CLIENT_ID | SCOPES)); |
| 335 EXPECT_CALL(*func.get(), HasLoginToken()) | 363 EXPECT_CALL(*func.get(), HasLoginToken()) |
| 336 .WillOnce(Return(false)) | 364 .WillOnce(Return(false)); |
| 337 .WillOnce(Return(true)) | 365 func->set_login_ui_result(true); |
| 338 .WillOnce(Return(true)); | |
| 339 TestOAuth2MintTokenFlow* flow1 = new TestOAuth2MintTokenFlow( | 366 TestOAuth2MintTokenFlow* flow1 = new TestOAuth2MintTokenFlow( |
| 340 TestOAuth2MintTokenFlow::ISSUE_ADVICE_SUCCESS, func.get()); | 367 TestOAuth2MintTokenFlow::ISSUE_ADVICE_SUCCESS, func.get()); |
| 341 TestOAuth2MintTokenFlow* flow2 = new TestOAuth2MintTokenFlow( | 368 TestOAuth2MintTokenFlow* flow2 = new TestOAuth2MintTokenFlow( |
| 342 TestOAuth2MintTokenFlow::MINT_TOKEN_SUCCESS, func.get()); | 369 TestOAuth2MintTokenFlow::MINT_TOKEN_SUCCESS, func.get()); |
| 343 EXPECT_CALL(*func.get(), CreateMintTokenFlow(_)) | 370 EXPECT_CALL(*func.get(), CreateMintTokenFlow(_)) |
| 344 .WillOnce(Return(flow1)) | 371 .WillOnce(Return(flow1)) |
| 345 .WillOnce(Return(flow2)); | 372 .WillOnce(Return(flow2)); |
| 346 | 373 |
| 347 func->set_install_ui_result(true); | 374 func->set_install_ui_result(true); |
| 348 scoped_ptr<base::Value> value(utils::RunFunctionAndReturnSingleResult( | 375 scoped_ptr<base::Value> value(utils::RunFunctionAndReturnSingleResult( |
| 349 func.get(), "[{\"interactive\": true}]", browser())); | 376 func.get(), "[{\"interactive\": true}]", browser())); |
| 350 std::string access_token; | 377 std::string access_token; |
| 351 EXPECT_TRUE(value->GetAsString(&access_token)); | 378 EXPECT_TRUE(value->GetAsString(&access_token)); |
| 352 EXPECT_EQ(std::string(kAccessToken), access_token); | 379 EXPECT_EQ(std::string(kAccessToken), access_token); |
| 353 EXPECT_TRUE(func->login_ui_shown()); | 380 EXPECT_TRUE(func->login_ui_shown()); |
| 354 EXPECT_TRUE(func->install_ui_shown()); | 381 EXPECT_TRUE(func->install_ui_shown()); |
| 355 } | 382 } |
| 356 | 383 |
| 357 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, | 384 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, |
| 358 InteractiveApprovalAborted) { | 385 InteractiveApprovalAborted) { |
| 359 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); | 386 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); |
| 360 func->set_extension(CreateExtension(CLIENT_ID | SCOPES)); | 387 func->set_extension(CreateExtension(CLIENT_ID | SCOPES)); |
| 361 EXPECT_CALL(*func.get(), HasLoginToken()) | 388 EXPECT_CALL(*func.get(), HasLoginToken()) |
| 362 .WillOnce(Return(true)) | |
| 363 .WillOnce(Return(true)); | 389 .WillOnce(Return(true)); |
| 364 TestOAuth2MintTokenFlow* flow = new TestOAuth2MintTokenFlow( | 390 TestOAuth2MintTokenFlow* flow = new TestOAuth2MintTokenFlow( |
| 365 TestOAuth2MintTokenFlow::ISSUE_ADVICE_SUCCESS, func.get()); | 391 TestOAuth2MintTokenFlow::ISSUE_ADVICE_SUCCESS, func.get()); |
| 366 EXPECT_CALL(*func.get(), CreateMintTokenFlow(_)).WillOnce(Return(flow)); | 392 EXPECT_CALL(*func.get(), CreateMintTokenFlow(_)).WillOnce(Return(flow)); |
| 367 func->set_install_ui_result(false); | 393 func->set_install_ui_result(false); |
| 368 std::string error = utils::RunFunctionAndReturnError( | 394 std::string error = utils::RunFunctionAndReturnError( |
| 369 func.get(), "[{\"interactive\": true}]", browser()); | 395 func.get(), "[{\"interactive\": true}]", browser()); |
| 370 EXPECT_EQ(std::string(errors::kUserRejected), error); | 396 EXPECT_EQ(std::string(errors::kUserRejected), error); |
| 371 EXPECT_FALSE(func->login_ui_shown()); | 397 EXPECT_FALSE(func->login_ui_shown()); |
| 372 EXPECT_TRUE(func->install_ui_shown()); | 398 EXPECT_TRUE(func->install_ui_shown()); |
| 373 } | 399 } |
| 374 | 400 |
| 375 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, | 401 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, |
| 376 InteractiveApprovalDoneMintSuccess) { | 402 InteractiveApprovalDoneMintSuccess) { |
| 377 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); | 403 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); |
| 378 func->set_extension(CreateExtension(CLIENT_ID | SCOPES)); | 404 func->set_extension(CreateExtension(CLIENT_ID | SCOPES)); |
| 379 EXPECT_CALL(*func.get(), HasLoginToken()) | 405 EXPECT_CALL(*func.get(), HasLoginToken()) |
| 380 .WillOnce(Return(true)) | |
| 381 .WillOnce(Return(true)) | |
| 382 .WillOnce(Return(true)); | 406 .WillOnce(Return(true)); |
| 383 TestOAuth2MintTokenFlow* flow1 = new TestOAuth2MintTokenFlow( | 407 TestOAuth2MintTokenFlow* flow1 = new TestOAuth2MintTokenFlow( |
| 384 TestOAuth2MintTokenFlow::ISSUE_ADVICE_SUCCESS, func.get()); | 408 TestOAuth2MintTokenFlow::ISSUE_ADVICE_SUCCESS, func.get()); |
| 385 TestOAuth2MintTokenFlow* flow2 = new TestOAuth2MintTokenFlow( | 409 TestOAuth2MintTokenFlow* flow2 = new TestOAuth2MintTokenFlow( |
| 386 TestOAuth2MintTokenFlow::MINT_TOKEN_SUCCESS, func.get()); | 410 TestOAuth2MintTokenFlow::MINT_TOKEN_SUCCESS, func.get()); |
| 387 EXPECT_CALL(*func.get(), CreateMintTokenFlow(_)) | 411 EXPECT_CALL(*func.get(), CreateMintTokenFlow(_)) |
| 388 .WillOnce(Return(flow1)) | 412 .WillOnce(Return(flow1)) |
| 389 .WillOnce(Return(flow2)); | 413 .WillOnce(Return(flow2)); |
| 390 | 414 |
| 391 func->set_install_ui_result(true); | 415 func->set_install_ui_result(true); |
| 392 scoped_ptr<base::Value> value(utils::RunFunctionAndReturnSingleResult( | 416 scoped_ptr<base::Value> value(utils::RunFunctionAndReturnSingleResult( |
| 393 func.get(), "[{\"interactive\": true}]", browser())); | 417 func.get(), "[{\"interactive\": true}]", browser())); |
| 394 std::string access_token; | 418 std::string access_token; |
| 395 EXPECT_TRUE(value->GetAsString(&access_token)); | 419 EXPECT_TRUE(value->GetAsString(&access_token)); |
| 396 EXPECT_EQ(std::string(kAccessToken), access_token); | 420 EXPECT_EQ(std::string(kAccessToken), access_token); |
| 397 EXPECT_FALSE(func->login_ui_shown()); | 421 EXPECT_FALSE(func->login_ui_shown()); |
| 398 EXPECT_TRUE(func->install_ui_shown()); | 422 EXPECT_TRUE(func->install_ui_shown()); |
| 399 } | 423 } |
| 400 | 424 |
| 425 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, | |
| 426 InteractiveApprovalDoneMintBadCredentials) { | |
| 427 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); | |
| 428 func->set_extension(CreateExtension(CLIENT_ID | SCOPES)); | |
| 429 EXPECT_CALL(*func.get(), HasLoginToken()) | |
| 430 .WillOnce(Return(true)); | |
| 431 TestOAuth2MintTokenFlow* flow1 = new TestOAuth2MintTokenFlow( | |
| 432 TestOAuth2MintTokenFlow::ISSUE_ADVICE_SUCCESS, func.get()); | |
| 433 TestOAuth2MintTokenFlow* flow2 = new TestOAuth2MintTokenFlow( | |
| 434 TestOAuth2MintTokenFlow::MINT_TOKEN_BAD_CREDENTIALS, func.get()); | |
| 435 EXPECT_CALL(*func.get(), CreateMintTokenFlow(_)) | |
| 436 .WillOnce(Return(flow1)) | |
| 437 .WillOnce(Return(flow2)); | |
| 438 | |
| 439 func->set_install_ui_result(true); | |
| 440 std::string error = utils::RunFunctionAndReturnError( | |
| 441 func.get(), "[{\"interactive\": true}]", browser()); | |
| 442 EXPECT_TRUE(StartsWithASCII(error, errors::kAuthFailure, false)); | |
| 443 EXPECT_FALSE(func->login_ui_shown()); | |
| 444 EXPECT_TRUE(func->install_ui_shown()); | |
| 445 } | |
| 446 | |
| 401 class LaunchWebAuthFlowFunctionTest : public ExtensionBrowserTest { | 447 class LaunchWebAuthFlowFunctionTest : public ExtensionBrowserTest { |
| 402 protected: | 448 protected: |
| 403 void RunAndCheckBounds( | 449 void RunAndCheckBounds( |
| 404 const std::string& extra_params, | 450 const std::string& extra_params, |
| 405 int expected_x, | 451 int expected_x, |
| 406 int expected_y, | 452 int expected_y, |
| 407 int expected_width, | 453 int expected_width, |
| 408 int expected_height) { | 454 int expected_height) { |
| 409 content::WindowedNotificationObserver observer( | 455 content::WindowedNotificationObserver observer( |
| 410 chrome::NOTIFICATION_BROWSER_WINDOW_READY, | 456 chrome::NOTIFICATION_BROWSER_WINDOW_READY, |
| 411 content::NotificationService::AllSources()); | 457 content::NotificationService::AllSources()); |
| 412 | 458 |
| 413 scoped_refptr<IdentityLaunchWebAuthFlowFunction> function( | 459 scoped_refptr<IdentityLaunchWebAuthFlowFunction> function( |
| 414 new IdentityLaunchWebAuthFlowFunction()); | 460 new IdentityLaunchWebAuthFlowFunction()); |
| 415 scoped_refptr<Extension> empty_extension( | 461 scoped_refptr<Extension> empty_extension( |
| 416 utils::CreateEmptyExtension()); | 462 utils::CreateEmptyExtension()); |
| 417 function->set_extension(empty_extension.get()); | 463 function->set_extension(empty_extension.get()); |
| 418 std::string args = base::StringPrintf( | 464 std::string args = base::StringPrintf( |
| 419 "[{\"interactive\": true, \"url\": \"data:text/html,auth\"%s%s}]", | 465 "[{\"interactive\": true, \"url\": \"data:text/html,auth\"%s%s}]", |
| 420 extra_params.length() ? "," : "", | 466 extra_params.length() ? "," : "", |
| 421 extra_params.c_str()); | 467 extra_params.c_str()); |
| 422 scoped_ptr<base::ListValue> parsed_args(utils::ParseList(args)); | 468 scoped_ptr<base::ListValue> parsed_args(utils::ParseList(args)); |
| 423 EXPECT_TRUE(parsed_args.get()) << | 469 EXPECT_TRUE(parsed_args.get()) << |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 447 IN_PROC_BROWSER_TEST_F(LaunchWebAuthFlowFunctionTest, Bounds) { | 493 IN_PROC_BROWSER_TEST_F(LaunchWebAuthFlowFunctionTest, Bounds) { |
| 448 RunAndCheckBounds("", 0, 0, 0, 0); | 494 RunAndCheckBounds("", 0, 0, 0, 0); |
| 449 RunAndCheckBounds("\"width\": 100, \"height\": 200", 0, 0, 100, 200); | 495 RunAndCheckBounds("\"width\": 100, \"height\": 200", 0, 0, 100, 200); |
| 450 RunAndCheckBounds("\"left\": 100, \"top\": 200", 100, 200, 0, 0); | 496 RunAndCheckBounds("\"left\": 100, \"top\": 200", 100, 200, 0, 0); |
| 451 RunAndCheckBounds( | 497 RunAndCheckBounds( |
| 452 "\"left\": 100, \"top\": 200, \"width\": 300, \"height\": 400", | 498 "\"left\": 100, \"top\": 200, \"width\": 300, \"height\": 400", |
| 453 100, 200, 300, 400); | 499 100, 200, 300, 400); |
| 454 } | 500 } |
| 455 | 501 |
| 456 } // namespace extensions | 502 } // namespace extensions |
| OLD | NEW |