OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/collection_view/collection_view_controller_test.h
" | 5 #import "ios/chrome/browser/ui/collection_view/collection_view_controller_test.h
" |
6 | 6 |
7 #include "base/ios/weak_nsobject.h" | |
8 #include "base/logging.h" | 7 #include "base/logging.h" |
9 #import "base/mac/foundation_util.h" | 8 #import "base/mac/foundation_util.h" |
10 #include "base/mac/scoped_nsobject.h" | |
11 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_detail_item
.h" | 9 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_detail_item
.h" |
12 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_footer_item
.h" | 10 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_footer_item
.h" |
13 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_item.h" | 11 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_item.h" |
14 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_switch_item
.h" | 12 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_switch_item
.h" |
15 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_text_item.h
" | 13 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_text_item.h
" |
16 #import "ios/chrome/browser/ui/collection_view/collection_view_controller.h" | 14 #import "ios/chrome/browser/ui/collection_view/collection_view_controller.h" |
17 #import "ios/chrome/browser/ui/collection_view/collection_view_model.h" | 15 #import "ios/chrome/browser/ui/collection_view/collection_view_model.h" |
18 | 16 |
19 #include "testing/gtest_mac.h" | 17 #include "testing/gtest_mac.h" |
20 #include "ui/base/l10n/l10n_util.h" | 18 #include "ui/base/l10n/l10n_util.h" |
21 | 19 |
| 20 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 21 #error "This file requires ARC support." |
| 22 #endif |
| 23 |
22 CollectionViewControllerTest::CollectionViewControllerTest() {} | 24 CollectionViewControllerTest::CollectionViewControllerTest() {} |
23 | 25 |
24 CollectionViewControllerTest::~CollectionViewControllerTest() {} | 26 CollectionViewControllerTest::~CollectionViewControllerTest() {} |
25 | 27 |
26 void CollectionViewControllerTest::TearDown() { | 28 void CollectionViewControllerTest::TearDown() { |
27 // Delete the controller before deleting other test variables, such as a | 29 // Delete the controller before deleting other test variables, such as a |
28 // profile, to ensure things are cleaned up in the same order as in Chrome. | 30 // profile, to ensure things are cleaned up in the same order as in Chrome. |
29 controller_.reset(); | 31 controller_.reset(); |
30 BlockCleanupTest::TearDown(); | 32 BlockCleanupTest::TearDown(); |
31 } | 33 } |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
176 EXPECT_EQ(accessory_type, | 178 EXPECT_EQ(accessory_type, |
177 (MDCCollectionViewCellAccessoryType)[text_item accessoryType]); | 179 (MDCCollectionViewCellAccessoryType)[text_item accessoryType]); |
178 } | 180 } |
179 | 181 |
180 void CollectionViewControllerTest::DeleteItem( | 182 void CollectionViewControllerTest::DeleteItem( |
181 int section, | 183 int section, |
182 int item, | 184 int item, |
183 ProceduralBlock completion_block) { | 185 ProceduralBlock completion_block) { |
184 NSIndexPath* index_path = | 186 NSIndexPath* index_path = |
185 [NSIndexPath indexPathForItem:item inSection:section]; | 187 [NSIndexPath indexPathForItem:item inSection:section]; |
186 base::WeakNSObject<CollectionViewController> weak_controller(controller_); | 188 __weak CollectionViewController* weak_controller = controller_; |
187 void (^batch_updates)() = ^{ | 189 void (^batch_updates)() = ^{ |
188 base::scoped_nsobject<CollectionViewController> strong_controller( | 190 CollectionViewController* strong_controller = weak_controller; |
189 [weak_controller retain]); | |
190 if (!strong_controller) | 191 if (!strong_controller) |
191 return; | 192 return; |
192 // Notify delegate to delete data. | 193 // Notify delegate to delete data. |
193 [strong_controller collectionView:[strong_controller collectionView] | 194 [strong_controller collectionView:[strong_controller collectionView] |
194 willDeleteItemsAtIndexPaths:@[ index_path ]]; | 195 willDeleteItemsAtIndexPaths:@[ index_path ]]; |
195 | 196 |
196 // Delete index paths. | 197 // Delete index paths. |
197 [[strong_controller collectionView] | 198 [[strong_controller collectionView] |
198 deleteItemsAtIndexPaths:@[ index_path ]]; | 199 deleteItemsAtIndexPaths:@[ index_path ]]; |
199 }; | 200 }; |
200 | 201 |
201 void (^completion)(BOOL finished) = ^(BOOL finished) { | 202 void (^completion)(BOOL finished) = ^(BOOL finished) { |
202 // Notify delegate of deletion. | 203 // Notify delegate of deletion. |
203 base::scoped_nsobject<CollectionViewController> strong_controller( | 204 CollectionViewController* strong_controller = weak_controller; |
204 [weak_controller retain]); | |
205 if (!strong_controller) | 205 if (!strong_controller) |
206 return; | 206 return; |
207 [strong_controller collectionView:[strong_controller collectionView] | 207 [strong_controller collectionView:[strong_controller collectionView] |
208 didDeleteItemsAtIndexPaths:@[ index_path ]]; | 208 didDeleteItemsAtIndexPaths:@[ index_path ]]; |
209 if (completion_block) { | 209 if (completion_block) { |
210 completion_block(); | 210 completion_block(); |
211 } | 211 } |
212 }; | 212 }; |
213 | 213 |
214 [[controller_ collectionView] performBatchUpdates:batch_updates | 214 [[controller_ collectionView] performBatchUpdates:batch_updates |
215 completion:completion]; | 215 completion:completion]; |
216 } | 216 } |
OLD | NEW |