| OLD | NEW |
| (Empty) |
| 1 // Copyright 2017 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/content_suggestions/content_suggestions_favicon_i
tem.h" | |
| 6 | |
| 7 #include "base/mac/foundation_util.h" | |
| 8 #import "ios/chrome/browser/ui/content_suggestions/content_suggestions_favicon_i
nternal_cell.h" | |
| 9 #include "testing/gtest/include/gtest/gtest.h" | |
| 10 #import "third_party/ocmock/OCMock/OCMock.h" | |
| 11 | |
| 12 #if !defined(__has_feature) || !__has_feature(objc_arc) | |
| 13 #error "This file requires ARC support." | |
| 14 #endif | |
| 15 | |
| 16 namespace { | |
| 17 | |
| 18 ContentSuggestionsFaviconInternalCell* GetInnerCell( | |
| 19 NSInteger cellIndex, | |
| 20 ContentSuggestionsFaviconCell* outerCell) { | |
| 21 UICollectionViewCell* innerCell = [outerCell.collectionView.dataSource | |
| 22 collectionView:outerCell.collectionView | |
| 23 cellForItemAtIndexPath:[NSIndexPath indexPathForItem:cellIndex | |
| 24 inSection:0]]; | |
| 25 | |
| 26 EXPECT_EQ([ContentSuggestionsFaviconInternalCell class], [innerCell class]); | |
| 27 return base::mac::ObjCCastStrict<ContentSuggestionsFaviconInternalCell>( | |
| 28 innerCell); | |
| 29 } | |
| 30 | |
| 31 #pragma mark - Tests | |
| 32 | |
| 33 // Tests that configureCell: set all the fields of the cell. | |
| 34 TEST(ContentSuggestionsFaviconItemTest, CellIsConfigured) { | |
| 35 id delegateMock = [OCMockObject | |
| 36 mockForProtocol:@protocol(ContentSuggestionsFaviconCellDelegate)]; | |
| 37 ContentSuggestionsFaviconItem* item = | |
| 38 [[ContentSuggestionsFaviconItem alloc] initWithType:0]; | |
| 39 item.delegate = delegateMock; | |
| 40 | |
| 41 ContentSuggestionsFaviconCell* cell = [[[item cellClass] alloc] init]; | |
| 42 ASSERT_EQ([ContentSuggestionsFaviconCell class], [cell class]); | |
| 43 | |
| 44 [item configureCell:cell]; | |
| 45 EXPECT_EQ(delegateMock, cell.delegate); | |
| 46 } | |
| 47 | |
| 48 // Tests that the favicon added to the item are correctly passed to the inner | |
| 49 // collection view. | |
| 50 TEST(ContentSuggestionsFaviconItemTest, AddAFavicon) { | |
| 51 ContentSuggestionsFaviconItem* item = | |
| 52 [[ContentSuggestionsFaviconItem alloc] initWithType:0]; | |
| 53 UIImage* image1 = [[UIImage alloc] init]; | |
| 54 NSString* title1 = @"testTitle1"; | |
| 55 UIImage* image2 = [[UIImage alloc] init]; | |
| 56 NSString* title2 = @"testTitle2"; | |
| 57 [item addFavicon:image1 withTitle:title1]; | |
| 58 [item addFavicon:image2 withTitle:title2]; | |
| 59 | |
| 60 ContentSuggestionsFaviconCell* cell = [[[item cellClass] alloc] init]; | |
| 61 | |
| 62 [item configureCell:cell]; | |
| 63 | |
| 64 ContentSuggestionsFaviconInternalCell* faviconInternalCell1 = | |
| 65 GetInnerCell(0, cell); | |
| 66 EXPECT_EQ(image1, faviconInternalCell1.faviconView.image); | |
| 67 EXPECT_TRUE([title1 isEqualToString:faviconInternalCell1.titleLabel.text]); | |
| 68 | |
| 69 ContentSuggestionsFaviconInternalCell* faviconInternalCell2 = | |
| 70 GetInnerCell(1, cell); | |
| 71 EXPECT_EQ(image2, faviconInternalCell2.faviconView.image); | |
| 72 EXPECT_TRUE([title2 isEqualToString:faviconInternalCell2.titleLabel.text]); | |
| 73 } | |
| 74 | |
| 75 // Tests that adding nil favicon does nothing. | |
| 76 TEST(ContentSuggestionsFaviconItemTest, AddNilFavicon) { | |
| 77 ContentSuggestionsFaviconItem* item = | |
| 78 [[ContentSuggestionsFaviconItem alloc] initWithType:0]; | |
| 79 UIImage* image = [[UIImage alloc] init]; | |
| 80 NSString* title = @"testTitle1"; | |
| 81 UIImage* nilImage = nil; | |
| 82 NSString* nilTitle = nil; | |
| 83 [item addFavicon:nilImage withTitle:title]; | |
| 84 [item addFavicon:image withTitle:nilTitle]; | |
| 85 | |
| 86 ContentSuggestionsFaviconCell* cell = [[[item cellClass] alloc] init]; | |
| 87 | |
| 88 [item configureCell:cell]; | |
| 89 | |
| 90 EXPECT_EQ(0, | |
| 91 [cell.collectionView.dataSource collectionView:cell.collectionView | |
| 92 numberOfItemsInSection:0]); | |
| 93 } | |
| 94 | |
| 95 } // namespace | |
| OLD | NEW |