OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #import "ios/chrome/browser/ui/collection_view/cells/MDCCollectionViewCell+Chrom
e.h" |
| 6 |
| 7 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_footer_item
.h" |
| 8 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_item.h" |
| 9 #include "testing/gtest/include/gtest/gtest.h" |
| 10 |
| 11 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 12 #error "This file requires ARC support." |
| 13 #endif |
| 14 |
| 15 @interface FakeCollectionViewCell : MDCCollectionViewCell |
| 16 @end |
| 17 |
| 18 @implementation FakeCollectionViewCell |
| 19 @end |
| 20 |
| 21 @interface FakeCollectionViewItem : CollectionViewItem |
| 22 @property(nonatomic, assign) NSInteger configureCount; |
| 23 @end |
| 24 @implementation FakeCollectionViewItem |
| 25 @synthesize configureCount = _configureCount; |
| 26 - (void)configureCell:(MDCCollectionViewCell*)cell { |
| 27 [super configureCell:cell]; |
| 28 EXPECT_TRUE([cell isMemberOfClass:[FakeCollectionViewCell class]]); |
| 29 self.configureCount++; |
| 30 } |
| 31 @end |
| 32 |
| 33 namespace { |
| 34 |
| 35 TEST(MDCCollectionViewCellChrome, PreferredHeightCallsConfigureCell) { |
| 36 FakeCollectionViewItem* item = |
| 37 [[FakeCollectionViewItem alloc] initWithType:0]; |
| 38 item.cellClass = [FakeCollectionViewCell class]; |
| 39 EXPECT_EQ(0, item.configureCount); |
| 40 |
| 41 [MDCCollectionViewCell cr_preferredHeightForWidth:0 forItem:item]; |
| 42 |
| 43 EXPECT_EQ(1, item.configureCount); |
| 44 } |
| 45 |
| 46 TEST(MDCCollectionViewCellChrome, PreferredHeight) { |
| 47 CollectionViewFooterItem* footerItem = |
| 48 [[CollectionViewFooterItem alloc] initWithType:0]; |
| 49 footerItem.text = @"This is a pretty lengthy sentence."; |
| 50 CGFloat (^heightForWidth)(CGFloat width) = ^(CGFloat width) { |
| 51 return [MDCCollectionViewCell cr_preferredHeightForWidth:width |
| 52 forItem:footerItem]; |
| 53 }; |
| 54 EXPECT_NEAR(heightForWidth(300), 50, 5); |
| 55 EXPECT_NEAR(heightForWidth(100), 110, 5); |
| 56 } |
| 57 |
| 58 } // namespace |
OLD | NEW |