| 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_article_i
tem.h" | |
| 6 | |
| 7 #include "testing/gtest/include/gtest/gtest.h" | |
| 8 #import "third_party/ocmock/OCMock/OCMock.h" | |
| 9 #import "third_party/ocmock/gtest_support.h" | |
| 10 #include "url/gurl.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 // Tests that configureCell: set all the fields of the cell except the image and | |
| 19 // fetches the image through the delegate. | |
| 20 TEST(ContentSuggestionsArticleItemTest, CellIsConfiguredWithoutImage) { | |
| 21 // Setup. | |
| 22 NSString* title = @"testTitle"; | |
| 23 NSString* subtitle = @"testSubtitle"; | |
| 24 GURL url = GURL("http://chromium.org"); | |
| 25 id delegateMock = | |
| 26 OCMProtocolMock(@protocol(ContentSuggestionsArticleItemDelegate)); | |
| 27 ContentSuggestionsArticleItem* item = | |
| 28 [[ContentSuggestionsArticleItem alloc] initWithType:0 | |
| 29 title:title | |
| 30 subtitle:subtitle | |
| 31 delegate:delegateMock | |
| 32 url:url]; | |
| 33 OCMExpect([delegateMock loadImageForArticleItem:item]); | |
| 34 ContentSuggestionsArticleCell* cell = [[[item cellClass] alloc] init]; | |
| 35 ASSERT_EQ([ContentSuggestionsArticleCell class], [cell class]); | |
| 36 ASSERT_EQ(url, item.articleURL); | |
| 37 ASSERT_NE(nil, item.image); | |
| 38 | |
| 39 // Action. | |
| 40 [item configureCell:cell]; | |
| 41 | |
| 42 // Tests. | |
| 43 EXPECT_EQ(item.image, cell.imageView.image); | |
| 44 EXPECT_EQ(title, cell.titleLabel.text); | |
| 45 EXPECT_EQ(subtitle, cell.subtitleLabel.text); | |
| 46 EXPECT_OCMOCK_VERIFY(delegateMock); | |
| 47 } | |
| 48 | |
| 49 // Tests that configureCell: does not call the delegate if it fetched the image | |
| 50 // once. | |
| 51 TEST(ContentSuggestionsArticleItemTest, DontFetchImageIsImageIsBeingFetched) { | |
| 52 // Setup. | |
| 53 NSString* title = @"testTitle"; | |
| 54 NSString* subtitle = @"testSubtitle"; | |
| 55 GURL url = GURL("http://chromium.org"); | |
| 56 id niceDelegateMock = | |
| 57 OCMProtocolMock(@protocol(ContentSuggestionsArticleItemDelegate)); | |
| 58 ContentSuggestionsArticleItem* item = | |
| 59 [[ContentSuggestionsArticleItem alloc] initWithType:0 | |
| 60 title:title | |
| 61 subtitle:subtitle | |
| 62 delegate:niceDelegateMock | |
| 63 url:url]; | |
| 64 | |
| 65 OCMExpect([niceDelegateMock loadImageForArticleItem:item]); | |
| 66 ContentSuggestionsArticleCell* cell = [[[item cellClass] alloc] init]; | |
| 67 ASSERT_NE(nil, item.image); | |
| 68 [item configureCell:cell]; | |
| 69 ASSERT_OCMOCK_VERIFY(niceDelegateMock); | |
| 70 | |
| 71 id strictDelegateMock = | |
| 72 OCMStrictProtocolMock(@protocol(ContentSuggestionsArticleItemDelegate)); | |
| 73 item.delegate = strictDelegateMock; | |
| 74 | |
| 75 // Action. | |
| 76 [item configureCell:cell]; | |
| 77 | |
| 78 // Tests. | |
| 79 EXPECT_EQ(item.image, cell.imageView.image); | |
| 80 EXPECT_EQ(title, cell.titleLabel.text); | |
| 81 EXPECT_EQ(subtitle, cell.subtitleLabel.text); | |
| 82 } | |
| 83 | |
| 84 } // namespace | |
| OLD | NEW |