Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(153)

Side by Side Diff: ios/chrome/browser/ui/settings/settings_navigation_controller_unittest.mm

Issue 2622913002: Simplify registration of a test ChromeBrowserStateManager. (Closed)
Patch Set: Fix typo in naming variable. Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ios/chrome/browser/signin/authentication_service_unittest.mm ('k') | ios/chrome/test/BUILD.gn » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #import "ios/chrome/browser/ui/settings/settings_navigation_controller.h" 5 #import "ios/chrome/browser/ui/settings/settings_navigation_controller.h"
6 6
7 #import <Foundation/Foundation.h> 7 #import <Foundation/Foundation.h>
8 8
9 #include <memory> 9 #include <memory>
10 10
11 #include "base/mac/scoped_nsautorelease_pool.h" 11 #include "base/mac/scoped_nsautorelease_pool.h"
12 #import "base/mac/scoped_nsobject.h" 12 #import "base/mac/scoped_nsobject.h"
13 #include "base/memory/ptr_util.h" 13 #include "base/memory/ptr_util.h"
14 #include "components/search_engines/template_url_service.h" 14 #include "components/search_engines/template_url_service.h"
15 #include "ios/chrome/browser/browser_state/test_chrome_browser_state.h" 15 #include "ios/chrome/browser/browser_state/test_chrome_browser_state.h"
16 #include "ios/chrome/browser/browser_state/test_chrome_browser_state_manager.h" 16 #include "ios/chrome/browser/browser_state/test_chrome_browser_state_manager.h"
17 #include "ios/chrome/browser/search_engines/template_url_service_factory.h" 17 #include "ios/chrome/browser/search_engines/template_url_service_factory.h"
18 #import "ios/chrome/browser/signin/authentication_service.h" 18 #import "ios/chrome/browser/signin/authentication_service.h"
19 #include "ios/chrome/browser/signin/authentication_service_factory.h" 19 #include "ios/chrome/browser/signin/authentication_service_factory.h"
20 #import "ios/chrome/browser/signin/authentication_service_fake.h" 20 #import "ios/chrome/browser/signin/authentication_service_fake.h"
21 #include "ios/chrome/browser/sync/sync_setup_service.h" 21 #include "ios/chrome/browser/sync/sync_setup_service.h"
22 #include "ios/chrome/browser/sync/sync_setup_service_factory.h" 22 #include "ios/chrome/browser/sync/sync_setup_service_factory.h"
23 #include "ios/chrome/test/testing_application_context.h" 23 #include "ios/chrome/test/ios_chrome_scoped_testing_chrome_browser_state_manager .h"
24 #include "ios/web/public/test/test_web_thread_bundle.h" 24 #include "ios/web/public/test/test_web_thread_bundle.h"
25 #include "testing/gmock/include/gmock/gmock.h" 25 #include "testing/gmock/include/gmock/gmock.h"
26 #include "testing/gtest/include/gtest/gtest.h" 26 #include "testing/gtest/include/gtest/gtest.h"
27 #import "testing/gtest_mac.h" 27 #import "testing/gtest_mac.h"
28 #include "testing/platform_test.h" 28 #include "testing/platform_test.h"
29 #import "third_party/ocmock/OCMock/OCMock.h" 29 #import "third_party/ocmock/OCMock/OCMock.h"
30 #include "third_party/ocmock/gtest_support.h" 30 #include "third_party/ocmock/gtest_support.h"
31 31
32 namespace { 32 namespace {
33 33
34 NSString* const kSpdyProxyEnabled = @"SpdyProxyEnabled"; 34 NSString* const kSpdyProxyEnabled = @"SpdyProxyEnabled";
35 35
36 using testing::ReturnRef; 36 using testing::ReturnRef;
37 37
38 class SettingsNavigationControllerTest : public PlatformTest { 38 class SettingsNavigationControllerTest : public PlatformTest {
39 protected: 39 protected:
40 SettingsNavigationControllerTest() 40 SettingsNavigationControllerTest()
41 : browser_state_manager_(base::FilePath()) {} 41 : scoped_browser_state_manager_(
42 42 base::MakeUnique<TestChromeBrowserStateManager>(base::FilePath())) {
43 void SetUp() override {
44 PlatformTest::SetUp();
45 TestingApplicationContext::GetGlobal()->SetChromeBrowserStateManager(
46 &browser_state_manager_);
47
48 TestChromeBrowserState::Builder test_cbs_builder; 43 TestChromeBrowserState::Builder test_cbs_builder;
49 test_cbs_builder.AddTestingFactory( 44 test_cbs_builder.AddTestingFactory(
50 AuthenticationServiceFactory::GetInstance(), 45 AuthenticationServiceFactory::GetInstance(),
51 &AuthenticationServiceFake::CreateAuthenticationService); 46 &AuthenticationServiceFake::CreateAuthenticationService);
52 test_cbs_builder.AddTestingFactory( 47 test_cbs_builder.AddTestingFactory(
53 ios::TemplateURLServiceFactory::GetInstance(), 48 ios::TemplateURLServiceFactory::GetInstance(),
54 ios::TemplateURLServiceFactory::GetDefaultFactory()); 49 ios::TemplateURLServiceFactory::GetDefaultFactory());
55 chrome_browser_state_ = test_cbs_builder.Build(); 50 chrome_browser_state_ = test_cbs_builder.Build();
56 51
57 mockDelegate_.reset([[OCMockObject 52 mockDelegate_.reset([[OCMockObject
58 niceMockForProtocol:@protocol(SettingsNavigationControllerDelegate)] 53 niceMockForProtocol:@protocol(SettingsNavigationControllerDelegate)]
59 retain]); 54 retain]);
60 55
61 TemplateURLService* template_url_service = 56 TemplateURLService* template_url_service =
62 ios::TemplateURLServiceFactory::GetForBrowserState( 57 ios::TemplateURLServiceFactory::GetForBrowserState(
63 chrome_browser_state_.get()); 58 chrome_browser_state_.get());
64 template_url_service->Load(); 59 template_url_service->Load();
65 60
66 NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults]; 61 NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
67 initialValueForSpdyProxyEnabled_.reset( 62 initialValueForSpdyProxyEnabled_.reset(
68 [[defaults stringForKey:kSpdyProxyEnabled] copy]); 63 [[defaults stringForKey:kSpdyProxyEnabled] copy]);
69 [defaults setObject:@"Disabled" forKey:kSpdyProxyEnabled]; 64 [defaults setObject:@"Disabled" forKey:kSpdyProxyEnabled];
70 }; 65 };
71 66
72 void TearDown() override { 67 ~SettingsNavigationControllerTest() override {
73 if (initialValueForSpdyProxyEnabled_) { 68 if (initialValueForSpdyProxyEnabled_) {
74 [[NSUserDefaults standardUserDefaults] 69 [[NSUserDefaults standardUserDefaults]
75 setObject:initialValueForSpdyProxyEnabled_.get() 70 setObject:initialValueForSpdyProxyEnabled_.get()
76 forKey:kSpdyProxyEnabled]; 71 forKey:kSpdyProxyEnabled];
77 } else { 72 } else {
78 [[NSUserDefaults standardUserDefaults] 73 [[NSUserDefaults standardUserDefaults]
79 removeObjectForKey:kSpdyProxyEnabled]; 74 removeObjectForKey:kSpdyProxyEnabled];
80 } 75 }
81 TestingApplicationContext::GetGlobal()->SetChromeBrowserStateManager(
82 nullptr);
83 PlatformTest::TearDown();
84 } 76 }
85 77
86 web::TestWebThreadBundle threadBundle_; 78 web::TestWebThreadBundle thread_bundle_;
87 TestChromeBrowserStateManager browser_state_manager_; 79 IOSChromeScopedTestingChromeBrowserStateManager scoped_browser_state_manager_;
88 std::unique_ptr<TestChromeBrowserState> chrome_browser_state_; 80 std::unique_ptr<TestChromeBrowserState> chrome_browser_state_;
89 base::mac::ScopedNSAutoreleasePool pool; 81 base::mac::ScopedNSAutoreleasePool pool_;
90 base::scoped_nsprotocol<id> mockDelegate_; 82 base::scoped_nsprotocol<id> mockDelegate_;
91 base::scoped_nsobject<NSString> initialValueForSpdyProxyEnabled_; 83 base::scoped_nsobject<NSString> initialValueForSpdyProxyEnabled_;
92 }; 84 };
93 85
94 // When navigation stack has more than one view controller, 86 // When navigation stack has more than one view controller,
95 // -popViewControllerAnimated: successfully removes the top view controller. 87 // -popViewControllerAnimated: successfully removes the top view controller.
96 TEST_F(SettingsNavigationControllerTest, PopController) { 88 TEST_F(SettingsNavigationControllerTest, PopController) {
97 base::scoped_nsobject<SettingsNavigationController> settingsController( 89 base::scoped_nsobject<SettingsNavigationController> settingsController(
98 [SettingsNavigationController 90 [SettingsNavigationController
99 newSettingsMainControllerWithMainBrowserState:chrome_browser_state_ 91 newSettingsMainControllerWithMainBrowserState:chrome_browser_state_
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 currentBrowserState:chrome_browser_state_ 153 currentBrowserState:chrome_browser_state_
162 .get() 154 .get()
163 delegate:mockDelegate_]); 155 delegate:mockDelegate_]);
164 EXPECT_EQ(1U, [[settingsController viewControllers] count]); 156 EXPECT_EQ(1U, [[settingsController viewControllers] count]);
165 [[mockDelegate_ expect] closeSettings]; 157 [[mockDelegate_ expect] closeSettings];
166 [settingsController popViewControllerOrCloseSettingsAnimated:NO]; 158 [settingsController popViewControllerOrCloseSettingsAnimated:NO];
167 EXPECT_OCMOCK_VERIFY(mockDelegate_); 159 EXPECT_OCMOCK_VERIFY(mockDelegate_);
168 } 160 }
169 161
170 } // namespace 162 } // namespace
OLDNEW
« no previous file with comments | « ios/chrome/browser/signin/authentication_service_unittest.mm ('k') | ios/chrome/test/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698