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