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 { | |
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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
135 MOCK_METHOD1(CreateMintTokenFlow, | 133 MOCK_METHOD1(CreateMintTokenFlow, |
136 OAuth2MintTokenFlow* (OAuth2MintTokenFlow::Mode mode)); | 134 OAuth2MintTokenFlow* (OAuth2MintTokenFlow::Mode mode)); |
137 private: | 135 private: |
138 ~MockGetAuthTokenFunction() {} | 136 ~MockGetAuthTokenFunction() {} |
139 bool install_ui_result_; | 137 bool install_ui_result_; |
140 bool login_ui_shown_; | 138 bool login_ui_shown_; |
141 bool install_ui_shown_; | 139 bool install_ui_shown_; |
142 }; | 140 }; |
143 | 141 |
144 class GetAuthTokenFunctionTest : public ExtensionBrowserTest { | 142 class GetAuthTokenFunctionTest : public ExtensionBrowserTest { |
143 public: | |
144 virtual void SetUp() { | |
Devlin
2013/01/17 10:04:59
virtual void SetUp() OVERRIDE {
SanjoyPal
2013/01/17 19:13:43
Done.
| |
145 InProcessBrowserTest::SetUp(); | |
Devlin
2013/01/17 10:04:59
Call the immediate super function (which should, i
SanjoyPal
2013/01/17 19:13:43
Done.
| |
146 ManifestHandler::Register(extension_manifest_keys::kOAuth2, | |
147 new OAuth2ManifestHandler); | |
148 } | |
145 protected: | 149 protected: |
146 enum OAuth2Fields { | 150 enum OAuth2Fields { |
147 NONE = 0, | 151 NONE = 0, |
148 CLIENT_ID = 1, | 152 CLIENT_ID = 1, |
149 SCOPES = 2 | 153 SCOPES = 2 |
150 }; | 154 }; |
151 | 155 |
152 ~GetAuthTokenFunctionTest() {} | 156 ~GetAuthTokenFunctionTest() {} |
153 | 157 |
154 // Helper to create an extension with specific OAuth2Info fields set. | 158 // Helper to create an extension with specific OAuth2Info fields set. |
155 // |fields_to_set| should be computed by using fields of Oauth2Fields enum. | 159 // |fields_to_set| should be computed by using fields of Oauth2Fields enum. |
156 const Extension* CreateExtension(int fields_to_set) { | 160 const Extension* CreateExtension(int fields_to_set) { |
157 const Extension* ext = LoadExtension( | 161 const Extension* ext = LoadExtension( |
158 test_data_dir_.AppendASCII("platform_apps/oauth2")); | 162 test_data_dir_.AppendASCII("platform_apps/oauth2")); |
159 Extension::OAuth2Info& oauth2_info = const_cast<Extension::OAuth2Info&>( | 163 OAuth2Info& oauth2_info = const_cast<OAuth2Info&>( |
160 ext->oauth2_info()); | 164 OAuth2Info::GetOAuth2Info(ext)); |
161 if ((fields_to_set & CLIENT_ID) != 0) | 165 if ((fields_to_set & CLIENT_ID) != 0) |
162 oauth2_info.client_id = "client1"; | 166 oauth2_info.client_id = "client1"; |
163 if ((fields_to_set & SCOPES) != 0) { | 167 if ((fields_to_set & SCOPES) != 0) { |
164 oauth2_info.scopes.push_back("scope1"); | 168 oauth2_info.scopes.push_back("scope1"); |
165 oauth2_info.scopes.push_back("scope2"); | 169 oauth2_info.scopes.push_back("scope2"); |
166 } | 170 } |
167 return ext; | 171 return ext; |
168 } | 172 } |
169 }; | 173 }; |
170 | 174 |
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
405 int expected_x, | 409 int expected_x, |
406 int expected_y, | 410 int expected_y, |
407 int expected_width, | 411 int expected_width, |
408 int expected_height) { | 412 int expected_height) { |
409 content::WindowedNotificationObserver observer( | 413 content::WindowedNotificationObserver observer( |
410 chrome::NOTIFICATION_BROWSER_WINDOW_READY, | 414 chrome::NOTIFICATION_BROWSER_WINDOW_READY, |
411 content::NotificationService::AllSources()); | 415 content::NotificationService::AllSources()); |
412 | 416 |
413 scoped_refptr<IdentityLaunchWebAuthFlowFunction> function( | 417 scoped_refptr<IdentityLaunchWebAuthFlowFunction> function( |
414 new IdentityLaunchWebAuthFlowFunction()); | 418 new IdentityLaunchWebAuthFlowFunction()); |
415 scoped_refptr<extensions::Extension> empty_extension( | 419 scoped_refptr<Extension> empty_extension( |
416 utils::CreateEmptyExtension()); | 420 utils::CreateEmptyExtension()); |
417 function->set_extension(empty_extension.get()); | 421 function->set_extension(empty_extension.get()); |
418 std::string args = base::StringPrintf( | 422 std::string args = base::StringPrintf( |
419 "[{\"interactive\": true, \"url\": \"data:text/html,auth\"%s%s}]", | 423 "[{\"interactive\": true, \"url\": \"data:text/html,auth\"%s%s}]", |
420 extra_params.length() ? "," : "", | 424 extra_params.length() ? "," : "", |
421 extra_params.c_str()); | 425 extra_params.c_str()); |
422 scoped_ptr<base::ListValue> parsed_args(utils::ParseList(args)); | 426 scoped_ptr<base::ListValue> parsed_args(utils::ParseList(args)); |
423 EXPECT_TRUE(parsed_args.get()) << | 427 EXPECT_TRUE(parsed_args.get()) << |
424 "Could not parse extension function arguments: " << args; | 428 "Could not parse extension function arguments: " << args; |
425 function->SetArgs(parsed_args.get()); | 429 function->SetArgs(parsed_args.get()); |
(...skipping 19 matching lines...) Expand all Loading... | |
445 }; | 449 }; |
446 | 450 |
447 IN_PROC_BROWSER_TEST_F(LaunchWebAuthFlowFunctionTest, Bounds) { | 451 IN_PROC_BROWSER_TEST_F(LaunchWebAuthFlowFunctionTest, Bounds) { |
448 RunAndCheckBounds("", 0, 0, 0, 0); | 452 RunAndCheckBounds("", 0, 0, 0, 0); |
449 RunAndCheckBounds("\"width\": 100, \"height\": 200", 0, 0, 100, 200); | 453 RunAndCheckBounds("\"width\": 100, \"height\": 200", 0, 0, 100, 200); |
450 RunAndCheckBounds("\"left\": 100, \"top\": 200", 100, 200, 0, 0); | 454 RunAndCheckBounds("\"left\": 100, \"top\": 200", 100, 200, 0, 0); |
451 RunAndCheckBounds( | 455 RunAndCheckBounds( |
452 "\"left\": 100, \"top\": 200, \"width\": 300, \"height\": 400", | 456 "\"left\": 100, \"top\": 200, \"width\": 300, \"height\": 400", |
453 100, 200, 300, 400); | 457 100, 200, 300, 400); |
454 } | 458 } |
459 | |
460 } // namespace extensions | |
OLD | NEW |