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; | 31 using extensions::Extension; |
Devlin
2013/01/16 20:26:40
These using statements can be removed now (as can
SanjoyPal
2013/01/16 23:03:13
Done.
| |
29 using extensions::IdentityGetAuthTokenFunction; | 32 using extensions::IdentityGetAuthTokenFunction; |
30 using extensions::IdentityLaunchWebAuthFlowFunction; | 33 using extensions::IdentityLaunchWebAuthFlowFunction; |
31 using testing::_; | 34 using testing::_; |
32 using testing::Return; | 35 using testing::Return; |
33 using testing::ReturnRef; | 36 using testing::ReturnRef; |
34 | 37 |
35 namespace errors = extensions::identity_constants; | 38 namespace extensions { |
39 | |
40 namespace errors = identity_constants; | |
36 namespace utils = extension_function_test_utils; | 41 namespace utils = extension_function_test_utils; |
37 | 42 |
38 namespace { | |
39 | |
40 static const char kAccessToken[] = "auth_token"; | 43 static const char kAccessToken[] = "auth_token"; |
41 | 44 |
42 class TestLoginUI : public LoginUIService::LoginUI { | 45 class TestLoginUI : public LoginUIService::LoginUI { |
43 public: | 46 public: |
44 virtual void FocusUI() OVERRIDE {} | 47 virtual void FocusUI() OVERRIDE {} |
45 virtual void CloseUI() OVERRIDE {} | 48 virtual void CloseUI() OVERRIDE {} |
46 }; | 49 }; |
47 | 50 |
48 class TestOAuth2MintTokenFlow : public OAuth2MintTokenFlow { | 51 class TestOAuth2MintTokenFlow : public OAuth2MintTokenFlow { |
49 public: | 52 public: |
(...skipping 28 matching lines...) Expand all Loading... | |
78 break; | 81 break; |
79 } | 82 } |
80 } | 83 } |
81 } | 84 } |
82 | 85 |
83 private: | 86 private: |
84 ResultType result_; | 87 ResultType result_; |
85 OAuth2MintTokenFlow::Delegate* delegate_; | 88 OAuth2MintTokenFlow::Delegate* delegate_; |
86 }; | 89 }; |
87 | 90 |
88 } // namespace | |
89 | |
90 class MockGetAuthTokenFunction : public IdentityGetAuthTokenFunction { | 91 class MockGetAuthTokenFunction : public IdentityGetAuthTokenFunction { |
91 public: | 92 public: |
92 MockGetAuthTokenFunction() : install_ui_result_(false), | 93 MockGetAuthTokenFunction() : install_ui_result_(false), |
93 login_ui_shown_(false), | 94 login_ui_shown_(false), |
94 install_ui_shown_(false) { | 95 install_ui_shown_(false) { |
95 } | 96 } |
96 | 97 |
97 void set_install_ui_result(bool result) { | 98 void set_install_ui_result(bool result) { |
98 install_ui_result_ = result; | 99 install_ui_result_ = result; |
99 } | 100 } |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
147 NONE = 0, | 148 NONE = 0, |
148 CLIENT_ID = 1, | 149 CLIENT_ID = 1, |
149 SCOPES = 2 | 150 SCOPES = 2 |
150 }; | 151 }; |
151 | 152 |
152 ~GetAuthTokenFunctionTest() {} | 153 ~GetAuthTokenFunctionTest() {} |
153 | 154 |
154 // Helper to create an extension with specific OAuth2Info fields set. | 155 // Helper to create an extension with specific OAuth2Info fields set. |
155 // |fields_to_set| should be computed by using fields of Oauth2Fields enum. | 156 // |fields_to_set| should be computed by using fields of Oauth2Fields enum. |
156 const Extension* CreateExtension(int fields_to_set) { | 157 const Extension* CreateExtension(int fields_to_set) { |
158 ManifestHandler::Register(extension_manifest_keys::kOAuth2, | |
159 new OAuth2ManifestHandler); | |
157 const Extension* ext = LoadExtension( | 160 const Extension* ext = LoadExtension( |
158 test_data_dir_.AppendASCII("platform_apps/oauth2")); | 161 test_data_dir_.AppendASCII("platform_apps/oauth2")); |
159 Extension::OAuth2Info& oauth2_info = const_cast<Extension::OAuth2Info&>( | 162 OAuth2Info& oauth2_info = const_cast<OAuth2Info&>( |
160 ext->oauth2_info()); | 163 OAuth2Info::GetOAuth2Info(ext)); |
161 if ((fields_to_set & CLIENT_ID) != 0) | 164 if ((fields_to_set & CLIENT_ID) != 0) |
162 oauth2_info.client_id = "client1"; | 165 oauth2_info.client_id = "client1"; |
163 if ((fields_to_set & SCOPES) != 0) { | 166 if ((fields_to_set & SCOPES) != 0) { |
164 oauth2_info.scopes.push_back("scope1"); | 167 oauth2_info.scopes.push_back("scope1"); |
165 oauth2_info.scopes.push_back("scope2"); | 168 oauth2_info.scopes.push_back("scope2"); |
166 } | 169 } |
167 return ext; | 170 return ext; |
168 } | 171 } |
169 }; | 172 }; |
170 | 173 |
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
405 int expected_x, | 408 int expected_x, |
406 int expected_y, | 409 int expected_y, |
407 int expected_width, | 410 int expected_width, |
408 int expected_height) { | 411 int expected_height) { |
409 content::WindowedNotificationObserver observer( | 412 content::WindowedNotificationObserver observer( |
410 chrome::NOTIFICATION_BROWSER_WINDOW_READY, | 413 chrome::NOTIFICATION_BROWSER_WINDOW_READY, |
411 content::NotificationService::AllSources()); | 414 content::NotificationService::AllSources()); |
412 | 415 |
413 scoped_refptr<IdentityLaunchWebAuthFlowFunction> function( | 416 scoped_refptr<IdentityLaunchWebAuthFlowFunction> function( |
414 new IdentityLaunchWebAuthFlowFunction()); | 417 new IdentityLaunchWebAuthFlowFunction()); |
415 scoped_refptr<extensions::Extension> empty_extension( | 418 scoped_refptr<Extension> empty_extension( |
416 utils::CreateEmptyExtension()); | 419 utils::CreateEmptyExtension()); |
417 function->set_extension(empty_extension.get()); | 420 function->set_extension(empty_extension.get()); |
418 std::string args = base::StringPrintf( | 421 std::string args = base::StringPrintf( |
419 "[{\"interactive\": true, \"url\": \"data:text/html,auth\"%s%s}]", | 422 "[{\"interactive\": true, \"url\": \"data:text/html,auth\"%s%s}]", |
420 extra_params.length() ? "," : "", | 423 extra_params.length() ? "," : "", |
421 extra_params.c_str()); | 424 extra_params.c_str()); |
422 scoped_ptr<base::ListValue> parsed_args(utils::ParseList(args)); | 425 scoped_ptr<base::ListValue> parsed_args(utils::ParseList(args)); |
423 EXPECT_TRUE(parsed_args.get()) << | 426 EXPECT_TRUE(parsed_args.get()) << |
424 "Could not parse extension function arguments: " << args; | 427 "Could not parse extension function arguments: " << args; |
425 function->SetArgs(parsed_args.get()); | 428 function->SetArgs(parsed_args.get()); |
(...skipping 19 matching lines...) Expand all Loading... | |
445 }; | 448 }; |
446 | 449 |
447 IN_PROC_BROWSER_TEST_F(LaunchWebAuthFlowFunctionTest, Bounds) { | 450 IN_PROC_BROWSER_TEST_F(LaunchWebAuthFlowFunctionTest, Bounds) { |
448 RunAndCheckBounds("", 0, 0, 0, 0); | 451 RunAndCheckBounds("", 0, 0, 0, 0); |
449 RunAndCheckBounds("\"width\": 100, \"height\": 200", 0, 0, 100, 200); | 452 RunAndCheckBounds("\"width\": 100, \"height\": 200", 0, 0, 100, 200); |
450 RunAndCheckBounds("\"left\": 100, \"top\": 200", 100, 200, 0, 0); | 453 RunAndCheckBounds("\"left\": 100, \"top\": 200", 100, 200, 0, 0); |
451 RunAndCheckBounds( | 454 RunAndCheckBounds( |
452 "\"left\": 100, \"top\": 200, \"width\": 300, \"height\": 400", | 455 "\"left\": 100, \"top\": 200, \"width\": 300, \"height\": 400", |
453 100, 200, 300, 400); | 456 100, 200, 300, 400); |
454 } | 457 } |
458 | |
459 } // namespace extensions | |
OLD | NEW |