| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "ios/public/provider/chrome/browser/test_chrome_browser_provider.h" | 5 #include "ios/public/provider/chrome/browser/test_chrome_browser_provider.h" |
| 6 | 6 |
| 7 #import <UIKit/UIKit.h> | 7 #import <UIKit/UIKit.h> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/mac/scoped_nsobject.h" | 10 #include "base/mac/scoped_nsobject.h" |
| 11 #include "base/memory/ptr_util.h" | 11 #include "base/memory/ptr_util.h" |
| 12 #include "ios/public/provider/chrome/browser/signin/fake_chrome_identity_service
.h" | 12 #include "ios/public/provider/chrome/browser/signin/fake_chrome_identity_service
.h" |
| 13 #import "ios/public/provider/chrome/browser/test_updatable_resource_provider.h" | 13 #import "ios/public/provider/chrome/browser/test_updatable_resource_provider.h" |
| 14 #import "ios/public/provider/chrome/browser/voice/test_voice_search_provider.h" |
| 14 #import "ios/public/provider/chrome/browser/voice/voice_search_language.h" | 15 #import "ios/public/provider/chrome/browser/voice/voice_search_language.h" |
| 15 | 16 |
| 16 @interface TestStyledTextField : UITextField<TextFieldStyling> | 17 @interface TestStyledTextField : UITextField<TextFieldStyling> |
| 17 @end | 18 @end |
| 18 | 19 |
| 19 @implementation TestStyledTextField | 20 @implementation TestStyledTextField |
| 20 @synthesize placeholderStyle = _placeholderStyle; | 21 @synthesize placeholderStyle = _placeholderStyle; |
| 21 @synthesize textValidator = _textValidator; | 22 @synthesize textValidator = _textValidator; |
| 22 | 23 |
| 23 - (void)setUseErrorStyling:(BOOL)error { | 24 - (void)setUseErrorStyling:(BOOL)error { |
| 24 } | 25 } |
| 25 @end | 26 @end |
| 26 | 27 |
| 27 namespace ios { | 28 namespace ios { |
| 28 | 29 |
| 29 TestChromeBrowserProvider::TestChromeBrowserProvider() | 30 TestChromeBrowserProvider::TestChromeBrowserProvider() |
| 30 : test_updatable_resource_provider_(new TestUpdatableResourceProvider) {} | 31 : updatable_resource_provider_( |
| 32 base::MakeUnique<TestUpdatableResourceProvider>()), |
| 33 voice_search_provider_(base::MakeUnique<TestVoiceSearchProvider>()) {} |
| 31 | 34 |
| 32 TestChromeBrowserProvider::~TestChromeBrowserProvider() {} | 35 TestChromeBrowserProvider::~TestChromeBrowserProvider() {} |
| 33 | 36 |
| 34 // static | 37 // static |
| 35 TestChromeBrowserProvider* TestChromeBrowserProvider::GetTestProvider() { | 38 TestChromeBrowserProvider* TestChromeBrowserProvider::GetTestProvider() { |
| 36 ChromeBrowserProvider* provider = GetChromeBrowserProvider(); | 39 ChromeBrowserProvider* provider = GetChromeBrowserProvider(); |
| 37 DCHECK(provider); | 40 DCHECK(provider); |
| 38 return static_cast<TestChromeBrowserProvider*>(provider); | 41 return static_cast<TestChromeBrowserProvider*>(provider); |
| 39 } | 42 } |
| 40 | 43 |
| 41 void TestChromeBrowserProvider::SetChromeIdentityServiceForTesting( | 44 void TestChromeBrowserProvider::SetChromeIdentityServiceForTesting( |
| 42 std::unique_ptr<ChromeIdentityService> service) { | 45 std::unique_ptr<ChromeIdentityService> service) { |
| 43 chrome_identity_service_.swap(service); | 46 chrome_identity_service_.swap(service); |
| 44 } | 47 } |
| 45 | 48 |
| 46 ChromeIdentityService* TestChromeBrowserProvider::GetChromeIdentityService() { | 49 ChromeIdentityService* TestChromeBrowserProvider::GetChromeIdentityService() { |
| 47 if (!chrome_identity_service_) { | 50 if (!chrome_identity_service_) { |
| 48 chrome_identity_service_.reset(new FakeChromeIdentityService()); | 51 chrome_identity_service_.reset(new FakeChromeIdentityService()); |
| 49 } | 52 } |
| 50 return chrome_identity_service_.get(); | 53 return chrome_identity_service_.get(); |
| 51 } | 54 } |
| 52 | 55 |
| 53 UpdatableResourceProvider* | 56 UpdatableResourceProvider* |
| 54 TestChromeBrowserProvider::GetUpdatableResourceProvider() { | 57 TestChromeBrowserProvider::GetUpdatableResourceProvider() { |
| 55 return test_updatable_resource_provider_.get(); | 58 return updatable_resource_provider_.get(); |
| 56 } | 59 } |
| 57 | 60 |
| 58 UITextField<TextFieldStyling>* TestChromeBrowserProvider::CreateStyledTextField( | 61 UITextField<TextFieldStyling>* TestChromeBrowserProvider::CreateStyledTextField( |
| 59 CGRect frame) const { | 62 CGRect frame) const { |
| 60 return [[TestStyledTextField alloc] initWithFrame:frame]; | 63 return [[TestStyledTextField alloc] initWithFrame:frame]; |
| 61 } | 64 } |
| 62 | 65 |
| 63 NSArray* TestChromeBrowserProvider::GetAvailableVoiceSearchLanguages() const { | 66 NSArray* TestChromeBrowserProvider::GetAvailableVoiceSearchLanguages() const { |
| 64 base::scoped_nsobject<VoiceSearchLanguage> en([[VoiceSearchLanguage alloc] | 67 return voice_search_provider_->GetAvailableLanguages(); |
| 65 initWithIdentifier:@"en-US" | 68 } |
| 66 displayName:@"English (US)" | 69 |
| 67 localizationPreference:nil]); | 70 VoiceSearchProvider* TestChromeBrowserProvider::GetVoiceSearchProvider() const { |
| 68 return @[ en ]; | 71 return voice_search_provider_.get(); |
| 69 } | 72 } |
| 70 | 73 |
| 71 } // namespace ios | 74 } // namespace ios |
| OLD | NEW |