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

Unified Diff: ios/chrome/browser/ui/collection_view/cells/MDCCollectionViewCell+Chrome_unittest.mm

Issue 2588713002: Upstream Chrome on iOS source code [4/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 side-by-side diff with in-line comments
Download patch
Index: ios/chrome/browser/ui/collection_view/cells/MDCCollectionViewCell+Chrome_unittest.mm
diff --git a/ios/chrome/browser/ui/collection_view/cells/MDCCollectionViewCell+Chrome_unittest.mm b/ios/chrome/browser/ui/collection_view/cells/MDCCollectionViewCell+Chrome_unittest.mm
new file mode 100644
index 0000000000000000000000000000000000000000..6338e7327af21b9aaa07748ab63bbd6d4b7a58f0
--- /dev/null
+++ b/ios/chrome/browser/ui/collection_view/cells/MDCCollectionViewCell+Chrome_unittest.mm
@@ -0,0 +1,58 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#import "ios/chrome/browser/ui/collection_view/cells/MDCCollectionViewCell+Chrome.h"
+
+#import "ios/chrome/browser/ui/collection_view/cells/collection_view_footer_item.h"
+#import "ios/chrome/browser/ui/collection_view/cells/collection_view_item.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+#if !defined(__has_feature) || !__has_feature(objc_arc)
+#error "This file requires ARC support."
+#endif
+
+@interface FakeCollectionViewCell : MDCCollectionViewCell
+@end
+
+@implementation FakeCollectionViewCell
+@end
+
+@interface FakeCollectionViewItem : CollectionViewItem
+@property(nonatomic, assign) NSInteger configureCount;
+@end
+@implementation FakeCollectionViewItem
+@synthesize configureCount = _configureCount;
+- (void)configureCell:(MDCCollectionViewCell*)cell {
+ [super configureCell:cell];
+ EXPECT_TRUE([cell isMemberOfClass:[FakeCollectionViewCell class]]);
+ self.configureCount++;
+}
+@end
+
+namespace {
+
+TEST(MDCCollectionViewCellChrome, PreferredHeightCallsConfigureCell) {
+ FakeCollectionViewItem* item =
+ [[FakeCollectionViewItem alloc] initWithType:0];
+ item.cellClass = [FakeCollectionViewCell class];
+ EXPECT_EQ(0, item.configureCount);
+
+ [MDCCollectionViewCell cr_preferredHeightForWidth:0 forItem:item];
+
+ EXPECT_EQ(1, item.configureCount);
+}
+
+TEST(MDCCollectionViewCellChrome, PreferredHeight) {
+ CollectionViewFooterItem* footerItem =
+ [[CollectionViewFooterItem alloc] initWithType:0];
+ footerItem.text = @"This is a pretty lengthy sentence.";
+ CGFloat (^heightForWidth)(CGFloat width) = ^(CGFloat width) {
+ return [MDCCollectionViewCell cr_preferredHeightForWidth:width
+ forItem:footerItem];
+ };
+ EXPECT_NEAR(heightForWidth(300), 50, 5);
+ EXPECT_NEAR(heightForWidth(100), 110, 5);
+}
+
+} // namespace

Powered by Google App Engine
This is Rietveld 408576698