| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "chrome/browser/ui/app_list/speech_auth_helper.h" | 5 #include "chrome/browser/ui/app_list/speech_auth_helper.h" |
| 6 | 6 |
| 7 #include <memory> |
| 7 #include <utility> | 8 #include <utility> |
| 8 | 9 |
| 9 #include "base/memory/scoped_ptr.h" | |
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| 11 #include "base/test/simple_test_clock.h" | 11 #include "base/test/simple_test_clock.h" |
| 12 #include "chrome/browser/signin/fake_profile_oauth2_token_service_builder.h" | 12 #include "chrome/browser/signin/fake_profile_oauth2_token_service_builder.h" |
| 13 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" | 13 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" |
| 14 #include "chrome/browser/signin/signin_manager_factory.h" | 14 #include "chrome/browser/signin/signin_manager_factory.h" |
| 15 #include "chrome/test/base/testing_browser_process.h" | 15 #include "chrome/test/base/testing_browser_process.h" |
| 16 #include "chrome/test/base/testing_profile.h" | 16 #include "chrome/test/base/testing_profile.h" |
| 17 #include "chrome/test/base/testing_profile_manager.h" | 17 #include "chrome/test/base/testing_profile_manager.h" |
| 18 #include "components/signin/core/browser/fake_profile_oauth2_token_service.h" | 18 #include "components/signin/core/browser/fake_profile_oauth2_token_service.h" |
| 19 #include "components/signin/core/browser/signin_manager.h" | 19 #include "components/signin/core/browser/signin_manager.h" |
| (...skipping 19 matching lines...) Expand all Loading... |
| 39 | 39 |
| 40 void SetUp() override { | 40 void SetUp() override { |
| 41 // Set up FakeProfileOAuth2TokenService. | 41 // Set up FakeProfileOAuth2TokenService. |
| 42 TestingProfile::TestingFactories factories; | 42 TestingProfile::TestingFactories factories; |
| 43 factories.push_back(std::make_pair( | 43 factories.push_back(std::make_pair( |
| 44 ProfileOAuth2TokenServiceFactory::GetInstance(), | 44 ProfileOAuth2TokenServiceFactory::GetInstance(), |
| 45 &BuildAutoIssuingFakeProfileOAuth2TokenService)); | 45 &BuildAutoIssuingFakeProfileOAuth2TokenService)); |
| 46 | 46 |
| 47 ASSERT_TRUE(testing_profile_manager_->SetUp()); | 47 ASSERT_TRUE(testing_profile_manager_->SetUp()); |
| 48 profile_ = testing_profile_manager_->CreateTestingProfile( | 48 profile_ = testing_profile_manager_->CreateTestingProfile( |
| 49 kTestUser, | 49 kTestUser, std::unique_ptr<syncable_prefs::PrefServiceSyncable>(), |
| 50 scoped_ptr<syncable_prefs::PrefServiceSyncable>(), | 50 base::UTF8ToUTF16(kTestUser), 0, std::string(), factories); |
| 51 base::UTF8ToUTF16(kTestUser), | |
| 52 0, | |
| 53 std::string(), | |
| 54 factories); | |
| 55 | 51 |
| 56 // Set up the authenticated user name and ID. | 52 // Set up the authenticated user name and ID. |
| 57 SigninManagerFactory::GetForProfile(profile_)->SetAuthenticatedAccountInfo( | 53 SigninManagerFactory::GetForProfile(profile_)->SetAuthenticatedAccountInfo( |
| 58 kTestGaiaId, kTestUser); | 54 kTestGaiaId, kTestUser); |
| 59 } | 55 } |
| 60 | 56 |
| 61 protected: | 57 protected: |
| 62 void SetupRefreshToken() { | 58 void SetupRefreshToken() { |
| 63 std::string account_id = SigninManagerFactory::GetForProfile(profile_) | 59 std::string account_id = SigninManagerFactory::GetForProfile(profile_) |
| 64 ->GetAuthenticatedAccountId(); | 60 ->GetAuthenticatedAccountId(); |
| 65 GetFakeProfileOAuth2TokenService()->UpdateCredentials(account_id, | 61 GetFakeProfileOAuth2TokenService()->UpdateCredentials(account_id, |
| 66 "fake_refresh_token"); | 62 "fake_refresh_token"); |
| 67 } | 63 } |
| 68 | 64 |
| 69 FakeProfileOAuth2TokenService* GetFakeProfileOAuth2TokenService() { | 65 FakeProfileOAuth2TokenService* GetFakeProfileOAuth2TokenService() { |
| 70 return static_cast<FakeProfileOAuth2TokenService*>( | 66 return static_cast<FakeProfileOAuth2TokenService*>( |
| 71 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_)); | 67 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_)); |
| 72 } | 68 } |
| 73 | 69 |
| 74 base::SimpleTestClock test_clock_; | 70 base::SimpleTestClock test_clock_; |
| 75 content::TestBrowserThreadBundle thread_bundle; | 71 content::TestBrowserThreadBundle thread_bundle; |
| 76 scoped_ptr<TestingProfileManager> testing_profile_manager_; | 72 std::unique_ptr<TestingProfileManager> testing_profile_manager_; |
| 77 Profile* profile_; | 73 Profile* profile_; |
| 78 scoped_ptr<SpeechAuthHelper> auth_helper_; | 74 std::unique_ptr<SpeechAuthHelper> auth_helper_; |
| 79 }; | 75 }; |
| 80 | 76 |
| 81 TEST_F(SpeechAuthHelperTest, TokenFetch) { | 77 TEST_F(SpeechAuthHelperTest, TokenFetch) { |
| 82 SetupRefreshToken(); | 78 SetupRefreshToken(); |
| 83 SpeechAuthHelper helper(profile_, &test_clock_); | 79 SpeechAuthHelper helper(profile_, &test_clock_); |
| 84 EXPECT_TRUE(helper.GetToken().empty()); | 80 EXPECT_TRUE(helper.GetToken().empty()); |
| 85 | 81 |
| 86 OAuth2TokenService::ScopeSet scopes; | 82 OAuth2TokenService::ScopeSet scopes; |
| 87 scopes.insert(kScope); | 83 scopes.insert(kScope); |
| 88 GetFakeProfileOAuth2TokenService()->IssueTokenForScope(scopes, | 84 GetFakeProfileOAuth2TokenService()->IssueTokenForScope(scopes, |
| (...skipping 27 matching lines...) Expand all Loading... |
| 116 OAuth2TokenService::ScopeSet scopes; | 112 OAuth2TokenService::ScopeSet scopes; |
| 117 scopes.insert(kScope); | 113 scopes.insert(kScope); |
| 118 GetFakeProfileOAuth2TokenService()->IssueErrorForScope( | 114 GetFakeProfileOAuth2TokenService()->IssueErrorForScope( |
| 119 scopes, GoogleServiceAuthError(GoogleServiceAuthError::SERVICE_ERROR)); | 115 scopes, GoogleServiceAuthError(GoogleServiceAuthError::SERVICE_ERROR)); |
| 120 | 116 |
| 121 EXPECT_TRUE(helper.GetToken().empty()); | 117 EXPECT_TRUE(helper.GetToken().empty()); |
| 122 EXPECT_EQ(kScope, helper.GetScope()); | 118 EXPECT_EQ(kScope, helper.GetScope()); |
| 123 } | 119 } |
| 124 | 120 |
| 125 } // namespace app_list | 121 } // namespace app_list |
| OLD | NEW |