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

Side by Side Diff: ios/chrome/browser/ui/ntp/recent_tabs/recent_tabs_panel_controller_unittest.mm

Issue 2672383002: [ObjC ARC] Converts ios/chrome/browser/ui/ntp/recent_tabs:unit_tests to ARC. (Closed)
Patch Set: Created 3 years, 10 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/ui/ntp/recent_tabs/BUILD.gn ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #import "ios/chrome/browser/ui/ntp/recent_tabs/recent_tabs_panel_controller.h" 5 #import "ios/chrome/browser/ui/ntp/recent_tabs/recent_tabs_panel_controller.h"
6 6
7 #import <UIKit/UIKit.h> 7 #import <UIKit/UIKit.h>
8 8
9 #include <memory> 9 #include <memory>
10 10
11 #import "base/mac/scoped_nsautorelease_pool.h"
12 #import "base/mac/scoped_nsobject.h"
13 #include "base/memory/ptr_util.h" 11 #include "base/memory/ptr_util.h"
14 #include "components/browser_sync/profile_sync_service.h" 12 #include "components/browser_sync/profile_sync_service.h"
15 #include "components/browser_sync/profile_sync_service_mock.h" 13 #include "components/browser_sync/profile_sync_service_mock.h"
16 #include "components/signin/core/browser/signin_manager.h" 14 #include "components/signin/core/browser/signin_manager.h"
17 #include "components/sync_sessions/open_tabs_ui_delegate.h" 15 #include "components/sync_sessions/open_tabs_ui_delegate.h"
18 #include "ios/chrome/browser/browser_state/test_chrome_browser_state.h" 16 #include "ios/chrome/browser/browser_state/test_chrome_browser_state.h"
19 #include "ios/chrome/browser/signin/signin_manager_factory.h" 17 #include "ios/chrome/browser/signin/signin_manager_factory.h"
20 #include "ios/chrome/browser/sync/ios_chrome_profile_sync_service_factory.h" 18 #include "ios/chrome/browser/sync/ios_chrome_profile_sync_service_factory.h"
21 #include "ios/chrome/browser/sync/ios_chrome_profile_sync_test_util.h" 19 #include "ios/chrome/browser/sync/ios_chrome_profile_sync_test_util.h"
22 #include "ios/chrome/browser/sync/sync_setup_service.h" 20 #include "ios/chrome/browser/sync/sync_setup_service.h"
23 #include "ios/chrome/browser/sync/sync_setup_service_factory.h" 21 #include "ios/chrome/browser/sync/sync_setup_service_factory.h"
24 #include "ios/chrome/browser/sync/sync_setup_service_mock.h" 22 #include "ios/chrome/browser/sync/sync_setup_service_mock.h"
25 #import "ios/chrome/browser/ui/ntp/centering_scrollview.h" 23 #import "ios/chrome/browser/ui/ntp/centering_scrollview.h"
26 #import "ios/chrome/browser/ui/ntp/recent_tabs/recent_tabs_panel_controller.h" 24 #import "ios/chrome/browser/ui/ntp/recent_tabs/recent_tabs_panel_controller.h"
27 #import "ios/chrome/browser/ui/ntp/recent_tabs/recent_tabs_table_view_controller .h" 25 #import "ios/chrome/browser/ui/ntp/recent_tabs/recent_tabs_table_view_controller .h"
28 #include "ios/chrome/test/block_cleanup_test.h" 26 #include "ios/chrome/test/block_cleanup_test.h"
29 #include "ios/chrome/test/ios_chrome_scoped_testing_local_state.h" 27 #include "ios/chrome/test/ios_chrome_scoped_testing_local_state.h"
30 #include "ios/web/public/test/test_web_thread_bundle.h" 28 #include "ios/web/public/test/test_web_thread_bundle.h"
31 #include "testing/gtest/include/gtest/gtest.h" 29 #include "testing/gtest/include/gtest/gtest.h"
32 #import "third_party/ocmock/OCMock/OCMock.h" 30 #import "third_party/ocmock/OCMock/OCMock.h"
33 #import "third_party/ocmock/gtest_support.h" 31 #import "third_party/ocmock/gtest_support.h"
34 32
33 #if !defined(__has_feature) || !__has_feature(objc_arc)
34 #error "This file requires ARC support."
35 #endif
36
35 using testing::_; 37 using testing::_;
36 using testing::AtLeast; 38 using testing::AtLeast;
37 using testing::Return; 39 using testing::Return;
38 40
39 namespace { 41 namespace {
40 42
41 std::unique_ptr<KeyedService> CreateSyncSetupService( 43 std::unique_ptr<KeyedService> CreateSyncSetupService(
42 web::BrowserState* context) { 44 web::BrowserState* context) {
43 ios::ChromeBrowserState* chrome_browser_state = 45 ios::ChromeBrowserState* chrome_browser_state =
44 ios::ChromeBrowserState::FromBrowserState(context); 46 ios::ChromeBrowserState::FromBrowserState(context);
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 EXPECT_CALL(*sync_service, GetAuthError()) 119 EXPECT_CALL(*sync_service, GetAuthError())
118 .WillRepeatedly(::testing::ReturnRef(no_error_)); 120 .WillRepeatedly(::testing::ReturnRef(no_error_));
119 ON_CALL(*sync_service, GetRegisteredDataTypes()) 121 ON_CALL(*sync_service, GetRegisteredDataTypes())
120 .WillByDefault(Return(syncer::ModelTypeSet())); 122 .WillByDefault(Return(syncer::ModelTypeSet()));
121 sync_service->Initialize(); 123 sync_service->Initialize();
122 EXPECT_CALL(*sync_service, IsEngineInitialized()) 124 EXPECT_CALL(*sync_service, IsEngineInitialized())
123 .WillRepeatedly(Return(true)); 125 .WillRepeatedly(Return(true));
124 EXPECT_CALL(*sync_service, GetOpenTabsUIDelegate()) 126 EXPECT_CALL(*sync_service, GetOpenTabsUIDelegate())
125 .WillRepeatedly(Return(nullptr)); 127 .WillRepeatedly(Return(nullptr));
126 128
127 mock_table_view_controller_.reset([[OCMockObject 129 mock_table_view_controller_ =
128 niceMockForClass:[RecentTabsTableViewController class]] retain]); 130 [OCMockObject niceMockForClass:[RecentTabsTableViewController class]];
129 } 131 }
130 132
131 void SetupSyncState(BOOL signedIn, 133 void SetupSyncState(BOOL signedIn,
132 BOOL syncEnabled, 134 BOOL syncEnabled,
133 BOOL hasForeignSessions) { 135 BOOL hasForeignSessions) {
134 SigninManager* siginManager = ios::SigninManagerFactory::GetForBrowserState( 136 SigninManager* siginManager = ios::SigninManagerFactory::GetForBrowserState(
135 chrome_browser_state_.get()); 137 chrome_browser_state_.get());
136 if (signedIn) 138 if (signedIn)
137 siginManager->SetAuthenticatedAccountInfo("test", "test"); 139 siginManager->SetAuthenticatedAccountInfo("test", "test");
138 else if (siginManager->IsAuthenticated()) 140 else if (siginManager->IsAuthenticated())
(...skipping 26 matching lines...) Expand all
165 void CreateController() { 167 void CreateController() {
166 // Sets up the test expectations for the Sync Service Observer Bridge. 168 // Sets up the test expectations for the Sync Service Observer Bridge.
167 // RecentTabsPanelController must be added as an observer of 169 // RecentTabsPanelController must be added as an observer of
168 // ProfileSyncService changes and removed when it is destroyed. 170 // ProfileSyncService changes and removed when it is destroyed.
169 browser_sync::ProfileSyncServiceMock* sync_service = 171 browser_sync::ProfileSyncServiceMock* sync_service =
170 static_cast<browser_sync::ProfileSyncServiceMock*>( 172 static_cast<browser_sync::ProfileSyncServiceMock*>(
171 IOSChromeProfileSyncServiceFactory::GetForBrowserState( 173 IOSChromeProfileSyncServiceFactory::GetForBrowserState(
172 chrome_browser_state_.get())); 174 chrome_browser_state_.get()));
173 EXPECT_CALL(*sync_service, AddObserver(_)).Times(AtLeast(1)); 175 EXPECT_CALL(*sync_service, AddObserver(_)).Times(AtLeast(1));
174 EXPECT_CALL(*sync_service, RemoveObserver(_)).Times(AtLeast(1)); 176 EXPECT_CALL(*sync_service, RemoveObserver(_)).Times(AtLeast(1));
175 controller_.reset([[RecentTabsPanelController alloc] 177 controller_ = [[RecentTabsPanelController alloc]
176 initWithController:(RecentTabsTableViewController*) 178 initWithController:(RecentTabsTableViewController*)
177 mock_table_view_controller_.get() 179 mock_table_view_controller_
178 browserState:chrome_browser_state_.get()]); 180 browserState:chrome_browser_state_.get()];
179 } 181 }
180 182
181 protected: 183 protected:
182 web::TestWebThreadBundle thread_bundle_; 184 web::TestWebThreadBundle thread_bundle_;
183 GoogleServiceAuthError no_error_; 185 GoogleServiceAuthError no_error_;
184 IOSChromeScopedTestingLocalState local_state_; 186 IOSChromeScopedTestingLocalState local_state_;
185 187
186 std::unique_ptr<TestChromeBrowserState> chrome_browser_state_; 188 std::unique_ptr<TestChromeBrowserState> chrome_browser_state_;
187 std::unique_ptr<OpenTabsUIDelegateMock> open_tabs_ui_delegate_; 189 std::unique_ptr<OpenTabsUIDelegateMock> open_tabs_ui_delegate_;
188 190
189 // Must be declared *after* |chrome_browser_state_| so it can outlive it. 191 // Must be declared *after* |chrome_browser_state_| so it can outlive it.
190 base::scoped_nsobject<OCMockObject> mock_table_view_controller_; 192 OCMockObject* mock_table_view_controller_;
191 base::scoped_nsobject<RecentTabsPanelController> controller_; 193 RecentTabsPanelController* controller_;
192
193 // Sets up a private Autorelease Pool so objects retained by OCMockObject
stkhapugin 2017/02/06 15:52:50 Please add this to notable issues.
lody 2017/02/07 10:06:27 Done.
jif-google 2017/02/07 10:14:21 Seems like a bug in OCMock?
194 // are released as soon as possible. Otherwise, weak pointers in the
195 // objects retained by OCMockObject may surface as a BADACC when the
196 // unit test autorelease pool is released.
197 base::mac::ScopedNSAutoreleasePool pool_;
198 }; 194 };
199 195
200 TEST_F(RecentTabsPanelControllerTest, TestConstructorDestructor) { 196 TEST_F(RecentTabsPanelControllerTest, TestConstructorDestructor) {
201 CreateController(); 197 CreateController();
202 EXPECT_TRUE(controller_.get()); 198 EXPECT_TRUE(controller_);
203 } 199 }
204 200
205 TEST_F(RecentTabsPanelControllerTest, TestUserSignedOut) { 201 TEST_F(RecentTabsPanelControllerTest, TestUserSignedOut) {
206 [[mock_table_view_controller_ expect] 202 [[mock_table_view_controller_ expect]
207 refreshUserState:SessionsSyncUserState::USER_SIGNED_OUT]; 203 refreshUserState:SessionsSyncUserState::USER_SIGNED_OUT];
208 SetupSyncState(NO, NO, NO); 204 SetupSyncState(NO, NO, NO);
209 CreateController(); 205 CreateController();
210 EXPECT_OCMOCK_VERIFY(mock_table_view_controller_); 206 EXPECT_OCMOCK_VERIFY(mock_table_view_controller_);
211 } 207 }
212 208
(...skipping 16 matching lines...) Expand all
229 TEST_F(RecentTabsPanelControllerTest, TestUserSignedInSyncOnWithSessions) { 225 TEST_F(RecentTabsPanelControllerTest, TestUserSignedInSyncOnWithSessions) {
230 [[mock_table_view_controller_ expect] 226 [[mock_table_view_controller_ expect]
231 refreshUserState:SessionsSyncUserState:: 227 refreshUserState:SessionsSyncUserState::
232 USER_SIGNED_IN_SYNC_ON_WITH_SESSIONS]; 228 USER_SIGNED_IN_SYNC_ON_WITH_SESSIONS];
233 SetupSyncState(YES, YES, YES); 229 SetupSyncState(YES, YES, YES);
234 CreateController(); 230 CreateController();
235 EXPECT_OCMOCK_VERIFY(mock_table_view_controller_); 231 EXPECT_OCMOCK_VERIFY(mock_table_view_controller_);
236 } 232 }
237 233
238 } // namespace 234 } // namespace
OLDNEW
« no previous file with comments | « ios/chrome/browser/ui/ntp/recent_tabs/BUILD.gn ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698