| 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 <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
| 11 #include "base/strings/string_util.h" | 11 #include "base/strings/string_util.h" |
| 12 #include "base/strings/stringprintf.h" | 12 #include "base/strings/stringprintf.h" |
| 13 #include "base/values.h" | 13 #include "base/values.h" |
| 14 #include "chrome/browser/chrome_notification_types.h" | 14 #include "chrome/browser/chrome_notification_types.h" |
| 15 #include "chrome/browser/extensions/api/identity/identity_api.h" | 15 #include "chrome/browser/extensions/api/identity/identity_api.h" |
| 16 #include "chrome/browser/extensions/component_loader.h" | 16 #include "chrome/browser/extensions/component_loader.h" |
| 17 #include "chrome/browser/extensions/extension_apitest.h" | 17 #include "chrome/browser/extensions/extension_apitest.h" |
| 18 #include "chrome/browser/extensions/extension_browsertest.h" | 18 #include "chrome/browser/extensions/extension_browsertest.h" |
| 19 #include "chrome/browser/extensions/extension_function_test_utils.h" | 19 #include "chrome/browser/extensions/extension_function_test_utils.h" |
| 20 #include "chrome/browser/extensions/extension_service.h" | 20 #include "chrome/browser/extensions/extension_service.h" |
| 21 #include "chrome/browser/profiles/profile.h" | 21 #include "chrome/browser/profiles/profile.h" |
| 22 #include "chrome/browser/signin/account_reconcilor_factory.h" | |
| 23 #include "chrome/browser/signin/account_tracker_service_factory.h" | 22 #include "chrome/browser/signin/account_tracker_service_factory.h" |
| 24 #include "chrome/browser/signin/fake_account_reconcilor.h" | 23 #include "chrome/browser/signin/fake_gaia_cookie_manager_service.h" |
| 25 #include "chrome/browser/signin/fake_profile_oauth2_token_service.h" | 24 #include "chrome/browser/signin/fake_profile_oauth2_token_service.h" |
| 26 #include "chrome/browser/signin/fake_profile_oauth2_token_service_builder.h" | 25 #include "chrome/browser/signin/fake_profile_oauth2_token_service_builder.h" |
| 27 #include "chrome/browser/signin/fake_signin_manager.h" | 26 #include "chrome/browser/signin/fake_signin_manager.h" |
| 27 #include "chrome/browser/signin/gaia_cookie_manager_service_factory.h" |
| 28 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" | 28 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" |
| 29 #include "chrome/browser/signin/signin_manager_factory.h" | 29 #include "chrome/browser/signin/signin_manager_factory.h" |
| 30 #include "chrome/browser/ui/browser.h" | 30 #include "chrome/browser/ui/browser.h" |
| 31 #include "chrome/browser/ui/browser_window.h" | 31 #include "chrome/browser/ui/browser_window.h" |
| 32 #include "chrome/common/chrome_switches.h" | 32 #include "chrome/common/chrome_switches.h" |
| 33 #include "chrome/common/extensions/api/identity.h" | 33 #include "chrome/common/extensions/api/identity.h" |
| 34 #include "chrome/test/base/in_process_browser_test.h" | 34 #include "chrome/test/base/in_process_browser_test.h" |
| 35 #include "chrome/test/base/test_switches.h" | 35 #include "chrome/test/base/test_switches.h" |
| 36 #include "components/crx_file/id_util.h" | 36 #include "components/crx_file/id_util.h" |
| 37 #include "components/signin/core/browser/account_tracker_service.h" | 37 #include "components/signin/core/browser/account_tracker_service.h" |
| (...skipping 510 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 548 } | 548 } |
| 549 | 549 |
| 550 void OnWillCreateBrowserContextServices(content::BrowserContext* context) { | 550 void OnWillCreateBrowserContextServices(content::BrowserContext* context) { |
| 551 // Replace the signin manager and token service with fakes. Do this ahead of | 551 // Replace the signin manager and token service with fakes. Do this ahead of |
| 552 // creating the browser so that a bunch of classes don't register as | 552 // creating the browser so that a bunch of classes don't register as |
| 553 // observers and end up needing to unregister when the fake is substituted. | 553 // observers and end up needing to unregister when the fake is substituted. |
| 554 SigninManagerFactory::GetInstance()->SetTestingFactory( | 554 SigninManagerFactory::GetInstance()->SetTestingFactory( |
| 555 context, &FakeSigninManagerBase::Build); | 555 context, &FakeSigninManagerBase::Build); |
| 556 ProfileOAuth2TokenServiceFactory::GetInstance()->SetTestingFactory( | 556 ProfileOAuth2TokenServiceFactory::GetInstance()->SetTestingFactory( |
| 557 context, &BuildFakeProfileOAuth2TokenService); | 557 context, &BuildFakeProfileOAuth2TokenService); |
| 558 AccountReconcilorFactory::GetInstance()->SetTestingFactory( | 558 GaiaCookieManagerServiceFactory::GetInstance()->SetTestingFactory( |
| 559 context, &FakeAccountReconcilor::Build); | 559 context, &FakeGaiaCookieManagerService::Build); |
| 560 } | 560 } |
| 561 | 561 |
| 562 void SetUpOnMainThread() override { | 562 void SetUpOnMainThread() override { |
| 563 AsyncExtensionBrowserTest::SetUpOnMainThread(); | 563 AsyncExtensionBrowserTest::SetUpOnMainThread(); |
| 564 | 564 |
| 565 // Grab references to the fake signin manager and token service. | 565 // Grab references to the fake signin manager and token service. |
| 566 signin_manager_ = static_cast<FakeSigninManagerForTesting*>( | 566 signin_manager_ = static_cast<FakeSigninManagerForTesting*>( |
| 567 SigninManagerFactory::GetInstance()->GetForProfile(profile())); | 567 SigninManagerFactory::GetInstance()->GetForProfile(profile())); |
| 568 ASSERT_TRUE(signin_manager_); | 568 ASSERT_TRUE(signin_manager_); |
| 569 token_service_ = static_cast<FakeProfileOAuth2TokenService*>( | 569 token_service_ = static_cast<FakeProfileOAuth2TokenService*>( |
| 570 ProfileOAuth2TokenServiceFactory::GetInstance()->GetForProfile( | 570 ProfileOAuth2TokenServiceFactory::GetInstance()->GetForProfile( |
| 571 profile())); | 571 profile())); |
| 572 ASSERT_TRUE(token_service_); | 572 ASSERT_TRUE(token_service_); |
| 573 GaiaCookieManagerServiceFactory::GetInstance()->GetForProfile(profile()) |
| 574 ->Init(); |
| 573 } | 575 } |
| 574 | 576 |
| 575 protected: | 577 protected: |
| 576 void SignIn(const std::string account_key) { | 578 void SignIn(const std::string account_key) { |
| 577 #if defined(OS_CHROMEOS) | 579 #if defined(OS_CHROMEOS) |
| 578 signin_manager_->SetAuthenticatedUsername(account_key); | 580 signin_manager_->SetAuthenticatedUsername(account_key); |
| 579 #else | 581 #else |
| 580 signin_manager_->SignIn(account_key, "password"); | 582 signin_manager_->SignIn(account_key, "password"); |
| 581 #endif | 583 #endif |
| 582 token_service_->IssueRefreshTokenForUser(account_key, "refresh_token"); | 584 token_service_->IssueRefreshTokenForUser(account_key, "refresh_token"); |
| (...skipping 1238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1821 EXPECT_EQ(std::string("https://abcdefghij.chromiumapp.org/callback#test"), | 1823 EXPECT_EQ(std::string("https://abcdefghij.chromiumapp.org/callback#test"), |
| 1822 url); | 1824 url); |
| 1823 } | 1825 } |
| 1824 | 1826 |
| 1825 } // namespace extensions | 1827 } // namespace extensions |
| 1826 | 1828 |
| 1827 // Tests the chrome.identity API implemented by custom JS bindings . | 1829 // Tests the chrome.identity API implemented by custom JS bindings . |
| 1828 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, ChromeIdentityJsBindings) { | 1830 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, ChromeIdentityJsBindings) { |
| 1829 ASSERT_TRUE(RunExtensionTest("identity/js_bindings")) << message_; | 1831 ASSERT_TRUE(RunExtensionTest("identity/js_bindings")) << message_; |
| 1830 } | 1832 } |
| OLD | NEW |