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" | 15 #include "chrome/browser/ui/webui/signin/login_ui_service.h" |
| 16 #include "chrome/common/chrome_switches.h" | 16 #include "chrome/common/chrome_switches.h" |
| 17 #include "chrome/common/chrome_notification_types.h" | 17 #include "chrome/common/chrome_notification_types.h" |
| 18 #include "chrome/common/extensions/api/identity/oauth2_manifest_handler.h" | |
| 19 #include "chrome/common/extensions/extension_manifest_constants.h" | |
| 20 #include "chrome/common/extensions/manifest_handler.h" | |
| 18 #include "chrome/test/base/in_process_browser_test.h" | 21 #include "chrome/test/base/in_process_browser_test.h" |
| 19 #include "content/public/browser/notification_service.h" | 22 #include "content/public/browser/notification_service.h" |
| 20 #include "content/public/browser/notification_source.h" | 23 #include "content/public/browser/notification_source.h" |
| 21 #include "content/public/test/test_utils.h" | 24 #include "content/public/test/test_utils.h" |
| 22 #include "google_apis/gaia/google_service_auth_error.h" | 25 #include "google_apis/gaia/google_service_auth_error.h" |
| 23 #include "google_apis/gaia/oauth2_mint_token_flow.h" | 26 #include "google_apis/gaia/oauth2_mint_token_flow.h" |
| 24 #include "googleurl/src/gurl.h" | 27 #include "googleurl/src/gurl.h" |
| 25 #include "testing/gmock/include/gmock/gmock.h" | 28 #include "testing/gmock/include/gmock/gmock.h" |
| 26 #include "testing/gtest/include/gtest/gtest.h" | 29 #include "testing/gtest/include/gtest/gtest.h" |
| 27 | 30 |
| 28 using extensions::Extension; | |
| 29 using extensions::IdentityGetAuthTokenFunction; | |
| 30 using extensions::IdentityLaunchWebAuthFlowFunction; | |
| 31 using testing::_; | 31 using testing::_; |
| 32 using testing::Return; | 32 using testing::Return; |
| 33 using testing::ReturnRef; | 33 using testing::ReturnRef; |
| 34 | 34 |
| 35 namespace errors = extensions::identity_constants; | 35 namespace extensions { |
| 36 | |
| 37 namespace errors = identity_constants; | |
| 36 namespace utils = extension_function_test_utils; | 38 namespace utils = extension_function_test_utils; |
| 37 | 39 |
| 38 namespace { | |
|
Devlin
2013/01/16 23:25:40
Why remove this?
SanjoyPal
2013/01/17 00:11:13
which one?
Devlin
2013/01/17 10:04:59
The anonymous namespace. It won't break anything t
SanjoyPal
2013/01/17 19:13:43
Done.
| |
| 39 | |
| 40 static const char kAccessToken[] = "auth_token"; | 40 static const char kAccessToken[] = "auth_token"; |
| 41 | 41 |
| 42 class TestLoginUI : public LoginUIService::LoginUI { | 42 class TestLoginUI : public LoginUIService::LoginUI { |
| 43 public: | 43 public: |
| 44 virtual void FocusUI() OVERRIDE {} | 44 virtual void FocusUI() OVERRIDE {} |
| 45 virtual void CloseUI() OVERRIDE {} | 45 virtual void CloseUI() OVERRIDE {} |
| 46 }; | 46 }; |
| 47 | 47 |
| 48 class TestOAuth2MintTokenFlow : public OAuth2MintTokenFlow { | 48 class TestOAuth2MintTokenFlow : public OAuth2MintTokenFlow { |
| 49 public: | 49 public: |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 78 break; | 78 break; |
| 79 } | 79 } |
| 80 } | 80 } |
| 81 } | 81 } |
| 82 | 82 |
| 83 private: | 83 private: |
| 84 ResultType result_; | 84 ResultType result_; |
| 85 OAuth2MintTokenFlow::Delegate* delegate_; | 85 OAuth2MintTokenFlow::Delegate* delegate_; |
| 86 }; | 86 }; |
| 87 | 87 |
| 88 } // namespace | |
| 89 | |
| 90 class MockGetAuthTokenFunction : public IdentityGetAuthTokenFunction { | 88 class MockGetAuthTokenFunction : public IdentityGetAuthTokenFunction { |
| 91 public: | 89 public: |
| 92 MockGetAuthTokenFunction() : install_ui_result_(false), | 90 MockGetAuthTokenFunction() : install_ui_result_(false), |
| 93 login_ui_shown_(false), | 91 login_ui_shown_(false), |
| 94 install_ui_shown_(false) { | 92 install_ui_shown_(false) { |
| 95 } | 93 } |
| 96 | 94 |
| 97 void set_install_ui_result(bool result) { | 95 void set_install_ui_result(bool result) { |
| 98 install_ui_result_ = result; | 96 install_ui_result_ = result; |
| 99 } | 97 } |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 147 NONE = 0, | 145 NONE = 0, |
| 148 CLIENT_ID = 1, | 146 CLIENT_ID = 1, |
| 149 SCOPES = 2 | 147 SCOPES = 2 |
| 150 }; | 148 }; |
| 151 | 149 |
| 152 ~GetAuthTokenFunctionTest() {} | 150 ~GetAuthTokenFunctionTest() {} |
| 153 | 151 |
| 154 // Helper to create an extension with specific OAuth2Info fields set. | 152 // Helper to create an extension with specific OAuth2Info fields set. |
| 155 // |fields_to_set| should be computed by using fields of Oauth2Fields enum. | 153 // |fields_to_set| should be computed by using fields of Oauth2Fields enum. |
| 156 const Extension* CreateExtension(int fields_to_set) { | 154 const Extension* CreateExtension(int fields_to_set) { |
| 155 ManifestHandler::Register(extension_manifest_keys::kOAuth2, | |
|
Devlin
2013/01/16 23:25:40
This registration should probably be done in a Set
SanjoyPal
2013/01/17 00:11:13
Done.
| |
| 156 new OAuth2ManifestHandler); | |
| 157 const Extension* ext = LoadExtension( | 157 const Extension* ext = LoadExtension( |
| 158 test_data_dir_.AppendASCII("platform_apps/oauth2")); | 158 test_data_dir_.AppendASCII("platform_apps/oauth2")); |
| 159 Extension::OAuth2Info& oauth2_info = const_cast<Extension::OAuth2Info&>( | 159 OAuth2Info& oauth2_info = const_cast<OAuth2Info&>( |
| 160 ext->oauth2_info()); | 160 OAuth2Info::GetOAuth2Info(ext)); |
| 161 if ((fields_to_set & CLIENT_ID) != 0) | 161 if ((fields_to_set & CLIENT_ID) != 0) |
| 162 oauth2_info.client_id = "client1"; | 162 oauth2_info.client_id = "client1"; |
| 163 if ((fields_to_set & SCOPES) != 0) { | 163 if ((fields_to_set & SCOPES) != 0) { |
| 164 oauth2_info.scopes.push_back("scope1"); | 164 oauth2_info.scopes.push_back("scope1"); |
| 165 oauth2_info.scopes.push_back("scope2"); | 165 oauth2_info.scopes.push_back("scope2"); |
| 166 } | 166 } |
| 167 return ext; | 167 return ext; |
| 168 } | 168 } |
| 169 }; | 169 }; |
| 170 | 170 |
| (...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 405 int expected_x, | 405 int expected_x, |
| 406 int expected_y, | 406 int expected_y, |
| 407 int expected_width, | 407 int expected_width, |
| 408 int expected_height) { | 408 int expected_height) { |
| 409 content::WindowedNotificationObserver observer( | 409 content::WindowedNotificationObserver observer( |
| 410 chrome::NOTIFICATION_BROWSER_WINDOW_READY, | 410 chrome::NOTIFICATION_BROWSER_WINDOW_READY, |
| 411 content::NotificationService::AllSources()); | 411 content::NotificationService::AllSources()); |
| 412 | 412 |
| 413 scoped_refptr<IdentityLaunchWebAuthFlowFunction> function( | 413 scoped_refptr<IdentityLaunchWebAuthFlowFunction> function( |
| 414 new IdentityLaunchWebAuthFlowFunction()); | 414 new IdentityLaunchWebAuthFlowFunction()); |
| 415 scoped_refptr<extensions::Extension> empty_extension( | 415 scoped_refptr<Extension> empty_extension( |
| 416 utils::CreateEmptyExtension()); | 416 utils::CreateEmptyExtension()); |
| 417 function->set_extension(empty_extension.get()); | 417 function->set_extension(empty_extension.get()); |
| 418 std::string args = base::StringPrintf( | 418 std::string args = base::StringPrintf( |
| 419 "[{\"interactive\": true, \"url\": \"data:text/html,auth\"%s%s}]", | 419 "[{\"interactive\": true, \"url\": \"data:text/html,auth\"%s%s}]", |
| 420 extra_params.length() ? "," : "", | 420 extra_params.length() ? "," : "", |
| 421 extra_params.c_str()); | 421 extra_params.c_str()); |
| 422 scoped_ptr<base::ListValue> parsed_args(utils::ParseList(args)); | 422 scoped_ptr<base::ListValue> parsed_args(utils::ParseList(args)); |
| 423 EXPECT_TRUE(parsed_args.get()) << | 423 EXPECT_TRUE(parsed_args.get()) << |
| 424 "Could not parse extension function arguments: " << args; | 424 "Could not parse extension function arguments: " << args; |
| 425 function->SetArgs(parsed_args.get()); | 425 function->SetArgs(parsed_args.get()); |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 445 }; | 445 }; |
| 446 | 446 |
| 447 IN_PROC_BROWSER_TEST_F(LaunchWebAuthFlowFunctionTest, Bounds) { | 447 IN_PROC_BROWSER_TEST_F(LaunchWebAuthFlowFunctionTest, Bounds) { |
| 448 RunAndCheckBounds("", 0, 0, 0, 0); | 448 RunAndCheckBounds("", 0, 0, 0, 0); |
| 449 RunAndCheckBounds("\"width\": 100, \"height\": 200", 0, 0, 100, 200); | 449 RunAndCheckBounds("\"width\": 100, \"height\": 200", 0, 0, 100, 200); |
| 450 RunAndCheckBounds("\"left\": 100, \"top\": 200", 100, 200, 0, 0); | 450 RunAndCheckBounds("\"left\": 100, \"top\": 200", 100, 200, 0, 0); |
| 451 RunAndCheckBounds( | 451 RunAndCheckBounds( |
| 452 "\"left\": 100, \"top\": 200, \"width\": 300, \"height\": 400", | 452 "\"left\": 100, \"top\": 200, \"width\": 300, \"height\": 400", |
| 453 100, 200, 300, 400); | 453 100, 200, 300, 400); |
| 454 } | 454 } |
| 455 | |
| 456 } // namespace extensions | |
| OLD | NEW |