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

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

Issue 2587023002: Upstream Chrome on iOS source code [8/11]. (Closed)
Patch Set: Created 4 years 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
OLDNEW
(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 #import "ios/chrome/browser/ui/settings/settings_navigation_controller.h"
6
7 #import <Foundation/Foundation.h>
8
9 #include <memory>
10
11 #include "base/mac/scoped_nsautorelease_pool.h"
12 #include "base/mac/scoped_nsobject.h"
13 #include "base/memory/ptr_util.h"
14 #include "components/search_engines/template_url_service.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"
17 #include "ios/chrome/browser/search_engines/template_url_service_factory.h"
18 #include "ios/chrome/browser/signin/authentication_service.h"
19 #include "ios/chrome/browser/signin/authentication_service_factory.h"
20 #include "ios/chrome/browser/signin/authentication_service_fake.h"
21 #include "ios/chrome/browser/sync/sync_setup_service.h"
22 #include "ios/chrome/browser/sync/sync_setup_service_factory.h"
23 #include "ios/chrome/test/testing_application_context.h"
24 #include "ios/web/public/test/test_web_thread_bundle.h"
25 #include "testing/gmock/include/gmock/gmock.h"
26 #include "testing/gtest/include/gtest/gtest.h"
27 #include "testing/gtest_mac.h"
28 #include "testing/platform_test.h"
29 #import "third_party/ocmock/OCMock/OCMock.h"
30 #include "third_party/ocmock/gtest_support.h"
31
32 namespace {
33
34 NSString* const kSpdyProxyEnabled = @"SpdyProxyEnabled";
35
36 using testing::ReturnRef;
37
38 class SettingsNavigationControllerTest : public PlatformTest {
39 protected:
40 SettingsNavigationControllerTest()
41 : browser_state_manager_(base::FilePath()) {}
42
43 void SetUp() override {
44 PlatformTest::SetUp();
45 TestingApplicationContext::GetGlobal()->SetChromeBrowserStateManager(
46 &browser_state_manager_);
47
48 TestChromeBrowserState::Builder test_cbs_builder;
49 test_cbs_builder.AddTestingFactory(
50 AuthenticationServiceFactory::GetInstance(),
51 &AuthenticationServiceFake::CreateAuthenticationService);
52 test_cbs_builder.AddTestingFactory(
53 ios::TemplateURLServiceFactory::GetInstance(),
54 ios::TemplateURLServiceFactory::GetDefaultFactory());
55 chrome_browser_state_ = test_cbs_builder.Build();
56
57 mockDelegate_.reset([[OCMockObject
58 niceMockForProtocol:@protocol(SettingsNavigationControllerDelegate)]
59 retain]);
60
61 TemplateURLService* template_url_service =
62 ios::TemplateURLServiceFactory::GetForBrowserState(
63 chrome_browser_state_.get());
64 template_url_service->Load();
65
66 NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
67 initialValueForSpdyProxyEnabled_.reset(
68 [[defaults stringForKey:kSpdyProxyEnabled] copy]);
69 [defaults setObject:@"Disabled" forKey:kSpdyProxyEnabled];
70 };
71
72 void TearDown() override {
73 if (initialValueForSpdyProxyEnabled_) {
74 [[NSUserDefaults standardUserDefaults]
75 setObject:initialValueForSpdyProxyEnabled_.get()
76 forKey:kSpdyProxyEnabled];
77 } else {
78 [[NSUserDefaults standardUserDefaults]
79 removeObjectForKey:kSpdyProxyEnabled];
80 }
81 TestingApplicationContext::GetGlobal()->SetChromeBrowserStateManager(
82 nullptr);
83 PlatformTest::TearDown();
84 }
85
86 web::TestWebThreadBundle threadBundle_;
87 TestChromeBrowserStateManager browser_state_manager_;
88 std::unique_ptr<TestChromeBrowserState> chrome_browser_state_;
89 base::mac::ScopedNSAutoreleasePool pool;
90 base::scoped_nsprotocol<id> mockDelegate_;
91 base::scoped_nsobject<NSString> initialValueForSpdyProxyEnabled_;
92 };
93
94 // When navigation stack has more than one view controller,
95 // -popViewControllerAnimated: successfully removes the top view controller.
96 TEST_F(SettingsNavigationControllerTest, PopController) {
97 base::scoped_nsobject<SettingsNavigationController> settingsController(
98 [SettingsNavigationController
99 newSettingsMainControllerWithMainBrowserState:chrome_browser_state_
100 .get()
101 currentBrowserState:chrome_browser_state_
102 .get()
103 delegate:nil]);
104 base::scoped_nsobject<UIViewController> viewController(
105 [[UIViewController alloc] initWithNibName:nil bundle:nil]);
106 [settingsController pushViewController:viewController animated:NO];
107 EXPECT_EQ(2U, [[settingsController viewControllers] count]);
108
109 UIViewController* poppedViewController =
110 [settingsController popViewControllerAnimated:NO];
111 EXPECT_NSEQ(viewController, poppedViewController);
112 EXPECT_EQ(1U, [[settingsController viewControllers] count]);
113 }
114
115 // When the navigation stack has only one view controller,
116 // -popViewControllerAnimated: returns false.
117 TEST_F(SettingsNavigationControllerTest, DontPopRootController) {
118 base::scoped_nsobject<SettingsNavigationController> settingsController(
119 [SettingsNavigationController
120 newSettingsMainControllerWithMainBrowserState:chrome_browser_state_
121 .get()
122 currentBrowserState:chrome_browser_state_
123 .get()
124 delegate:nil]);
125 EXPECT_EQ(1U, [[settingsController viewControllers] count]);
126
127 EXPECT_FALSE([settingsController popViewControllerAnimated:NO]);
128 }
129
130 // When the settings navigation stack has more than one view controller, calling
131 // -popViewControllerOrCloseSettingsAnimated: pops the top view controller to
132 // reveal the view controller underneath.
133 TEST_F(SettingsNavigationControllerTest,
134 PopWhenNavigationStackSizeIsGreaterThanOne) {
135 base::scoped_nsobject<SettingsNavigationController> settingsController(
136 [SettingsNavigationController
137 newSettingsMainControllerWithMainBrowserState:chrome_browser_state_
138 .get()
139 currentBrowserState:chrome_browser_state_
140 .get()
141 delegate:mockDelegate_]);
142 base::scoped_nsobject<UIViewController> viewController(
143 [[UIViewController alloc] initWithNibName:nil bundle:nil]);
144 [settingsController pushViewController:viewController animated:NO];
145 EXPECT_EQ(2U, [[settingsController viewControllers] count]);
146 [[mockDelegate_ reject] closeSettings];
147 [settingsController popViewControllerOrCloseSettingsAnimated:NO];
148 EXPECT_EQ(1U, [[settingsController viewControllers] count]);
149 EXPECT_OCMOCK_VERIFY(mockDelegate_);
150 }
151
152 // When the settings navigation stack only has one view controller, calling
153 // -popViewControllerOrCloseSettingsAnimated: calls -closeSettings on the
154 // delegate.
155 TEST_F(SettingsNavigationControllerTest,
156 CloseSettingsWhenNavigationStackSizeIsOne) {
157 base::scoped_nsobject<SettingsNavigationController> settingsController(
158 [SettingsNavigationController
159 newSettingsMainControllerWithMainBrowserState:chrome_browser_state_
160 .get()
161 currentBrowserState:chrome_browser_state_
162 .get()
163 delegate:mockDelegate_]);
164 EXPECT_EQ(1U, [[settingsController viewControllers] count]);
165 [[mockDelegate_ expect] closeSettings];
166 [settingsController popViewControllerOrCloseSettingsAnimated:NO];
167 EXPECT_OCMOCK_VERIFY(mockDelegate_);
168 }
169
170 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698