OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "ios/chrome/browser/ui/settings/passphrase_collection_view_controller_t
est.h" |
| 6 |
| 7 #import <UIKit/UIKit.h> |
| 8 |
| 9 #include <memory> |
| 10 |
| 11 #include "base/memory/ptr_util.h" |
| 12 #include "base/message_loop/message_loop.h" |
| 13 #include "base/strings/sys_string_conversions.h" |
| 14 #include "components/browser_sync/profile_sync_service_mock.h" |
| 15 #include "components/pref_registry/pref_registry_syncable.h" |
| 16 #include "components/sync_preferences/pref_service_mock_factory.h" |
| 17 #include "components/sync_preferences/pref_service_syncable.h" |
| 18 #include "ios/chrome/browser/browser_state/chrome_browser_state.h" |
| 19 #include "ios/chrome/browser/browser_state/test_chrome_browser_state.h" |
| 20 #include "ios/chrome/browser/prefs/browser_prefs.h" |
| 21 #include "ios/chrome/browser/signin/authentication_service_factory.h" |
| 22 #import "ios/chrome/browser/signin/authentication_service_fake.h" |
| 23 #include "ios/chrome/browser/sync/ios_chrome_profile_sync_service_factory.h" |
| 24 #include "ios/chrome/browser/sync/ios_chrome_profile_sync_test_util.h" |
| 25 #include "ios/chrome/browser/sync/sync_setup_service.h" |
| 26 #include "ios/chrome/browser/sync/sync_setup_service_factory.h" |
| 27 #import "ios/chrome/browser/ui/settings/settings_navigation_controller.h" |
| 28 #include "ios/public/provider/chrome/browser/signin/fake_chrome_identity_service
.h" |
| 29 #include "testing/gtest_mac.h" |
| 30 #include "testing/platform_test.h" |
| 31 |
| 32 using testing::DefaultValue; |
| 33 using testing::NiceMock; |
| 34 using testing::Return; |
| 35 |
| 36 std::unique_ptr<sync_preferences::PrefServiceSyncable> CreatePrefService() { |
| 37 sync_preferences::PrefServiceMockFactory factory; |
| 38 scoped_refptr<user_prefs::PrefRegistrySyncable> registry( |
| 39 new user_prefs::PrefRegistrySyncable); |
| 40 std::unique_ptr<sync_preferences::PrefServiceSyncable> prefs = |
| 41 factory.CreateSyncable(registry.get()); |
| 42 RegisterBrowserStatePrefs(registry.get()); |
| 43 return prefs; |
| 44 } |
| 45 |
| 46 std::unique_ptr<KeyedService> |
| 47 PassphraseCollectionViewControllerTest::CreateNiceProfileSyncServiceMock( |
| 48 web::BrowserState* context) { |
| 49 browser_sync::ProfileSyncService::InitParams init_params = |
| 50 CreateProfileSyncServiceParamsForTest( |
| 51 nullptr, ios::ChromeBrowserState::FromBrowserState(context)); |
| 52 return base::MakeUnique<NiceMock<browser_sync::ProfileSyncServiceMock>>( |
| 53 &init_params); |
| 54 } |
| 55 |
| 56 PassphraseCollectionViewControllerTest::PassphraseCollectionViewControllerTest() |
| 57 : CollectionViewControllerTest(), |
| 58 fake_sync_service_(NULL), |
| 59 default_auth_error_(GoogleServiceAuthError::NONE) {} |
| 60 |
| 61 PassphraseCollectionViewControllerTest:: |
| 62 ~PassphraseCollectionViewControllerTest() {} |
| 63 |
| 64 void PassphraseCollectionViewControllerTest::SetUp() { |
| 65 CollectionViewControllerTest::SetUp(); |
| 66 |
| 67 // Set up the default return values for non-trivial return types. |
| 68 DefaultValue<const GoogleServiceAuthError&>::Set(default_auth_error_); |
| 69 DefaultValue<syncer::SyncCycleSnapshot>::Set(default_sync_cycle_snapshot_); |
| 70 |
| 71 TestChromeBrowserState::Builder test_cbs_builder; |
| 72 test_cbs_builder.AddTestingFactory( |
| 73 AuthenticationServiceFactory::GetInstance(), |
| 74 AuthenticationServiceFake::CreateAuthenticationService); |
| 75 test_cbs_builder.SetPrefService(CreatePrefService()); |
| 76 chrome_browser_state_ = test_cbs_builder.Build(); |
| 77 |
| 78 fake_sync_service_ = static_cast<browser_sync::ProfileSyncServiceMock*>( |
| 79 IOSChromeProfileSyncServiceFactory::GetInstance() |
| 80 ->SetTestingFactoryAndUse(chrome_browser_state_.get(), |
| 81 CreateNiceProfileSyncServiceMock)); |
| 82 ON_CALL(*fake_sync_service_, GetRegisteredDataTypes()) |
| 83 .WillByDefault(Return(syncer::ModelTypeSet())); |
| 84 fake_sync_service_->Initialize(); |
| 85 |
| 86 // Set up non-default return values for our sync service mock. |
| 87 ON_CALL(*fake_sync_service_, IsPassphraseRequired()) |
| 88 .WillByDefault(Return(true)); |
| 89 ON_CALL(*fake_sync_service_, IsEngineInitialized()) |
| 90 .WillByDefault(Return(true)); |
| 91 |
| 92 ios::FakeChromeIdentityService* identityService = |
| 93 ios::FakeChromeIdentityService::GetInstanceFromChromeProvider(); |
| 94 identityService->AddIdentities(@[ @"identity1" ]); |
| 95 ChromeIdentity* identity = |
| 96 [identityService->GetAllIdentitiesSortedForDisplay() objectAtIndex:0]; |
| 97 AuthenticationServiceFactory::GetForBrowserState(chrome_browser_state_.get()) |
| 98 ->SignIn(identity, ""); |
| 99 } |
| 100 |
| 101 void PassphraseCollectionViewControllerTest::SetUpNavigationController( |
| 102 UIViewController* test_controller) { |
| 103 dummy_controller_.reset([[UIViewController alloc] init]); |
| 104 nav_controller_.reset([[SettingsNavigationController alloc] |
| 105 initWithRootViewController:dummy_controller_ |
| 106 browserState:chrome_browser_state_.get() |
| 107 delegate:nil]); |
| 108 [nav_controller_ pushViewController:test_controller animated:NO]; |
| 109 } |
OLD | NEW |