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

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

Issue 11882025: Move "oauth2" manifest key parsing out of Extension class. (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: Created 7 years, 10 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 | Annotate | Revision Log
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" 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 namespace utils = extension_function_test_utils;
37 36
38 namespace { 37 namespace {
39 38
39 namespace errors = identity_constants;
40 namespace utils = extension_function_test_utils;
41
40 static const char kAccessToken[] = "auth_token"; 42 static const char kAccessToken[] = "auth_token";
41 43
42 class TestLoginUI : public LoginUIService::LoginUI { 44 class TestLoginUI : public LoginUIService::LoginUI {
43 public: 45 public:
44 virtual void FocusUI() OVERRIDE {} 46 virtual void FocusUI() OVERRIDE {}
45 virtual void CloseUI() OVERRIDE {} 47 virtual void CloseUI() OVERRIDE {}
46 }; 48 };
47 49
48 class TestOAuth2MintTokenFlow : public OAuth2MintTokenFlow { 50 class TestOAuth2MintTokenFlow : public OAuth2MintTokenFlow {
49 public: 51 public:
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 MOCK_METHOD1(CreateMintTokenFlow, 137 MOCK_METHOD1(CreateMintTokenFlow,
136 OAuth2MintTokenFlow* (OAuth2MintTokenFlow::Mode mode)); 138 OAuth2MintTokenFlow* (OAuth2MintTokenFlow::Mode mode));
137 private: 139 private:
138 ~MockGetAuthTokenFunction() {} 140 ~MockGetAuthTokenFunction() {}
139 bool install_ui_result_; 141 bool install_ui_result_;
140 bool login_ui_shown_; 142 bool login_ui_shown_;
141 bool install_ui_shown_; 143 bool install_ui_shown_;
142 }; 144 };
143 145
144 class GetAuthTokenFunctionTest : public ExtensionBrowserTest { 146 class GetAuthTokenFunctionTest : public ExtensionBrowserTest {
147 public:
148 virtual void SetUp() OVERRIDE {
149 ExtensionBrowserTest::SetUp();
150 ManifestHandler::Register(extension_manifest_keys::kOAuth2,
151 new OAuth2ManifestHandler);
152 }
145 protected: 153 protected:
146 enum OAuth2Fields { 154 enum OAuth2Fields {
147 NONE = 0, 155 NONE = 0,
148 CLIENT_ID = 1, 156 CLIENT_ID = 1,
149 SCOPES = 2 157 SCOPES = 2
150 }; 158 };
151 159
152 ~GetAuthTokenFunctionTest() {} 160 ~GetAuthTokenFunctionTest() {}
153 161
154 // Helper to create an extension with specific OAuth2Info fields set. 162 // Helper to create an extension with specific OAuth2Info fields set.
155 // |fields_to_set| should be computed by using fields of Oauth2Fields enum. 163 // |fields_to_set| should be computed by using fields of Oauth2Fields enum.
156 const Extension* CreateExtension(int fields_to_set) { 164 const Extension* CreateExtension(int fields_to_set) {
157 const Extension* ext = LoadExtension( 165 const Extension* ext = LoadExtension(
158 test_data_dir_.AppendASCII("platform_apps/oauth2")); 166 test_data_dir_.AppendASCII("platform_apps/oauth2"));
159 Extension::OAuth2Info& oauth2_info = const_cast<Extension::OAuth2Info&>( 167 OAuth2Info& oauth2_info = const_cast<OAuth2Info&>(
160 ext->oauth2_info()); 168 OAuth2Info::GetOAuth2Info(ext));
161 if ((fields_to_set & CLIENT_ID) != 0) 169 if ((fields_to_set & CLIENT_ID) != 0)
162 oauth2_info.client_id = "client1"; 170 oauth2_info.client_id = "client1";
163 if ((fields_to_set & SCOPES) != 0) { 171 if ((fields_to_set & SCOPES) != 0) {
164 oauth2_info.scopes.push_back("scope1"); 172 oauth2_info.scopes.push_back("scope1");
165 oauth2_info.scopes.push_back("scope2"); 173 oauth2_info.scopes.push_back("scope2");
166 } 174 }
167 return ext; 175 return ext;
168 } 176 }
169 }; 177 };
170 178
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after
405 int expected_x, 413 int expected_x,
406 int expected_y, 414 int expected_y,
407 int expected_width, 415 int expected_width,
408 int expected_height) { 416 int expected_height) {
409 content::WindowedNotificationObserver observer( 417 content::WindowedNotificationObserver observer(
410 chrome::NOTIFICATION_BROWSER_WINDOW_READY, 418 chrome::NOTIFICATION_BROWSER_WINDOW_READY,
411 content::NotificationService::AllSources()); 419 content::NotificationService::AllSources());
412 420
413 scoped_refptr<IdentityLaunchWebAuthFlowFunction> function( 421 scoped_refptr<IdentityLaunchWebAuthFlowFunction> function(
414 new IdentityLaunchWebAuthFlowFunction()); 422 new IdentityLaunchWebAuthFlowFunction());
415 scoped_refptr<extensions::Extension> empty_extension( 423 scoped_refptr<Extension> empty_extension(
416 utils::CreateEmptyExtension()); 424 utils::CreateEmptyExtension());
417 function->set_extension(empty_extension.get()); 425 function->set_extension(empty_extension.get());
418 std::string args = base::StringPrintf( 426 std::string args = base::StringPrintf(
419 "[{\"interactive\": true, \"url\": \"data:text/html,auth\"%s%s}]", 427 "[{\"interactive\": true, \"url\": \"data:text/html,auth\"%s%s}]",
420 extra_params.length() ? "," : "", 428 extra_params.length() ? "," : "",
421 extra_params.c_str()); 429 extra_params.c_str());
422 scoped_ptr<base::ListValue> parsed_args(utils::ParseList(args)); 430 scoped_ptr<base::ListValue> parsed_args(utils::ParseList(args));
423 EXPECT_TRUE(parsed_args.get()) << 431 EXPECT_TRUE(parsed_args.get()) <<
424 "Could not parse extension function arguments: " << args; 432 "Could not parse extension function arguments: " << args;
425 function->SetArgs(parsed_args.get()); 433 function->SetArgs(parsed_args.get());
(...skipping 19 matching lines...) Expand all
445 }; 453 };
446 454
447 IN_PROC_BROWSER_TEST_F(LaunchWebAuthFlowFunctionTest, Bounds) { 455 IN_PROC_BROWSER_TEST_F(LaunchWebAuthFlowFunctionTest, Bounds) {
448 RunAndCheckBounds("", 0, 0, 0, 0); 456 RunAndCheckBounds("", 0, 0, 0, 0);
449 RunAndCheckBounds("\"width\": 100, \"height\": 200", 0, 0, 100, 200); 457 RunAndCheckBounds("\"width\": 100, \"height\": 200", 0, 0, 100, 200);
450 RunAndCheckBounds("\"left\": 100, \"top\": 200", 100, 200, 0, 0); 458 RunAndCheckBounds("\"left\": 100, \"top\": 200", 100, 200, 0, 0);
451 RunAndCheckBounds( 459 RunAndCheckBounds(
452 "\"left\": 100, \"top\": 200, \"width\": 300, \"height\": 400", 460 "\"left\": 100, \"top\": 200, \"width\": 300, \"height\": 400",
453 100, 200, 300, 400); 461 100, 200, 300, 400);
454 } 462 }
463
464 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/api/identity/identity_api.cc ('k') | chrome/browser/extensions/extension_install_prompt.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698