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/suggestions/suggestions_favicon_item.h" | |
6 | |
7 #include "base/mac/foundation_util.h" | |
8 #import "ios/chrome/browser/ui/suggestions/suggestions_favicon_internal_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 SuggestionsFaviconInternalCell* GetInnerCell( | |
19 NSInteger cellIndex, | |
20 SuggestionsFaviconCell* outerCell) { | |
21 UICollectionViewCell* innerCell = [outerCell.collectionView.dataSource | |
22 collectionView:outerCell.collectionView | |
23 cellForItemAtIndexPath:[NSIndexPath indexPathForItem:cellIndex | |
24 inSection:0]]; | |
25 | |
26 EXPECT_EQ([SuggestionsFaviconInternalCell class], [innerCell class]); | |
27 return base::mac::ObjCCastStrict<SuggestionsFaviconInternalCell>(innerCell); | |
28 } | |
29 | |
30 #pragma mark - Tests | |
31 | |
32 // Tests that configureCell: set all the fields of the cell. | |
33 TEST(SuggestionsFaviconItemTest, CellIsConfigured) { | |
34 id delegateMock = | |
35 [OCMockObject mockForProtocol:@protocol(SuggestionsFaviconCellDelegate)]; | |
36 SuggestionsFaviconItem* item = | |
37 [[SuggestionsFaviconItem alloc] initWithType:0]; | |
38 item.delegate = delegateMock; | |
39 | |
40 SuggestionsFaviconCell* cell = [[[item cellClass] alloc] init]; | |
41 ASSERT_EQ([SuggestionsFaviconCell class], [cell class]); | |
42 | |
43 [item configureCell:cell]; | |
44 EXPECT_EQ(delegateMock, cell.delegate); | |
45 } | |
46 | |
47 // Tests that the favicon added to the item are correctly passed to the inner | |
48 // collection view. | |
49 TEST(SuggestionsFaviconItemTest, AddAFavicon) { | |
50 SuggestionsFaviconItem* item = | |
51 [[SuggestionsFaviconItem alloc] initWithType:0]; | |
52 UIImage* image1 = [[UIImage alloc] init]; | |
53 NSString* title1 = @"testTitle1"; | |
54 UIImage* image2 = [[UIImage alloc] init]; | |
55 NSString* title2 = @"testTitle2"; | |
56 [item addFavicon:image1 withTitle:title1]; | |
57 [item addFavicon:image2 withTitle:title2]; | |
58 | |
59 SuggestionsFaviconCell* cell = [[[item cellClass] alloc] init]; | |
60 | |
61 [item configureCell:cell]; | |
62 | |
63 SuggestionsFaviconInternalCell* faviconInternalCell1 = GetInnerCell(0, cell); | |
64 EXPECT_EQ(image1, faviconInternalCell1.faviconView.image); | |
65 EXPECT_TRUE([title1 isEqualToString:faviconInternalCell1.titleLabel.text]); | |
66 | |
67 SuggestionsFaviconInternalCell* faviconInternalCell2 = GetInnerCell(1, cell); | |
68 EXPECT_EQ(image2, faviconInternalCell2.faviconView.image); | |
69 EXPECT_TRUE([title2 isEqualToString:faviconInternalCell2.titleLabel.text]); | |
70 } | |
71 | |
72 } // namespace | |
OLD | NEW |