| 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 <set> | 5 #include <set> |
| 6 #include <string> | 6 #include <string> |
| 7 #include <utility> | 7 #include <utility> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| 11 #include "base/memory/ptr_util.h" |
| 11 #include "base/strings/string_util.h" | 12 #include "base/strings/string_util.h" |
| 12 #include "base/strings/stringprintf.h" | 13 #include "base/strings/stringprintf.h" |
| 13 #include "base/values.h" | 14 #include "base/values.h" |
| 14 #include "build/build_config.h" | 15 #include "build/build_config.h" |
| 15 #include "chrome/browser/chrome_notification_types.h" | 16 #include "chrome/browser/chrome_notification_types.h" |
| 16 #include "components/prefs/pref_service.h" | 17 #include "components/prefs/pref_service.h" |
| 17 #if defined(OS_CHROMEOS) | 18 #if defined(OS_CHROMEOS) |
| 18 #include "chrome/browser/chromeos/login/users/mock_user_manager.h" | 19 #include "chrome/browser/chromeos/login/users/mock_user_manager.h" |
| 19 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h" | 20 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h" |
| 20 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" | 21 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 ASSERT_FALSE(bad_message); | 106 ASSERT_FALSE(bad_message); |
| 106 ASSERT_FALSE(HasResponse()); | 107 ASSERT_FALSE(HasResponse()); |
| 107 response_.reset(new bool); | 108 response_.reset(new bool); |
| 108 *response_ = success; | 109 *response_ = success; |
| 109 if (should_post_quit_) { | 110 if (should_post_quit_) { |
| 110 base::MessageLoopForUI::current()->QuitWhenIdle(); | 111 base::MessageLoopForUI::current()->QuitWhenIdle(); |
| 111 } | 112 } |
| 112 } | 113 } |
| 113 | 114 |
| 114 private: | 115 private: |
| 115 scoped_ptr<bool> response_; | 116 std::unique_ptr<bool> response_; |
| 116 bool should_post_quit_; | 117 bool should_post_quit_; |
| 117 }; | 118 }; |
| 118 | 119 |
| 119 class AsyncExtensionBrowserTest : public ExtensionBrowserTest { | 120 class AsyncExtensionBrowserTest : public ExtensionBrowserTest { |
| 120 protected: | 121 protected: |
| 121 // Asynchronous function runner allows tests to manipulate the browser window | 122 // Asynchronous function runner allows tests to manipulate the browser window |
| 122 // after the call happens. | 123 // after the call happens. |
| 123 void RunFunctionAsync( | 124 void RunFunctionAsync( |
| 124 UIThreadExtensionFunction* function, | 125 UIThreadExtensionFunction* function, |
| 125 const std::string& args) { | 126 const std::string& args) { |
| 126 response_delegate_.reset(new SendResponseDelegate); | 127 response_delegate_.reset(new SendResponseDelegate); |
| 127 function->set_test_delegate(response_delegate_.get()); | 128 function->set_test_delegate(response_delegate_.get()); |
| 128 scoped_ptr<base::ListValue> parsed_args(utils::ParseList(args)); | 129 std::unique_ptr<base::ListValue> parsed_args(utils::ParseList(args)); |
| 129 EXPECT_TRUE(parsed_args.get()) << | 130 EXPECT_TRUE(parsed_args.get()) << |
| 130 "Could not parse extension function arguments: " << args; | 131 "Could not parse extension function arguments: " << args; |
| 131 function->SetArgs(parsed_args.get()); | 132 function->SetArgs(parsed_args.get()); |
| 132 | 133 |
| 133 if (!function->extension()) { | 134 if (!function->extension()) { |
| 134 scoped_refptr<Extension> empty_extension( | 135 scoped_refptr<Extension> empty_extension( |
| 135 test_util::CreateEmptyExtension()); | 136 test_util::CreateEmptyExtension()); |
| 136 function->set_extension(empty_extension.get()); | 137 function->set_extension(empty_extension.get()); |
| 137 } | 138 } |
| 138 | 139 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 163 void RunMessageLoopUntilResponse() { | 164 void RunMessageLoopUntilResponse() { |
| 164 // If the RunAsync of |function| didn't already call SendResponse, run the | 165 // If the RunAsync of |function| didn't already call SendResponse, run the |
| 165 // message loop until they do. | 166 // message loop until they do. |
| 166 if (!response_delegate_->HasResponse()) { | 167 if (!response_delegate_->HasResponse()) { |
| 167 response_delegate_->set_should_post_quit(true); | 168 response_delegate_->set_should_post_quit(true); |
| 168 content::RunMessageLoop(); | 169 content::RunMessageLoop(); |
| 169 } | 170 } |
| 170 EXPECT_TRUE(response_delegate_->HasResponse()); | 171 EXPECT_TRUE(response_delegate_->HasResponse()); |
| 171 } | 172 } |
| 172 | 173 |
| 173 scoped_ptr<SendResponseDelegate> response_delegate_; | 174 std::unique_ptr<SendResponseDelegate> response_delegate_; |
| 174 }; | 175 }; |
| 175 | 176 |
| 176 class TestHangOAuth2MintTokenFlow : public OAuth2MintTokenFlow { | 177 class TestHangOAuth2MintTokenFlow : public OAuth2MintTokenFlow { |
| 177 public: | 178 public: |
| 178 TestHangOAuth2MintTokenFlow() | 179 TestHangOAuth2MintTokenFlow() |
| 179 : OAuth2MintTokenFlow(NULL, OAuth2MintTokenFlow::Parameters()) {} | 180 : OAuth2MintTokenFlow(NULL, OAuth2MintTokenFlow::Parameters()) {} |
| 180 | 181 |
| 181 void Start(net::URLRequestContextGetter* context, | 182 void Start(net::URLRequestContextGetter* context, |
| 182 const std::string& access_token) override { | 183 const std::string& access_token) override { |
| 183 // Do nothing, simulating a hanging network call. | 184 // Do nothing, simulating a hanging network call. |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 299 void set_login_access_token_result(bool result) { | 300 void set_login_access_token_result(bool result) { |
| 300 login_access_token_result_ = result; | 301 login_access_token_result_ = result; |
| 301 } | 302 } |
| 302 | 303 |
| 303 void set_auto_login_access_token(bool automatic) { | 304 void set_auto_login_access_token(bool automatic) { |
| 304 auto_login_access_token_ = automatic; | 305 auto_login_access_token_ = automatic; |
| 305 } | 306 } |
| 306 | 307 |
| 307 void set_login_ui_result(bool result) { login_ui_result_ = result; } | 308 void set_login_ui_result(bool result) { login_ui_result_ = result; } |
| 308 | 309 |
| 309 void set_mint_token_flow(scoped_ptr<OAuth2MintTokenFlow> flow) { | 310 void set_mint_token_flow(std::unique_ptr<OAuth2MintTokenFlow> flow) { |
| 310 flow_ = std::move(flow); | 311 flow_ = std::move(flow); |
| 311 } | 312 } |
| 312 | 313 |
| 313 void set_mint_token_result(TestOAuth2MintTokenFlow::ResultType result_type) { | 314 void set_mint_token_result(TestOAuth2MintTokenFlow::ResultType result_type) { |
| 314 set_mint_token_flow( | 315 set_mint_token_flow( |
| 315 make_scoped_ptr(new TestOAuth2MintTokenFlow(result_type, this))); | 316 base::WrapUnique(new TestOAuth2MintTokenFlow(result_type, this))); |
| 316 } | 317 } |
| 317 | 318 |
| 318 void set_scope_ui_failure(GaiaWebAuthFlow::Failure failure) { | 319 void set_scope_ui_failure(GaiaWebAuthFlow::Failure failure) { |
| 319 scope_ui_result_ = false; | 320 scope_ui_result_ = false; |
| 320 scope_ui_failure_ = failure; | 321 scope_ui_failure_ = failure; |
| 321 } | 322 } |
| 322 | 323 |
| 323 void set_scope_ui_oauth_error(const std::string& oauth_error) { | 324 void set_scope_ui_oauth_error(const std::string& oauth_error) { |
| 324 scope_ui_result_ = false; | 325 scope_ui_result_ = false; |
| 325 scope_ui_failure_ = GaiaWebAuthFlow::OAUTH_ERROR; | 326 scope_ui_failure_ = GaiaWebAuthFlow::OAUTH_ERROR; |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 395 ~FakeGetAuthTokenFunction() override {} | 396 ~FakeGetAuthTokenFunction() override {} |
| 396 bool login_access_token_result_; | 397 bool login_access_token_result_; |
| 397 bool auto_login_access_token_; | 398 bool auto_login_access_token_; |
| 398 bool login_ui_result_; | 399 bool login_ui_result_; |
| 399 bool scope_ui_result_; | 400 bool scope_ui_result_; |
| 400 GaiaWebAuthFlow::Failure scope_ui_failure_; | 401 GaiaWebAuthFlow::Failure scope_ui_failure_; |
| 401 std::string scope_ui_oauth_error_; | 402 std::string scope_ui_oauth_error_; |
| 402 bool login_ui_shown_; | 403 bool login_ui_shown_; |
| 403 bool scope_ui_shown_; | 404 bool scope_ui_shown_; |
| 404 | 405 |
| 405 scoped_ptr<OAuth2MintTokenFlow> flow_; | 406 std::unique_ptr<OAuth2MintTokenFlow> flow_; |
| 406 | 407 |
| 407 std::string login_access_token_; | 408 std::string login_access_token_; |
| 408 }; | 409 }; |
| 409 | 410 |
| 410 class MockQueuedMintRequest : public IdentityMintRequestQueue::Request { | 411 class MockQueuedMintRequest : public IdentityMintRequestQueue::Request { |
| 411 public: | 412 public: |
| 412 MOCK_METHOD1(StartMintToken, void(IdentityMintRequestQueue::MintType)); | 413 MOCK_METHOD1(StartMintToken, void(IdentityMintRequestQueue::MintType)); |
| 413 }; | 414 }; |
| 414 | 415 |
| 415 gaia::AccountIds CreateIds(const std::string& email, const std::string& obfid) { | 416 gaia::AccountIds CreateIds(const std::string& email, const std::string& obfid) { |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 452 } | 453 } |
| 453 | 454 |
| 454 const base::ListValue* results; | 455 const base::ListValue* results; |
| 455 if (!callback_arguments->GetList(0, &results)) | 456 if (!callback_arguments->GetList(0, &results)) |
| 456 GenerateFailureResult(accounts, NULL) << "Result was not an array"; | 457 GenerateFailureResult(accounts, NULL) << "Result was not an array"; |
| 457 | 458 |
| 458 std::set<std::string> result_ids; | 459 std::set<std::string> result_ids; |
| 459 for (base::ListValue::const_iterator it = results->begin(); | 460 for (base::ListValue::const_iterator it = results->begin(); |
| 460 it != results->end(); | 461 it != results->end(); |
| 461 ++it) { | 462 ++it) { |
| 462 scoped_ptr<api::identity::AccountInfo> info = | 463 std::unique_ptr<api::identity::AccountInfo> info = |
| 463 api::identity::AccountInfo::FromValue(**it); | 464 api::identity::AccountInfo::FromValue(**it); |
| 464 if (info.get()) | 465 if (info.get()) |
| 465 result_ids.insert(info->id); | 466 result_ids.insert(info->id); |
| 466 else | 467 else |
| 467 return GenerateFailureResult(accounts, results); | 468 return GenerateFailureResult(accounts, results); |
| 468 } | 469 } |
| 469 | 470 |
| 470 for (std::vector<std::string>::const_iterator it = accounts.begin(); | 471 for (std::vector<std::string>::const_iterator it = accounts.begin(); |
| 471 it != accounts.end(); | 472 it != accounts.end(); |
| 472 ++it) { | 473 ++it) { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 486 ++it) { | 487 ++it) { |
| 487 msg << *it << " "; | 488 msg << *it << " "; |
| 488 } | 489 } |
| 489 msg << "Actual: "; | 490 msg << "Actual: "; |
| 490 if (!results) { | 491 if (!results) { |
| 491 msg << "NULL"; | 492 msg << "NULL"; |
| 492 } else { | 493 } else { |
| 493 for (base::ListValue::const_iterator it = results->begin(); | 494 for (base::ListValue::const_iterator it = results->begin(); |
| 494 it != results->end(); | 495 it != results->end(); |
| 495 ++it) { | 496 ++it) { |
| 496 scoped_ptr<api::identity::AccountInfo> info = | 497 std::unique_ptr<api::identity::AccountInfo> info = |
| 497 api::identity::AccountInfo::FromValue(**it); | 498 api::identity::AccountInfo::FromValue(**it); |
| 498 if (info.get()) | 499 if (info.get()) |
| 499 msg << info->id << " "; | 500 msg << info->id << " "; |
| 500 else | 501 else |
| 501 msg << *it << "<-" << (*it)->GetType() << " "; | 502 msg << *it << "<-" << (*it)->GetType() << " "; |
| 502 } | 503 } |
| 503 } | 504 } |
| 504 | 505 |
| 505 return testing::AssertionFailure(msg); | 506 return testing::AssertionFailure(msg); |
| 506 } | 507 } |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 607 signin_manager_->SetAuthenticatedAccountInfo(gaia, email); | 608 signin_manager_->SetAuthenticatedAccountInfo(gaia, email); |
| 608 #else | 609 #else |
| 609 signin_manager_->SignIn(gaia, email, "password"); | 610 signin_manager_->SignIn(gaia, email, "password"); |
| 610 #endif | 611 #endif |
| 611 token_service_->UpdateCredentials(account_id, "refresh_token"); | 612 token_service_->UpdateCredentials(account_id, "refresh_token"); |
| 612 } | 613 } |
| 613 | 614 |
| 614 FakeSigninManagerForTesting* signin_manager_; | 615 FakeSigninManagerForTesting* signin_manager_; |
| 615 FakeProfileOAuth2TokenService* token_service_; | 616 FakeProfileOAuth2TokenService* token_service_; |
| 616 | 617 |
| 617 scoped_ptr<base::CallbackList<void(content::BrowserContext*)>::Subscription> | 618 std::unique_ptr< |
| 619 base::CallbackList<void(content::BrowserContext*)>::Subscription> |
| 618 will_create_browser_context_services_subscription_; | 620 will_create_browser_context_services_subscription_; |
| 619 }; | 621 }; |
| 620 | 622 |
| 621 class IdentityGetProfileUserInfoFunctionTest : public IdentityTestWithSignin { | 623 class IdentityGetProfileUserInfoFunctionTest : public IdentityTestWithSignin { |
| 622 protected: | 624 protected: |
| 623 scoped_ptr<api::identity::ProfileUserInfo> RunGetProfileUserInfo() { | 625 std::unique_ptr<api::identity::ProfileUserInfo> RunGetProfileUserInfo() { |
| 624 scoped_refptr<IdentityGetProfileUserInfoFunction> func( | 626 scoped_refptr<IdentityGetProfileUserInfoFunction> func( |
| 625 new IdentityGetProfileUserInfoFunction); | 627 new IdentityGetProfileUserInfoFunction); |
| 626 func->set_extension(test_util::CreateEmptyExtension(kExtensionId).get()); | 628 func->set_extension(test_util::CreateEmptyExtension(kExtensionId).get()); |
| 627 scoped_ptr<base::Value> value( | 629 std::unique_ptr<base::Value> value( |
| 628 utils::RunFunctionAndReturnSingleResult(func.get(), "[]", browser())); | 630 utils::RunFunctionAndReturnSingleResult(func.get(), "[]", browser())); |
| 629 return api::identity::ProfileUserInfo::FromValue(*value.get()); | 631 return api::identity::ProfileUserInfo::FromValue(*value.get()); |
| 630 } | 632 } |
| 631 | 633 |
| 632 scoped_ptr<api::identity::ProfileUserInfo> RunGetProfileUserInfoWithEmail() { | 634 std::unique_ptr<api::identity::ProfileUserInfo> |
| 635 RunGetProfileUserInfoWithEmail() { |
| 633 scoped_refptr<IdentityGetProfileUserInfoFunction> func( | 636 scoped_refptr<IdentityGetProfileUserInfoFunction> func( |
| 634 new IdentityGetProfileUserInfoFunction); | 637 new IdentityGetProfileUserInfoFunction); |
| 635 func->set_extension(CreateExtensionWithEmailPermission()); | 638 func->set_extension(CreateExtensionWithEmailPermission()); |
| 636 scoped_ptr<base::Value> value( | 639 std::unique_ptr<base::Value> value( |
| 637 utils::RunFunctionAndReturnSingleResult(func.get(), "[]", browser())); | 640 utils::RunFunctionAndReturnSingleResult(func.get(), "[]", browser())); |
| 638 return api::identity::ProfileUserInfo::FromValue(*value.get()); | 641 return api::identity::ProfileUserInfo::FromValue(*value.get()); |
| 639 } | 642 } |
| 640 | 643 |
| 641 private: | 644 private: |
| 642 scoped_refptr<Extension> CreateExtensionWithEmailPermission() { | 645 scoped_refptr<Extension> CreateExtensionWithEmailPermission() { |
| 643 scoped_ptr<base::DictionaryValue> test_extension_value( | 646 std::unique_ptr<base::DictionaryValue> test_extension_value( |
| 644 api_test_utils::ParseDictionary( | 647 api_test_utils::ParseDictionary( |
| 645 "{\"name\": \"Test\", \"version\": \"1.0\", " | 648 "{\"name\": \"Test\", \"version\": \"1.0\", " |
| 646 "\"permissions\": [\"identity.email\"]}")); | 649 "\"permissions\": [\"identity.email\"]}")); |
| 647 return api_test_utils::CreateExtension(test_extension_value.get()); | 650 return api_test_utils::CreateExtension(test_extension_value.get()); |
| 648 } | 651 } |
| 649 }; | 652 }; |
| 650 | 653 |
| 651 IN_PROC_BROWSER_TEST_F(IdentityGetProfileUserInfoFunctionTest, NotSignedIn) { | 654 IN_PROC_BROWSER_TEST_F(IdentityGetProfileUserInfoFunctionTest, NotSignedIn) { |
| 652 scoped_ptr<api::identity::ProfileUserInfo> info = | 655 std::unique_ptr<api::identity::ProfileUserInfo> info = |
| 653 RunGetProfileUserInfoWithEmail(); | 656 RunGetProfileUserInfoWithEmail(); |
| 654 EXPECT_TRUE(info->email.empty()); | 657 EXPECT_TRUE(info->email.empty()); |
| 655 EXPECT_TRUE(info->id.empty()); | 658 EXPECT_TRUE(info->id.empty()); |
| 656 } | 659 } |
| 657 | 660 |
| 658 IN_PROC_BROWSER_TEST_F(IdentityGetProfileUserInfoFunctionTest, SignedIn) { | 661 IN_PROC_BROWSER_TEST_F(IdentityGetProfileUserInfoFunctionTest, SignedIn) { |
| 659 SignIn("president@example.com", "12345"); | 662 SignIn("president@example.com", "12345"); |
| 660 scoped_ptr<api::identity::ProfileUserInfo> info = | 663 std::unique_ptr<api::identity::ProfileUserInfo> info = |
| 661 RunGetProfileUserInfoWithEmail(); | 664 RunGetProfileUserInfoWithEmail(); |
| 662 EXPECT_EQ("president@example.com", info->email); | 665 EXPECT_EQ("president@example.com", info->email); |
| 663 EXPECT_EQ("12345", info->id); | 666 EXPECT_EQ("12345", info->id); |
| 664 } | 667 } |
| 665 | 668 |
| 666 IN_PROC_BROWSER_TEST_F(IdentityGetProfileUserInfoFunctionTest, | 669 IN_PROC_BROWSER_TEST_F(IdentityGetProfileUserInfoFunctionTest, |
| 667 NotSignedInNoEmail) { | 670 NotSignedInNoEmail) { |
| 668 scoped_ptr<api::identity::ProfileUserInfo> info = RunGetProfileUserInfo(); | 671 std::unique_ptr<api::identity::ProfileUserInfo> info = |
| 672 RunGetProfileUserInfo(); |
| 669 EXPECT_TRUE(info->email.empty()); | 673 EXPECT_TRUE(info->email.empty()); |
| 670 EXPECT_TRUE(info->id.empty()); | 674 EXPECT_TRUE(info->id.empty()); |
| 671 } | 675 } |
| 672 | 676 |
| 673 IN_PROC_BROWSER_TEST_F(IdentityGetProfileUserInfoFunctionTest, | 677 IN_PROC_BROWSER_TEST_F(IdentityGetProfileUserInfoFunctionTest, |
| 674 SignedInNoEmail) { | 678 SignedInNoEmail) { |
| 675 SignIn("president@example.com", "12345"); | 679 SignIn("president@example.com", "12345"); |
| 676 scoped_ptr<api::identity::ProfileUserInfo> info = RunGetProfileUserInfo(); | 680 std::unique_ptr<api::identity::ProfileUserInfo> info = |
| 681 RunGetProfileUserInfo(); |
| 677 EXPECT_TRUE(info->email.empty()); | 682 EXPECT_TRUE(info->email.empty()); |
| 678 EXPECT_TRUE(info->id.empty()); | 683 EXPECT_TRUE(info->id.empty()); |
| 679 } | 684 } |
| 680 | 685 |
| 681 class GetAuthTokenFunctionTest : public IdentityTestWithSignin { | 686 class GetAuthTokenFunctionTest : public IdentityTestWithSignin { |
| 682 public: | 687 public: |
| 683 void SetUpCommandLine(base::CommandLine* command_line) override { | 688 void SetUpCommandLine(base::CommandLine* command_line) override { |
| 684 IdentityTestWithSignin::SetUpCommandLine(command_line); | 689 IdentityTestWithSignin::SetUpCommandLine(command_line); |
| 685 command_line->AppendSwitch(switches::kExtensionsMultiAccount); | 690 command_line->AppendSwitch(switches::kExtensionsMultiAccount); |
| 686 } | 691 } |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 890 // Disable this test in Metro+Ash for now (http://crbug.com/262796). | 895 // Disable this test in Metro+Ash for now (http://crbug.com/262796). |
| 891 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 896 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 892 switches::kAshBrowserTests)) | 897 switches::kAshBrowserTests)) |
| 893 return; | 898 return; |
| 894 #endif | 899 #endif |
| 895 | 900 |
| 896 scoped_refptr<FakeGetAuthTokenFunction> func(new FakeGetAuthTokenFunction()); | 901 scoped_refptr<FakeGetAuthTokenFunction> func(new FakeGetAuthTokenFunction()); |
| 897 scoped_refptr<const Extension> extension(CreateExtension(CLIENT_ID | SCOPES)); | 902 scoped_refptr<const Extension> extension(CreateExtension(CLIENT_ID | SCOPES)); |
| 898 func->set_extension(extension.get()); | 903 func->set_extension(extension.get()); |
| 899 func->set_mint_token_result(TestOAuth2MintTokenFlow::MINT_TOKEN_SUCCESS); | 904 func->set_mint_token_result(TestOAuth2MintTokenFlow::MINT_TOKEN_SUCCESS); |
| 900 scoped_ptr<base::Value> value( | 905 std::unique_ptr<base::Value> value( |
| 901 utils::RunFunctionAndReturnSingleResult(func.get(), "[]", browser())); | 906 utils::RunFunctionAndReturnSingleResult(func.get(), "[]", browser())); |
| 902 std::string access_token; | 907 std::string access_token; |
| 903 EXPECT_TRUE(value->GetAsString(&access_token)); | 908 EXPECT_TRUE(value->GetAsString(&access_token)); |
| 904 EXPECT_EQ(std::string(kAccessToken), access_token); | 909 EXPECT_EQ(std::string(kAccessToken), access_token); |
| 905 EXPECT_FALSE(func->login_ui_shown()); | 910 EXPECT_FALSE(func->login_ui_shown()); |
| 906 EXPECT_FALSE(func->scope_ui_shown()); | 911 EXPECT_FALSE(func->scope_ui_shown()); |
| 907 EXPECT_EQ(IdentityTokenCacheValue::CACHE_STATUS_TOKEN, | 912 EXPECT_EQ(IdentityTokenCacheValue::CACHE_STATUS_TOKEN, |
| 908 GetCachedToken(std::string()).status()); | 913 GetCachedToken(std::string()).status()); |
| 909 } | 914 } |
| 910 | 915 |
| 911 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, | 916 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, |
| 912 NonInteractiveSuccess) { | 917 NonInteractiveSuccess) { |
| 913 SignIn("primary@example.com"); | 918 SignIn("primary@example.com"); |
| 914 #if defined(OS_WIN) && defined(USE_ASH) | 919 #if defined(OS_WIN) && defined(USE_ASH) |
| 915 // Disable this test in Metro+Ash for now (http://crbug.com/262796). | 920 // Disable this test in Metro+Ash for now (http://crbug.com/262796). |
| 916 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 921 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 917 switches::kAshBrowserTests)) | 922 switches::kAshBrowserTests)) |
| 918 return; | 923 return; |
| 919 #endif | 924 #endif |
| 920 | 925 |
| 921 scoped_refptr<FakeGetAuthTokenFunction> func(new FakeGetAuthTokenFunction()); | 926 scoped_refptr<FakeGetAuthTokenFunction> func(new FakeGetAuthTokenFunction()); |
| 922 scoped_refptr<const Extension> extension(CreateExtension(CLIENT_ID | SCOPES)); | 927 scoped_refptr<const Extension> extension(CreateExtension(CLIENT_ID | SCOPES)); |
| 923 func->set_extension(extension.get()); | 928 func->set_extension(extension.get()); |
| 924 func->set_mint_token_result(TestOAuth2MintTokenFlow::MINT_TOKEN_SUCCESS); | 929 func->set_mint_token_result(TestOAuth2MintTokenFlow::MINT_TOKEN_SUCCESS); |
| 925 scoped_ptr<base::Value> value(utils::RunFunctionAndReturnSingleResult( | 930 std::unique_ptr<base::Value> value( |
| 926 func.get(), "[{}]", browser())); | 931 utils::RunFunctionAndReturnSingleResult(func.get(), "[{}]", browser())); |
| 927 std::string access_token; | 932 std::string access_token; |
| 928 EXPECT_TRUE(value->GetAsString(&access_token)); | 933 EXPECT_TRUE(value->GetAsString(&access_token)); |
| 929 EXPECT_EQ(std::string(kAccessToken), access_token); | 934 EXPECT_EQ(std::string(kAccessToken), access_token); |
| 930 EXPECT_FALSE(func->login_ui_shown()); | 935 EXPECT_FALSE(func->login_ui_shown()); |
| 931 EXPECT_FALSE(func->scope_ui_shown()); | 936 EXPECT_FALSE(func->scope_ui_shown()); |
| 932 EXPECT_EQ(IdentityTokenCacheValue::CACHE_STATUS_TOKEN, | 937 EXPECT_EQ(IdentityTokenCacheValue::CACHE_STATUS_TOKEN, |
| 933 GetCachedToken(std::string()).status()); | 938 GetCachedToken(std::string()).status()); |
| 934 } | 939 } |
| 935 | 940 |
| 936 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, | 941 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1001 } | 1006 } |
| 1002 | 1007 |
| 1003 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, | 1008 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, |
| 1004 InteractiveLoginSuccessMintSuccess) { | 1009 InteractiveLoginSuccessMintSuccess) { |
| 1005 // TODO(courage): verify that account_id in token service requests | 1010 // TODO(courage): verify that account_id in token service requests |
| 1006 // is correct once manual token minting for tests is implemented. | 1011 // is correct once manual token minting for tests is implemented. |
| 1007 scoped_refptr<FakeGetAuthTokenFunction> func(new FakeGetAuthTokenFunction()); | 1012 scoped_refptr<FakeGetAuthTokenFunction> func(new FakeGetAuthTokenFunction()); |
| 1008 func->set_extension(CreateExtension(CLIENT_ID | SCOPES)); | 1013 func->set_extension(CreateExtension(CLIENT_ID | SCOPES)); |
| 1009 func->set_login_ui_result(true); | 1014 func->set_login_ui_result(true); |
| 1010 func->set_mint_token_result(TestOAuth2MintTokenFlow::MINT_TOKEN_SUCCESS); | 1015 func->set_mint_token_result(TestOAuth2MintTokenFlow::MINT_TOKEN_SUCCESS); |
| 1011 scoped_ptr<base::Value> value(utils::RunFunctionAndReturnSingleResult( | 1016 std::unique_ptr<base::Value> value(utils::RunFunctionAndReturnSingleResult( |
| 1012 func.get(), "[{\"interactive\": true}]", browser())); | 1017 func.get(), "[{\"interactive\": true}]", browser())); |
| 1013 std::string access_token; | 1018 std::string access_token; |
| 1014 EXPECT_TRUE(value->GetAsString(&access_token)); | 1019 EXPECT_TRUE(value->GetAsString(&access_token)); |
| 1015 EXPECT_EQ(std::string(kAccessToken), access_token); | 1020 EXPECT_EQ(std::string(kAccessToken), access_token); |
| 1016 EXPECT_TRUE(func->login_ui_shown()); | 1021 EXPECT_TRUE(func->login_ui_shown()); |
| 1017 EXPECT_FALSE(func->scope_ui_shown()); | 1022 EXPECT_FALSE(func->scope_ui_shown()); |
| 1018 } | 1023 } |
| 1019 | 1024 |
| 1020 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, | 1025 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, |
| 1021 InteractiveLoginSuccessApprovalAborted) { | 1026 InteractiveLoginSuccessApprovalAborted) { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 1032 } | 1037 } |
| 1033 | 1038 |
| 1034 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, | 1039 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, |
| 1035 InteractiveLoginSuccessApprovalSuccess) { | 1040 InteractiveLoginSuccessApprovalSuccess) { |
| 1036 scoped_refptr<const Extension> extension(CreateExtension(CLIENT_ID | SCOPES)); | 1041 scoped_refptr<const Extension> extension(CreateExtension(CLIENT_ID | SCOPES)); |
| 1037 scoped_refptr<FakeGetAuthTokenFunction> func(new FakeGetAuthTokenFunction()); | 1042 scoped_refptr<FakeGetAuthTokenFunction> func(new FakeGetAuthTokenFunction()); |
| 1038 func->set_extension(extension.get()); | 1043 func->set_extension(extension.get()); |
| 1039 func->set_login_ui_result(true); | 1044 func->set_login_ui_result(true); |
| 1040 func->set_mint_token_result(TestOAuth2MintTokenFlow::ISSUE_ADVICE_SUCCESS); | 1045 func->set_mint_token_result(TestOAuth2MintTokenFlow::ISSUE_ADVICE_SUCCESS); |
| 1041 | 1046 |
| 1042 scoped_ptr<base::Value> value(utils::RunFunctionAndReturnSingleResult( | 1047 std::unique_ptr<base::Value> value(utils::RunFunctionAndReturnSingleResult( |
| 1043 func.get(), "[{\"interactive\": true}]", browser())); | 1048 func.get(), "[{\"interactive\": true}]", browser())); |
| 1044 std::string access_token; | 1049 std::string access_token; |
| 1045 EXPECT_TRUE(value->GetAsString(&access_token)); | 1050 EXPECT_TRUE(value->GetAsString(&access_token)); |
| 1046 EXPECT_EQ(std::string(kAccessToken), access_token); | 1051 EXPECT_EQ(std::string(kAccessToken), access_token); |
| 1047 EXPECT_TRUE(func->login_ui_shown()); | 1052 EXPECT_TRUE(func->login_ui_shown()); |
| 1048 EXPECT_TRUE(func->scope_ui_shown()); | 1053 EXPECT_TRUE(func->scope_ui_shown()); |
| 1049 } | 1054 } |
| 1050 | 1055 |
| 1051 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, | 1056 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, |
| 1052 InteractiveApprovalAborted) { | 1057 InteractiveApprovalAborted) { |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1137 } | 1142 } |
| 1138 | 1143 |
| 1139 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, | 1144 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, |
| 1140 InteractiveApprovalSuccess) { | 1145 InteractiveApprovalSuccess) { |
| 1141 SignIn("primary@example.com"); | 1146 SignIn("primary@example.com"); |
| 1142 scoped_refptr<const Extension> extension(CreateExtension(CLIENT_ID | SCOPES)); | 1147 scoped_refptr<const Extension> extension(CreateExtension(CLIENT_ID | SCOPES)); |
| 1143 scoped_refptr<FakeGetAuthTokenFunction> func(new FakeGetAuthTokenFunction()); | 1148 scoped_refptr<FakeGetAuthTokenFunction> func(new FakeGetAuthTokenFunction()); |
| 1144 func->set_extension(extension.get()); | 1149 func->set_extension(extension.get()); |
| 1145 func->set_mint_token_result(TestOAuth2MintTokenFlow::ISSUE_ADVICE_SUCCESS); | 1150 func->set_mint_token_result(TestOAuth2MintTokenFlow::ISSUE_ADVICE_SUCCESS); |
| 1146 | 1151 |
| 1147 scoped_ptr<base::Value> value(utils::RunFunctionAndReturnSingleResult( | 1152 std::unique_ptr<base::Value> value(utils::RunFunctionAndReturnSingleResult( |
| 1148 func.get(), "[{\"interactive\": true}]", browser())); | 1153 func.get(), "[{\"interactive\": true}]", browser())); |
| 1149 std::string access_token; | 1154 std::string access_token; |
| 1150 EXPECT_TRUE(value->GetAsString(&access_token)); | 1155 EXPECT_TRUE(value->GetAsString(&access_token)); |
| 1151 EXPECT_EQ(std::string(kAccessToken), access_token); | 1156 EXPECT_EQ(std::string(kAccessToken), access_token); |
| 1152 EXPECT_FALSE(func->login_ui_shown()); | 1157 EXPECT_FALSE(func->login_ui_shown()); |
| 1153 EXPECT_TRUE(func->scope_ui_shown()); | 1158 EXPECT_TRUE(func->scope_ui_shown()); |
| 1154 | 1159 |
| 1155 EXPECT_EQ(IdentityTokenCacheValue::CACHE_STATUS_TOKEN, | 1160 EXPECT_EQ(IdentityTokenCacheValue::CACHE_STATUS_TOKEN, |
| 1156 GetCachedToken(std::string()).status()); | 1161 GetCachedToken(std::string()).status()); |
| 1157 } | 1162 } |
| (...skipping 16 matching lines...) Expand all Loading... |
| 1174 // the blocker. | 1179 // the blocker. |
| 1175 RunFunctionAsync(func.get(), "[{}]"); | 1180 RunFunctionAsync(func.get(), "[{}]"); |
| 1176 // Verify that we have fetched the login token at this point. | 1181 // Verify that we have fetched the login token at this point. |
| 1177 testing::Mock::VerifyAndClearExpectations(func.get()); | 1182 testing::Mock::VerifyAndClearExpectations(func.get()); |
| 1178 | 1183 |
| 1179 // The flow will be created after the first queued request clears. | 1184 // The flow will be created after the first queued request clears. |
| 1180 func->set_mint_token_result(TestOAuth2MintTokenFlow::MINT_TOKEN_SUCCESS); | 1185 func->set_mint_token_result(TestOAuth2MintTokenFlow::MINT_TOKEN_SUCCESS); |
| 1181 | 1186 |
| 1182 QueueRequestComplete(type, &queued_request); | 1187 QueueRequestComplete(type, &queued_request); |
| 1183 | 1188 |
| 1184 scoped_ptr<base::Value> value(WaitForSingleResult(func.get())); | 1189 std::unique_ptr<base::Value> value(WaitForSingleResult(func.get())); |
| 1185 std::string access_token; | 1190 std::string access_token; |
| 1186 EXPECT_TRUE(value->GetAsString(&access_token)); | 1191 EXPECT_TRUE(value->GetAsString(&access_token)); |
| 1187 EXPECT_EQ(std::string(kAccessToken), access_token); | 1192 EXPECT_EQ(std::string(kAccessToken), access_token); |
| 1188 EXPECT_FALSE(func->login_ui_shown()); | 1193 EXPECT_FALSE(func->login_ui_shown()); |
| 1189 EXPECT_FALSE(func->scope_ui_shown()); | 1194 EXPECT_FALSE(func->scope_ui_shown()); |
| 1190 } | 1195 } |
| 1191 | 1196 |
| 1192 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, InteractiveQueue) { | 1197 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, InteractiveQueue) { |
| 1193 SignIn("primary@example.com"); | 1198 SignIn("primary@example.com"); |
| 1194 scoped_refptr<const Extension> extension(CreateExtension(CLIENT_ID | SCOPES)); | 1199 scoped_refptr<const Extension> extension(CreateExtension(CLIENT_ID | SCOPES)); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1208 func->set_mint_token_result(TestOAuth2MintTokenFlow::ISSUE_ADVICE_SUCCESS); | 1213 func->set_mint_token_result(TestOAuth2MintTokenFlow::ISSUE_ADVICE_SUCCESS); |
| 1209 RunFunctionAsync(func.get(), "[{\"interactive\": true}]"); | 1214 RunFunctionAsync(func.get(), "[{\"interactive\": true}]"); |
| 1210 // Verify that we have fetched the login token and run the first flow. | 1215 // Verify that we have fetched the login token and run the first flow. |
| 1211 testing::Mock::VerifyAndClearExpectations(func.get()); | 1216 testing::Mock::VerifyAndClearExpectations(func.get()); |
| 1212 EXPECT_FALSE(func->scope_ui_shown()); | 1217 EXPECT_FALSE(func->scope_ui_shown()); |
| 1213 | 1218 |
| 1214 // The UI will be displayed and a token retrieved after the first | 1219 // The UI will be displayed and a token retrieved after the first |
| 1215 // queued request clears. | 1220 // queued request clears. |
| 1216 QueueRequestComplete(type, &queued_request); | 1221 QueueRequestComplete(type, &queued_request); |
| 1217 | 1222 |
| 1218 scoped_ptr<base::Value> value(WaitForSingleResult(func.get())); | 1223 std::unique_ptr<base::Value> value(WaitForSingleResult(func.get())); |
| 1219 std::string access_token; | 1224 std::string access_token; |
| 1220 EXPECT_TRUE(value->GetAsString(&access_token)); | 1225 EXPECT_TRUE(value->GetAsString(&access_token)); |
| 1221 EXPECT_EQ(std::string(kAccessToken), access_token); | 1226 EXPECT_EQ(std::string(kAccessToken), access_token); |
| 1222 EXPECT_FALSE(func->login_ui_shown()); | 1227 EXPECT_FALSE(func->login_ui_shown()); |
| 1223 EXPECT_TRUE(func->scope_ui_shown()); | 1228 EXPECT_TRUE(func->scope_ui_shown()); |
| 1224 } | 1229 } |
| 1225 | 1230 |
| 1226 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, InteractiveQueueShutdown) { | 1231 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, InteractiveQueueShutdown) { |
| 1227 SignIn("primary@example.com"); | 1232 SignIn("primary@example.com"); |
| 1228 scoped_refptr<const Extension> extension(CreateExtension(CLIENT_ID | SCOPES)); | 1233 scoped_refptr<const Extension> extension(CreateExtension(CLIENT_ID | SCOPES)); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 1253 | 1258 |
| 1254 QueueRequestComplete(type, &queued_request); | 1259 QueueRequestComplete(type, &queued_request); |
| 1255 } | 1260 } |
| 1256 | 1261 |
| 1257 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, NoninteractiveShutdown) { | 1262 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, NoninteractiveShutdown) { |
| 1258 SignIn("primary@example.com"); | 1263 SignIn("primary@example.com"); |
| 1259 scoped_refptr<const Extension> extension(CreateExtension(CLIENT_ID | SCOPES)); | 1264 scoped_refptr<const Extension> extension(CreateExtension(CLIENT_ID | SCOPES)); |
| 1260 scoped_refptr<FakeGetAuthTokenFunction> func(new FakeGetAuthTokenFunction()); | 1265 scoped_refptr<FakeGetAuthTokenFunction> func(new FakeGetAuthTokenFunction()); |
| 1261 func->set_extension(extension.get()); | 1266 func->set_extension(extension.get()); |
| 1262 | 1267 |
| 1263 func->set_mint_token_flow(make_scoped_ptr(new TestHangOAuth2MintTokenFlow())); | 1268 func->set_mint_token_flow( |
| 1269 base::WrapUnique(new TestHangOAuth2MintTokenFlow())); |
| 1264 RunFunctionAsync(func.get(), "[{\"interactive\": false}]"); | 1270 RunFunctionAsync(func.get(), "[{\"interactive\": false}]"); |
| 1265 | 1271 |
| 1266 // After the request is canceled, the function will complete. | 1272 // After the request is canceled, the function will complete. |
| 1267 func->OnShutdown(); | 1273 func->OnShutdown(); |
| 1268 EXPECT_EQ(std::string(errors::kCanceled), WaitForError(func.get())); | 1274 EXPECT_EQ(std::string(errors::kCanceled), WaitForError(func.get())); |
| 1269 } | 1275 } |
| 1270 | 1276 |
| 1271 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, | 1277 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, |
| 1272 InteractiveQueuedNoninteractiveFails) { | 1278 InteractiveQueuedNoninteractiveFails) { |
| 1273 SignIn("primary@example.com"); | 1279 SignIn("primary@example.com"); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 1300 scoped_refptr<const Extension> extension(CreateExtension(CLIENT_ID | SCOPES)); | 1306 scoped_refptr<const Extension> extension(CreateExtension(CLIENT_ID | SCOPES)); |
| 1301 scoped_refptr<FakeGetAuthTokenFunction> func(new FakeGetAuthTokenFunction()); | 1307 scoped_refptr<FakeGetAuthTokenFunction> func(new FakeGetAuthTokenFunction()); |
| 1302 func->set_extension(extension.get()); | 1308 func->set_extension(extension.get()); |
| 1303 | 1309 |
| 1304 // pre-populate the cache with a token | 1310 // pre-populate the cache with a token |
| 1305 IdentityTokenCacheValue token(kAccessToken, | 1311 IdentityTokenCacheValue token(kAccessToken, |
| 1306 base::TimeDelta::FromSeconds(3600)); | 1312 base::TimeDelta::FromSeconds(3600)); |
| 1307 SetCachedToken(token); | 1313 SetCachedToken(token); |
| 1308 | 1314 |
| 1309 // Get a token. Should not require a GAIA request. | 1315 // Get a token. Should not require a GAIA request. |
| 1310 scoped_ptr<base::Value> value(utils::RunFunctionAndReturnSingleResult( | 1316 std::unique_ptr<base::Value> value( |
| 1311 func.get(), "[{}]", browser())); | 1317 utils::RunFunctionAndReturnSingleResult(func.get(), "[{}]", browser())); |
| 1312 std::string access_token; | 1318 std::string access_token; |
| 1313 EXPECT_TRUE(value->GetAsString(&access_token)); | 1319 EXPECT_TRUE(value->GetAsString(&access_token)); |
| 1314 EXPECT_EQ(std::string(kAccessToken), access_token); | 1320 EXPECT_EQ(std::string(kAccessToken), access_token); |
| 1315 EXPECT_FALSE(func->login_ui_shown()); | 1321 EXPECT_FALSE(func->login_ui_shown()); |
| 1316 EXPECT_FALSE(func->scope_ui_shown()); | 1322 EXPECT_FALSE(func->scope_ui_shown()); |
| 1317 } | 1323 } |
| 1318 | 1324 |
| 1319 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, | 1325 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, |
| 1320 NonInteractiveIssueAdviceCacheHit) { | 1326 NonInteractiveIssueAdviceCacheHit) { |
| 1321 SignIn("primary@example.com"); | 1327 SignIn("primary@example.com"); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1359 // Populate the cache with a token while the request is blocked. | 1365 // Populate the cache with a token while the request is blocked. |
| 1360 IdentityTokenCacheValue token(kAccessToken, | 1366 IdentityTokenCacheValue token(kAccessToken, |
| 1361 base::TimeDelta::FromSeconds(3600)); | 1367 base::TimeDelta::FromSeconds(3600)); |
| 1362 SetCachedToken(token); | 1368 SetCachedToken(token); |
| 1363 | 1369 |
| 1364 // When we wake up the request, it returns the cached token without | 1370 // When we wake up the request, it returns the cached token without |
| 1365 // displaying a UI, or hitting GAIA. | 1371 // displaying a UI, or hitting GAIA. |
| 1366 | 1372 |
| 1367 QueueRequestComplete(type, &queued_request); | 1373 QueueRequestComplete(type, &queued_request); |
| 1368 | 1374 |
| 1369 scoped_ptr<base::Value> value(WaitForSingleResult(func.get())); | 1375 std::unique_ptr<base::Value> value(WaitForSingleResult(func.get())); |
| 1370 std::string access_token; | 1376 std::string access_token; |
| 1371 EXPECT_TRUE(value->GetAsString(&access_token)); | 1377 EXPECT_TRUE(value->GetAsString(&access_token)); |
| 1372 EXPECT_EQ(std::string(kAccessToken), access_token); | 1378 EXPECT_EQ(std::string(kAccessToken), access_token); |
| 1373 EXPECT_FALSE(func->login_ui_shown()); | 1379 EXPECT_FALSE(func->login_ui_shown()); |
| 1374 EXPECT_FALSE(func->scope_ui_shown()); | 1380 EXPECT_FALSE(func->scope_ui_shown()); |
| 1375 } | 1381 } |
| 1376 | 1382 |
| 1377 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, | 1383 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, |
| 1378 LoginInvalidatesTokenCache) { | 1384 LoginInvalidatesTokenCache) { |
| 1379 scoped_refptr<FakeGetAuthTokenFunction> func(new FakeGetAuthTokenFunction()); | 1385 scoped_refptr<FakeGetAuthTokenFunction> func(new FakeGetAuthTokenFunction()); |
| 1380 scoped_refptr<const Extension> extension(CreateExtension(CLIENT_ID | SCOPES)); | 1386 scoped_refptr<const Extension> extension(CreateExtension(CLIENT_ID | SCOPES)); |
| 1381 func->set_extension(extension.get()); | 1387 func->set_extension(extension.get()); |
| 1382 | 1388 |
| 1383 // pre-populate the cache with a token | 1389 // pre-populate the cache with a token |
| 1384 IdentityTokenCacheValue token(kAccessToken, | 1390 IdentityTokenCacheValue token(kAccessToken, |
| 1385 base::TimeDelta::FromSeconds(3600)); | 1391 base::TimeDelta::FromSeconds(3600)); |
| 1386 SetCachedToken(token); | 1392 SetCachedToken(token); |
| 1387 | 1393 |
| 1388 // Because the user is not signed in, the token will be removed, | 1394 // Because the user is not signed in, the token will be removed, |
| 1389 // and we'll hit GAIA for new tokens. | 1395 // and we'll hit GAIA for new tokens. |
| 1390 func->set_login_ui_result(true); | 1396 func->set_login_ui_result(true); |
| 1391 func->set_mint_token_result(TestOAuth2MintTokenFlow::ISSUE_ADVICE_SUCCESS); | 1397 func->set_mint_token_result(TestOAuth2MintTokenFlow::ISSUE_ADVICE_SUCCESS); |
| 1392 | 1398 |
| 1393 scoped_ptr<base::Value> value(utils::RunFunctionAndReturnSingleResult( | 1399 std::unique_ptr<base::Value> value(utils::RunFunctionAndReturnSingleResult( |
| 1394 func.get(), "[{\"interactive\": true}]", browser())); | 1400 func.get(), "[{\"interactive\": true}]", browser())); |
| 1395 std::string access_token; | 1401 std::string access_token; |
| 1396 EXPECT_TRUE(value->GetAsString(&access_token)); | 1402 EXPECT_TRUE(value->GetAsString(&access_token)); |
| 1397 EXPECT_EQ(std::string(kAccessToken), access_token); | 1403 EXPECT_EQ(std::string(kAccessToken), access_token); |
| 1398 EXPECT_TRUE(func->login_ui_shown()); | 1404 EXPECT_TRUE(func->login_ui_shown()); |
| 1399 EXPECT_TRUE(func->scope_ui_shown()); | 1405 EXPECT_TRUE(func->scope_ui_shown()); |
| 1400 EXPECT_EQ(IdentityTokenCacheValue::CACHE_STATUS_TOKEN, | 1406 EXPECT_EQ(IdentityTokenCacheValue::CACHE_STATUS_TOKEN, |
| 1401 GetCachedToken(std::string()).status()); | 1407 GetCachedToken(std::string()).status()); |
| 1402 } | 1408 } |
| 1403 | 1409 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 1428 scoped_refptr<FakeGetAuthTokenFunction> func(new FakeGetAuthTokenFunction()); | 1434 scoped_refptr<FakeGetAuthTokenFunction> func(new FakeGetAuthTokenFunction()); |
| 1429 scoped_refptr<const Extension> extension(CreateExtension(CLIENT_ID | SCOPES)); | 1435 scoped_refptr<const Extension> extension(CreateExtension(CLIENT_ID | SCOPES)); |
| 1430 func->set_extension(extension.get()); | 1436 func->set_extension(extension.get()); |
| 1431 func->set_auto_login_access_token(false); | 1437 func->set_auto_login_access_token(false); |
| 1432 func->set_mint_token_result(TestOAuth2MintTokenFlow::MINT_TOKEN_SUCCESS); | 1438 func->set_mint_token_result(TestOAuth2MintTokenFlow::MINT_TOKEN_SUCCESS); |
| 1433 | 1439 |
| 1434 RunFunctionAsync(func.get(), "[{}]"); | 1440 RunFunctionAsync(func.get(), "[{}]"); |
| 1435 | 1441 |
| 1436 IssueLoginAccessTokenForAccount("primary@example.com"); | 1442 IssueLoginAccessTokenForAccount("primary@example.com"); |
| 1437 | 1443 |
| 1438 scoped_ptr<base::Value> value(WaitForSingleResult(func.get())); | 1444 std::unique_ptr<base::Value> value(WaitForSingleResult(func.get())); |
| 1439 std::string access_token; | 1445 std::string access_token; |
| 1440 EXPECT_TRUE(value->GetAsString(&access_token)); | 1446 EXPECT_TRUE(value->GetAsString(&access_token)); |
| 1441 EXPECT_EQ(std::string(kAccessToken), access_token); | 1447 EXPECT_EQ(std::string(kAccessToken), access_token); |
| 1442 EXPECT_EQ(IdentityTokenCacheValue::CACHE_STATUS_TOKEN, | 1448 EXPECT_EQ(IdentityTokenCacheValue::CACHE_STATUS_TOKEN, |
| 1443 GetCachedToken(std::string()).status()); | 1449 GetCachedToken(std::string()).status()); |
| 1444 EXPECT_EQ("access_token-primary@example.com", func->login_access_token()); | 1450 EXPECT_EQ("access_token-primary@example.com", func->login_access_token()); |
| 1445 } | 1451 } |
| 1446 | 1452 |
| 1447 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, MultiPrimaryUser) { | 1453 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, MultiPrimaryUser) { |
| 1448 SignIn("primary@example.com"); | 1454 SignIn("primary@example.com"); |
| 1449 IssueLoginRefreshTokenForAccount("secondary@example.com"); | 1455 IssueLoginRefreshTokenForAccount("secondary@example.com"); |
| 1450 SetAccountState(CreateIds("primary@example.com", "1"), true); | 1456 SetAccountState(CreateIds("primary@example.com", "1"), true); |
| 1451 SetAccountState(CreateIds("secondary@example.com", "2"), true); | 1457 SetAccountState(CreateIds("secondary@example.com", "2"), true); |
| 1452 | 1458 |
| 1453 scoped_refptr<FakeGetAuthTokenFunction> func(new FakeGetAuthTokenFunction()); | 1459 scoped_refptr<FakeGetAuthTokenFunction> func(new FakeGetAuthTokenFunction()); |
| 1454 scoped_refptr<const Extension> extension(CreateExtension(CLIENT_ID | SCOPES)); | 1460 scoped_refptr<const Extension> extension(CreateExtension(CLIENT_ID | SCOPES)); |
| 1455 func->set_extension(extension.get()); | 1461 func->set_extension(extension.get()); |
| 1456 func->set_auto_login_access_token(false); | 1462 func->set_auto_login_access_token(false); |
| 1457 func->set_mint_token_result(TestOAuth2MintTokenFlow::MINT_TOKEN_SUCCESS); | 1463 func->set_mint_token_result(TestOAuth2MintTokenFlow::MINT_TOKEN_SUCCESS); |
| 1458 | 1464 |
| 1459 RunFunctionAsync(func.get(), "[{\"account\": { \"id\": \"1\" } }]"); | 1465 RunFunctionAsync(func.get(), "[{\"account\": { \"id\": \"1\" } }]"); |
| 1460 | 1466 |
| 1461 IssueLoginAccessTokenForAccount("primary@example.com"); | 1467 IssueLoginAccessTokenForAccount("primary@example.com"); |
| 1462 | 1468 |
| 1463 scoped_ptr<base::Value> value(WaitForSingleResult(func.get())); | 1469 std::unique_ptr<base::Value> value(WaitForSingleResult(func.get())); |
| 1464 std::string access_token; | 1470 std::string access_token; |
| 1465 EXPECT_TRUE(value->GetAsString(&access_token)); | 1471 EXPECT_TRUE(value->GetAsString(&access_token)); |
| 1466 EXPECT_EQ(std::string(kAccessToken), access_token); | 1472 EXPECT_EQ(std::string(kAccessToken), access_token); |
| 1467 EXPECT_EQ(IdentityTokenCacheValue::CACHE_STATUS_TOKEN, | 1473 EXPECT_EQ(IdentityTokenCacheValue::CACHE_STATUS_TOKEN, |
| 1468 GetCachedToken(std::string()).status()); | 1474 GetCachedToken(std::string()).status()); |
| 1469 EXPECT_EQ("access_token-primary@example.com", func->login_access_token()); | 1475 EXPECT_EQ("access_token-primary@example.com", func->login_access_token()); |
| 1470 } | 1476 } |
| 1471 | 1477 |
| 1472 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, MultiSecondaryUser) { | 1478 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, MultiSecondaryUser) { |
| 1473 SignIn("primary@example.com"); | 1479 SignIn("primary@example.com"); |
| 1474 IssueLoginRefreshTokenForAccount("secondary@example.com"); | 1480 IssueLoginRefreshTokenForAccount("secondary@example.com"); |
| 1475 SetAccountState(CreateIds("primary@example.com", "1"), true); | 1481 SetAccountState(CreateIds("primary@example.com", "1"), true); |
| 1476 SetAccountState(CreateIds("secondary@example.com", "2"), true); | 1482 SetAccountState(CreateIds("secondary@example.com", "2"), true); |
| 1477 | 1483 |
| 1478 scoped_refptr<FakeGetAuthTokenFunction> func(new FakeGetAuthTokenFunction()); | 1484 scoped_refptr<FakeGetAuthTokenFunction> func(new FakeGetAuthTokenFunction()); |
| 1479 scoped_refptr<const Extension> extension(CreateExtension(CLIENT_ID | SCOPES)); | 1485 scoped_refptr<const Extension> extension(CreateExtension(CLIENT_ID | SCOPES)); |
| 1480 func->set_extension(extension.get()); | 1486 func->set_extension(extension.get()); |
| 1481 func->set_auto_login_access_token(false); | 1487 func->set_auto_login_access_token(false); |
| 1482 func->set_mint_token_result(TestOAuth2MintTokenFlow::MINT_TOKEN_SUCCESS); | 1488 func->set_mint_token_result(TestOAuth2MintTokenFlow::MINT_TOKEN_SUCCESS); |
| 1483 | 1489 |
| 1484 RunFunctionAsync(func.get(), "[{\"account\": { \"id\": \"2\" } }]"); | 1490 RunFunctionAsync(func.get(), "[{\"account\": { \"id\": \"2\" } }]"); |
| 1485 | 1491 |
| 1486 IssueLoginAccessTokenForAccount("secondary@example.com"); | 1492 IssueLoginAccessTokenForAccount("secondary@example.com"); |
| 1487 | 1493 |
| 1488 scoped_ptr<base::Value> value(WaitForSingleResult(func.get())); | 1494 std::unique_ptr<base::Value> value(WaitForSingleResult(func.get())); |
| 1489 std::string access_token; | 1495 std::string access_token; |
| 1490 EXPECT_TRUE(value->GetAsString(&access_token)); | 1496 EXPECT_TRUE(value->GetAsString(&access_token)); |
| 1491 EXPECT_EQ(std::string(kAccessToken), access_token); | 1497 EXPECT_EQ(std::string(kAccessToken), access_token); |
| 1492 EXPECT_EQ(IdentityTokenCacheValue::CACHE_STATUS_TOKEN, | 1498 EXPECT_EQ(IdentityTokenCacheValue::CACHE_STATUS_TOKEN, |
| 1493 GetCachedToken("secondary@example.com").status()); | 1499 GetCachedToken("secondary@example.com").status()); |
| 1494 EXPECT_EQ("access_token-secondary@example.com", func->login_access_token()); | 1500 EXPECT_EQ("access_token-secondary@example.com", func->login_access_token()); |
| 1495 } | 1501 } |
| 1496 | 1502 |
| 1497 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, MultiUnknownUser) { | 1503 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, MultiUnknownUser) { |
| 1498 SignIn("primary@example.com"); | 1504 SignIn("primary@example.com"); |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1563 EXPECT_FALSE(func->login_ui_shown()); | 1569 EXPECT_FALSE(func->login_ui_shown()); |
| 1564 EXPECT_TRUE(func->scope_ui_shown()); | 1570 EXPECT_TRUE(func->scope_ui_shown()); |
| 1565 } | 1571 } |
| 1566 | 1572 |
| 1567 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, ScopesDefault) { | 1573 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, ScopesDefault) { |
| 1568 SignIn("primary@example.com"); | 1574 SignIn("primary@example.com"); |
| 1569 scoped_refptr<FakeGetAuthTokenFunction> func(new FakeGetAuthTokenFunction()); | 1575 scoped_refptr<FakeGetAuthTokenFunction> func(new FakeGetAuthTokenFunction()); |
| 1570 scoped_refptr<const Extension> extension(CreateExtension(CLIENT_ID | SCOPES)); | 1576 scoped_refptr<const Extension> extension(CreateExtension(CLIENT_ID | SCOPES)); |
| 1571 func->set_extension(extension.get()); | 1577 func->set_extension(extension.get()); |
| 1572 func->set_mint_token_result(TestOAuth2MintTokenFlow::MINT_TOKEN_SUCCESS); | 1578 func->set_mint_token_result(TestOAuth2MintTokenFlow::MINT_TOKEN_SUCCESS); |
| 1573 scoped_ptr<base::Value> value( | 1579 std::unique_ptr<base::Value> value( |
| 1574 utils::RunFunctionAndReturnSingleResult(func.get(), "[{}]", browser())); | 1580 utils::RunFunctionAndReturnSingleResult(func.get(), "[{}]", browser())); |
| 1575 std::string access_token; | 1581 std::string access_token; |
| 1576 EXPECT_TRUE(value->GetAsString(&access_token)); | 1582 EXPECT_TRUE(value->GetAsString(&access_token)); |
| 1577 EXPECT_EQ(std::string(kAccessToken), access_token); | 1583 EXPECT_EQ(std::string(kAccessToken), access_token); |
| 1578 | 1584 |
| 1579 const ExtensionTokenKey* token_key = func->GetExtensionTokenKeyForTest(); | 1585 const ExtensionTokenKey* token_key = func->GetExtensionTokenKeyForTest(); |
| 1580 EXPECT_EQ(2ul, token_key->scopes.size()); | 1586 EXPECT_EQ(2ul, token_key->scopes.size()); |
| 1581 EXPECT_TRUE(ContainsKey(token_key->scopes, "scope1")); | 1587 EXPECT_TRUE(ContainsKey(token_key->scopes, "scope1")); |
| 1582 EXPECT_TRUE(ContainsKey(token_key->scopes, "scope2")); | 1588 EXPECT_TRUE(ContainsKey(token_key->scopes, "scope2")); |
| 1583 } | 1589 } |
| 1584 | 1590 |
| 1585 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, ScopesEmpty) { | 1591 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, ScopesEmpty) { |
| 1586 scoped_refptr<FakeGetAuthTokenFunction> func(new FakeGetAuthTokenFunction()); | 1592 scoped_refptr<FakeGetAuthTokenFunction> func(new FakeGetAuthTokenFunction()); |
| 1587 scoped_refptr<const Extension> extension(CreateExtension(CLIENT_ID | SCOPES)); | 1593 scoped_refptr<const Extension> extension(CreateExtension(CLIENT_ID | SCOPES)); |
| 1588 func->set_extension(extension.get()); | 1594 func->set_extension(extension.get()); |
| 1589 | 1595 |
| 1590 std::string error(utils::RunFunctionAndReturnError( | 1596 std::string error(utils::RunFunctionAndReturnError( |
| 1591 func.get(), "[{\"scopes\": []}]", browser())); | 1597 func.get(), "[{\"scopes\": []}]", browser())); |
| 1592 | 1598 |
| 1593 EXPECT_EQ(errors::kInvalidScopes, error); | 1599 EXPECT_EQ(errors::kInvalidScopes, error); |
| 1594 } | 1600 } |
| 1595 | 1601 |
| 1596 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, ScopesEmail) { | 1602 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, ScopesEmail) { |
| 1597 SignIn("primary@example.com"); | 1603 SignIn("primary@example.com"); |
| 1598 scoped_refptr<FakeGetAuthTokenFunction> func(new FakeGetAuthTokenFunction()); | 1604 scoped_refptr<FakeGetAuthTokenFunction> func(new FakeGetAuthTokenFunction()); |
| 1599 scoped_refptr<const Extension> extension(CreateExtension(CLIENT_ID | SCOPES)); | 1605 scoped_refptr<const Extension> extension(CreateExtension(CLIENT_ID | SCOPES)); |
| 1600 func->set_extension(extension.get()); | 1606 func->set_extension(extension.get()); |
| 1601 func->set_mint_token_result(TestOAuth2MintTokenFlow::MINT_TOKEN_SUCCESS); | 1607 func->set_mint_token_result(TestOAuth2MintTokenFlow::MINT_TOKEN_SUCCESS); |
| 1602 scoped_ptr<base::Value> value(utils::RunFunctionAndReturnSingleResult( | 1608 std::unique_ptr<base::Value> value(utils::RunFunctionAndReturnSingleResult( |
| 1603 func.get(), "[{\"scopes\": [\"email\"]}]", browser())); | 1609 func.get(), "[{\"scopes\": [\"email\"]}]", browser())); |
| 1604 std::string access_token; | 1610 std::string access_token; |
| 1605 EXPECT_TRUE(value->GetAsString(&access_token)); | 1611 EXPECT_TRUE(value->GetAsString(&access_token)); |
| 1606 EXPECT_EQ(std::string(kAccessToken), access_token); | 1612 EXPECT_EQ(std::string(kAccessToken), access_token); |
| 1607 | 1613 |
| 1608 const ExtensionTokenKey* token_key = func->GetExtensionTokenKeyForTest(); | 1614 const ExtensionTokenKey* token_key = func->GetExtensionTokenKeyForTest(); |
| 1609 EXPECT_EQ(1ul, token_key->scopes.size()); | 1615 EXPECT_EQ(1ul, token_key->scopes.size()); |
| 1610 EXPECT_TRUE(ContainsKey(token_key->scopes, "email")); | 1616 EXPECT_TRUE(ContainsKey(token_key->scopes, "email")); |
| 1611 } | 1617 } |
| 1612 | 1618 |
| 1613 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, ScopesEmailFooBar) { | 1619 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, ScopesEmailFooBar) { |
| 1614 SignIn("primary@example.com"); | 1620 SignIn("primary@example.com"); |
| 1615 scoped_refptr<FakeGetAuthTokenFunction> func(new FakeGetAuthTokenFunction()); | 1621 scoped_refptr<FakeGetAuthTokenFunction> func(new FakeGetAuthTokenFunction()); |
| 1616 scoped_refptr<const Extension> extension(CreateExtension(CLIENT_ID | SCOPES)); | 1622 scoped_refptr<const Extension> extension(CreateExtension(CLIENT_ID | SCOPES)); |
| 1617 func->set_extension(extension.get()); | 1623 func->set_extension(extension.get()); |
| 1618 func->set_mint_token_result(TestOAuth2MintTokenFlow::MINT_TOKEN_SUCCESS); | 1624 func->set_mint_token_result(TestOAuth2MintTokenFlow::MINT_TOKEN_SUCCESS); |
| 1619 scoped_ptr<base::Value> value(utils::RunFunctionAndReturnSingleResult( | 1625 std::unique_ptr<base::Value> value(utils::RunFunctionAndReturnSingleResult( |
| 1620 func.get(), "[{\"scopes\": [\"email\", \"foo\", \"bar\"]}]", browser())); | 1626 func.get(), "[{\"scopes\": [\"email\", \"foo\", \"bar\"]}]", browser())); |
| 1621 std::string access_token; | 1627 std::string access_token; |
| 1622 EXPECT_TRUE(value->GetAsString(&access_token)); | 1628 EXPECT_TRUE(value->GetAsString(&access_token)); |
| 1623 EXPECT_EQ(std::string(kAccessToken), access_token); | 1629 EXPECT_EQ(std::string(kAccessToken), access_token); |
| 1624 | 1630 |
| 1625 const ExtensionTokenKey* token_key = func->GetExtensionTokenKeyForTest(); | 1631 const ExtensionTokenKey* token_key = func->GetExtensionTokenKeyForTest(); |
| 1626 EXPECT_EQ(3ul, token_key->scopes.size()); | 1632 EXPECT_EQ(3ul, token_key->scopes.size()); |
| 1627 EXPECT_TRUE(ContainsKey(token_key->scopes, "email")); | 1633 EXPECT_TRUE(ContainsKey(token_key->scopes, "email")); |
| 1628 EXPECT_TRUE(ContainsKey(token_key->scopes, "foo")); | 1634 EXPECT_TRUE(ContainsKey(token_key->scopes, "foo")); |
| 1629 EXPECT_TRUE(ContainsKey(token_key->scopes, "bar")); | 1635 EXPECT_TRUE(ContainsKey(token_key->scopes, "bar")); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 1641 GetAuthTokenFunctionTest::SetUpInProcessBrowserTestFixture(); | 1647 GetAuthTokenFunctionTest::SetUpInProcessBrowserTestFixture(); |
| 1642 | 1648 |
| 1643 // Set up the user manager to fake a public session. | 1649 // Set up the user manager to fake a public session. |
| 1644 EXPECT_CALL(*user_manager_, IsLoggedInAsKioskApp()) | 1650 EXPECT_CALL(*user_manager_, IsLoggedInAsKioskApp()) |
| 1645 .WillRepeatedly(Return(false)); | 1651 .WillRepeatedly(Return(false)); |
| 1646 EXPECT_CALL(*user_manager_, IsLoggedInAsPublicAccount()) | 1652 EXPECT_CALL(*user_manager_, IsLoggedInAsPublicAccount()) |
| 1647 .WillRepeatedly(Return(true)); | 1653 .WillRepeatedly(Return(true)); |
| 1648 | 1654 |
| 1649 // Set up fake install attributes to make the device appeared as | 1655 // Set up fake install attributes to make the device appeared as |
| 1650 // enterprise-managed. | 1656 // enterprise-managed. |
| 1651 scoped_ptr<policy::StubEnterpriseInstallAttributes> attributes( | 1657 std::unique_ptr<policy::StubEnterpriseInstallAttributes> attributes( |
| 1652 new policy::StubEnterpriseInstallAttributes()); | 1658 new policy::StubEnterpriseInstallAttributes()); |
| 1653 attributes->SetDomain("example.com"); | 1659 attributes->SetDomain("example.com"); |
| 1654 attributes->SetRegistrationUser("user@example.com"); | 1660 attributes->SetRegistrationUser("user@example.com"); |
| 1655 policy::BrowserPolicyConnectorChromeOS::SetInstallAttributesForTesting( | 1661 policy::BrowserPolicyConnectorChromeOS::SetInstallAttributesForTesting( |
| 1656 attributes.release()); | 1662 attributes.release()); |
| 1657 } | 1663 } |
| 1658 | 1664 |
| 1659 scoped_refptr<Extension> CreateTestExtension(const std::string& id) { | 1665 scoped_refptr<Extension> CreateTestExtension(const std::string& id) { |
| 1660 return ExtensionBuilder() | 1666 return ExtensionBuilder() |
| 1661 .SetManifest( | 1667 .SetManifest( |
| 1662 DictionaryBuilder() | 1668 DictionaryBuilder() |
| 1663 .Set("name", "Test") | 1669 .Set("name", "Test") |
| 1664 .Set("version", "1.0") | 1670 .Set("version", "1.0") |
| 1665 .Set("oauth2", | 1671 .Set("oauth2", |
| 1666 DictionaryBuilder() | 1672 DictionaryBuilder() |
| (...skipping 22 matching lines...) Expand all Loading... |
| 1689 EXPECT_FALSE(func->login_ui_shown()); | 1695 EXPECT_FALSE(func->login_ui_shown()); |
| 1690 EXPECT_FALSE(func->scope_ui_shown()); | 1696 EXPECT_FALSE(func->scope_ui_shown()); |
| 1691 } | 1697 } |
| 1692 | 1698 |
| 1693 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionPublicSessionTest, Whitelisted) { | 1699 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionPublicSessionTest, Whitelisted) { |
| 1694 // GetAuthToken() should return a token for whitelisted extensions. | 1700 // GetAuthToken() should return a token for whitelisted extensions. |
| 1695 chromeos::ScopedUserManagerEnabler user_manager_enabler(user_manager_); | 1701 chromeos::ScopedUserManagerEnabler user_manager_enabler(user_manager_); |
| 1696 scoped_refptr<FakeGetAuthTokenFunction> func(new FakeGetAuthTokenFunction()); | 1702 scoped_refptr<FakeGetAuthTokenFunction> func(new FakeGetAuthTokenFunction()); |
| 1697 func->set_extension(CreateTestExtension("ljacajndfccfgnfohlgkdphmbnpkjflk")); | 1703 func->set_extension(CreateTestExtension("ljacajndfccfgnfohlgkdphmbnpkjflk")); |
| 1698 func->set_mint_token_result(TestOAuth2MintTokenFlow::MINT_TOKEN_SUCCESS); | 1704 func->set_mint_token_result(TestOAuth2MintTokenFlow::MINT_TOKEN_SUCCESS); |
| 1699 scoped_ptr<base::Value> value( | 1705 std::unique_ptr<base::Value> value( |
| 1700 utils::RunFunctionAndReturnSingleResult(func.get(), "[{}]", browser())); | 1706 utils::RunFunctionAndReturnSingleResult(func.get(), "[{}]", browser())); |
| 1701 std::string access_token; | 1707 std::string access_token; |
| 1702 EXPECT_TRUE(value->GetAsString(&access_token)); | 1708 EXPECT_TRUE(value->GetAsString(&access_token)); |
| 1703 EXPECT_EQ(std::string(kAccessToken), access_token); | 1709 EXPECT_EQ(std::string(kAccessToken), access_token); |
| 1704 } | 1710 } |
| 1705 | 1711 |
| 1706 #endif | 1712 #endif |
| 1707 | 1713 |
| 1708 | 1714 |
| 1709 class RemoveCachedAuthTokenFunctionTest : public ExtensionBrowserTest { | 1715 class RemoveCachedAuthTokenFunctionTest : public ExtensionBrowserTest { |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1851 switches::kAshBrowserTests)) | 1857 switches::kAshBrowserTests)) |
| 1852 return; | 1858 return; |
| 1853 #endif | 1859 #endif |
| 1854 | 1860 |
| 1855 scoped_refptr<IdentityLaunchWebAuthFlowFunction> function( | 1861 scoped_refptr<IdentityLaunchWebAuthFlowFunction> function( |
| 1856 new IdentityLaunchWebAuthFlowFunction()); | 1862 new IdentityLaunchWebAuthFlowFunction()); |
| 1857 scoped_refptr<Extension> empty_extension(test_util::CreateEmptyExtension()); | 1863 scoped_refptr<Extension> empty_extension(test_util::CreateEmptyExtension()); |
| 1858 function->set_extension(empty_extension.get()); | 1864 function->set_extension(empty_extension.get()); |
| 1859 | 1865 |
| 1860 function->InitFinalRedirectURLPrefixForTest("abcdefghij"); | 1866 function->InitFinalRedirectURLPrefixForTest("abcdefghij"); |
| 1861 scoped_ptr<base::Value> value(utils::RunFunctionAndReturnSingleResult( | 1867 std::unique_ptr<base::Value> value(utils::RunFunctionAndReturnSingleResult( |
| 1862 function.get(), | 1868 function.get(), |
| 1863 "[{\"interactive\": false," | 1869 "[{\"interactive\": false," |
| 1864 "\"url\": \"https://abcdefghij.chromiumapp.org/callback#test\"}]", | 1870 "\"url\": \"https://abcdefghij.chromiumapp.org/callback#test\"}]", |
| 1865 browser())); | 1871 browser())); |
| 1866 | 1872 |
| 1867 std::string url; | 1873 std::string url; |
| 1868 EXPECT_TRUE(value->GetAsString(&url)); | 1874 EXPECT_TRUE(value->GetAsString(&url)); |
| 1869 EXPECT_EQ(std::string("https://abcdefghij.chromiumapp.org/callback#test"), | 1875 EXPECT_EQ(std::string("https://abcdefghij.chromiumapp.org/callback#test"), |
| 1870 url); | 1876 url); |
| 1871 } | 1877 } |
| 1872 | 1878 |
| 1873 IN_PROC_BROWSER_TEST_F( | 1879 IN_PROC_BROWSER_TEST_F( |
| 1874 LaunchWebAuthFlowFunctionTest, InteractiveFirstNavigationSuccess) { | 1880 LaunchWebAuthFlowFunctionTest, InteractiveFirstNavigationSuccess) { |
| 1875 #if defined(OS_WIN) && defined(USE_ASH) | 1881 #if defined(OS_WIN) && defined(USE_ASH) |
| 1876 // Disable this test in Metro+Ash for now (http://crbug.com/262796). | 1882 // Disable this test in Metro+Ash for now (http://crbug.com/262796). |
| 1877 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 1883 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 1878 switches::kAshBrowserTests)) | 1884 switches::kAshBrowserTests)) |
| 1879 return; | 1885 return; |
| 1880 #endif | 1886 #endif |
| 1881 | 1887 |
| 1882 scoped_refptr<IdentityLaunchWebAuthFlowFunction> function( | 1888 scoped_refptr<IdentityLaunchWebAuthFlowFunction> function( |
| 1883 new IdentityLaunchWebAuthFlowFunction()); | 1889 new IdentityLaunchWebAuthFlowFunction()); |
| 1884 scoped_refptr<Extension> empty_extension(test_util::CreateEmptyExtension()); | 1890 scoped_refptr<Extension> empty_extension(test_util::CreateEmptyExtension()); |
| 1885 function->set_extension(empty_extension.get()); | 1891 function->set_extension(empty_extension.get()); |
| 1886 | 1892 |
| 1887 function->InitFinalRedirectURLPrefixForTest("abcdefghij"); | 1893 function->InitFinalRedirectURLPrefixForTest("abcdefghij"); |
| 1888 scoped_ptr<base::Value> value(utils::RunFunctionAndReturnSingleResult( | 1894 std::unique_ptr<base::Value> value(utils::RunFunctionAndReturnSingleResult( |
| 1889 function.get(), | 1895 function.get(), |
| 1890 "[{\"interactive\": true," | 1896 "[{\"interactive\": true," |
| 1891 "\"url\": \"https://abcdefghij.chromiumapp.org/callback#test\"}]", | 1897 "\"url\": \"https://abcdefghij.chromiumapp.org/callback#test\"}]", |
| 1892 browser())); | 1898 browser())); |
| 1893 | 1899 |
| 1894 std::string url; | 1900 std::string url; |
| 1895 EXPECT_TRUE(value->GetAsString(&url)); | 1901 EXPECT_TRUE(value->GetAsString(&url)); |
| 1896 EXPECT_EQ(std::string("https://abcdefghij.chromiumapp.org/callback#test"), | 1902 EXPECT_EQ(std::string("https://abcdefghij.chromiumapp.org/callback#test"), |
| 1897 url); | 1903 url); |
| 1898 } | 1904 } |
| 1899 | 1905 |
| 1900 IN_PROC_BROWSER_TEST_F(LaunchWebAuthFlowFunctionTest, | 1906 IN_PROC_BROWSER_TEST_F(LaunchWebAuthFlowFunctionTest, |
| 1901 DISABLED_InteractiveSecondNavigationSuccess) { | 1907 DISABLED_InteractiveSecondNavigationSuccess) { |
| 1902 net::EmbeddedTestServer https_server(net::EmbeddedTestServer::TYPE_HTTPS); | 1908 net::EmbeddedTestServer https_server(net::EmbeddedTestServer::TYPE_HTTPS); |
| 1903 https_server.ServeFilesFromSourceDirectory( | 1909 https_server.ServeFilesFromSourceDirectory( |
| 1904 "chrome/test/data/extensions/api_test/identity"); | 1910 "chrome/test/data/extensions/api_test/identity"); |
| 1905 ASSERT_TRUE(https_server.Start()); | 1911 ASSERT_TRUE(https_server.Start()); |
| 1906 GURL auth_url(https_server.GetURL("/redirect_to_chromiumapp.html")); | 1912 GURL auth_url(https_server.GetURL("/redirect_to_chromiumapp.html")); |
| 1907 | 1913 |
| 1908 scoped_refptr<IdentityLaunchWebAuthFlowFunction> function( | 1914 scoped_refptr<IdentityLaunchWebAuthFlowFunction> function( |
| 1909 new IdentityLaunchWebAuthFlowFunction()); | 1915 new IdentityLaunchWebAuthFlowFunction()); |
| 1910 scoped_refptr<Extension> empty_extension(test_util::CreateEmptyExtension()); | 1916 scoped_refptr<Extension> empty_extension(test_util::CreateEmptyExtension()); |
| 1911 function->set_extension(empty_extension.get()); | 1917 function->set_extension(empty_extension.get()); |
| 1912 | 1918 |
| 1913 function->InitFinalRedirectURLPrefixForTest("abcdefghij"); | 1919 function->InitFinalRedirectURLPrefixForTest("abcdefghij"); |
| 1914 std::string args = "[{\"interactive\": true, \"url\": \"" + | 1920 std::string args = "[{\"interactive\": true, \"url\": \"" + |
| 1915 auth_url.spec() + "\"}]"; | 1921 auth_url.spec() + "\"}]"; |
| 1916 scoped_ptr<base::Value> value( | 1922 std::unique_ptr<base::Value> value( |
| 1917 utils::RunFunctionAndReturnSingleResult(function.get(), args, browser())); | 1923 utils::RunFunctionAndReturnSingleResult(function.get(), args, browser())); |
| 1918 | 1924 |
| 1919 std::string url; | 1925 std::string url; |
| 1920 EXPECT_TRUE(value->GetAsString(&url)); | 1926 EXPECT_TRUE(value->GetAsString(&url)); |
| 1921 EXPECT_EQ(std::string("https://abcdefghij.chromiumapp.org/callback#test"), | 1927 EXPECT_EQ(std::string("https://abcdefghij.chromiumapp.org/callback#test"), |
| 1922 url); | 1928 url); |
| 1923 } | 1929 } |
| 1924 | 1930 |
| 1925 } // namespace extensions | 1931 } // namespace extensions |
| 1926 | 1932 |
| 1927 // Tests the chrome.identity API implemented by custom JS bindings . | 1933 // Tests the chrome.identity API implemented by custom JS bindings . |
| 1928 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, ChromeIdentityJsBindings) { | 1934 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, ChromeIdentityJsBindings) { |
| 1929 ASSERT_TRUE(RunExtensionTest("identity/js_bindings")) << message_; | 1935 ASSERT_TRUE(RunExtensionTest("identity/js_bindings")) << message_; |
| 1930 } | 1936 } |
| OLD | NEW |