| Index: ios/chrome/browser/ui/content_suggestions/content_suggestions_article_item_unittest.mm
|
| diff --git a/ios/chrome/browser/ui/content_suggestions/content_suggestions_article_item_unittest.mm b/ios/chrome/browser/ui/content_suggestions/content_suggestions_article_item_unittest.mm
|
| index 30f5fd4f98f7f19bd90e97fef4467a09b9f08da6..60eb0ea39f2ac0b91b0653ac0eaf76dc1a11d44c 100644
|
| --- a/ios/chrome/browser/ui/content_suggestions/content_suggestions_article_item_unittest.mm
|
| +++ b/ios/chrome/browser/ui/content_suggestions/content_suggestions_article_item_unittest.mm
|
| @@ -5,6 +5,8 @@
|
| #import "ios/chrome/browser/ui/content_suggestions/content_suggestions_article_item.h"
|
|
|
| #include "testing/gtest/include/gtest/gtest.h"
|
| +#import "third_party/ocmock/OCMock/OCMock.h"
|
| +#import "third_party/ocmock/gtest_support.h"
|
| #include "url/gurl.h"
|
|
|
| #if !defined(__has_feature) || !__has_feature(objc_arc)
|
| @@ -13,26 +15,93 @@
|
|
|
| namespace {
|
|
|
| -// Tests that configureCell: set all the fields of the cell.
|
| -TEST(ContentSuggestionsArticleItemTest, CellIsConfigured) {
|
| +// Tests that configureCell: set all the fields of the cell except the image and
|
| +// fetches the image through the delegate.
|
| +TEST(ContentSuggestionsArticleItemTest, CellIsConfiguredWithoutImage) {
|
| + // Setup.
|
| + NSString* title = @"testTitle";
|
| + NSString* subtitle = @"testSubtitle";
|
| + GURL url = GURL("http://chromium.org");
|
| + id delegateMock =
|
| + OCMProtocolMock(@protocol(ContentSuggestionsArticleItemDelegate));
|
| + ContentSuggestionsArticleItem* item =
|
| + [[ContentSuggestionsArticleItem alloc] initWithType:0
|
| + title:title
|
| + subtitle:subtitle
|
| + delegate:delegateMock
|
| + url:url];
|
| + OCMExpect([delegateMock loadImageForArticleItem:item]);
|
| + ContentSuggestionsArticleCell* cell = [[[item cellClass] alloc] init];
|
| + ASSERT_EQ([ContentSuggestionsArticleCell class], [cell class]);
|
| + ASSERT_EQ(url, item.articleURL);
|
| + ASSERT_EQ(nil, item.image);
|
| +
|
| + // Action.
|
| + [item configureCell:cell];
|
| +
|
| + // Tests.
|
| + EXPECT_EQ(nil, cell.imageView.image);
|
| + EXPECT_EQ(title, cell.titleLabel.text);
|
| + EXPECT_EQ(subtitle, cell.subtitleLabel.text);
|
| + EXPECT_OCMOCK_VERIFY(delegateMock);
|
| +}
|
| +
|
| +// Tests that configureCell: set all the fields of the cell with an image and
|
| +// does not call the delegate.
|
| +TEST(ContentSuggestionsArticleItemTest, CellIsConfiguredWithImage) {
|
| + // Setup.
|
| NSString* title = @"testTitle";
|
| NSString* subtitle = @"testSubtitle";
|
| UIImage* image = [[UIImage alloc] init];
|
| GURL url = GURL("http://chromium.org");
|
| + id delegateMock =
|
| + OCMStrictProtocolMock(@protocol(ContentSuggestionsArticleItemDelegate));
|
| ContentSuggestionsArticleItem* item =
|
| [[ContentSuggestionsArticleItem alloc] initWithType:0
|
| title:title
|
| subtitle:subtitle
|
| - image:image
|
| + delegate:delegateMock
|
| url:url];
|
| + item.image = image;
|
| ContentSuggestionsArticleCell* cell = [[[item cellClass] alloc] init];
|
| - EXPECT_EQ([ContentSuggestionsArticleCell class], [cell class]);
|
| - EXPECT_EQ(url, item.articleURL);
|
|
|
| + // Action.
|
| [item configureCell:cell];
|
| +
|
| + // Tests.
|
| + EXPECT_EQ(image, cell.imageView.image);
|
| EXPECT_EQ(title, cell.titleLabel.text);
|
| EXPECT_EQ(subtitle, cell.subtitleLabel.text);
|
| EXPECT_EQ(image, cell.imageView.image);
|
| }
|
|
|
| +// Tests that configureCell: does not call the delegate is |imageBeingFetched|
|
| +// is YES even if there is no image.
|
| +TEST(ContentSuggestionsArticleItemTest, DontFetchImageIsImageIsBeingFetched) {
|
| + // Setup.
|
| + NSString* title = @"testTitle";
|
| + NSString* subtitle = @"testSubtitle";
|
| + GURL url = GURL("http://chromium.org");
|
| + id delegateMock =
|
| + OCMStrictProtocolMock(@protocol(ContentSuggestionsArticleItemDelegate));
|
| + ContentSuggestionsArticleItem* item =
|
| + [[ContentSuggestionsArticleItem alloc] initWithType:0
|
| + title:title
|
| + subtitle:subtitle
|
| + delegate:delegateMock
|
| + url:url];
|
| + item.imageBeingFetched = YES;
|
| + ContentSuggestionsArticleCell* cell = [[[item cellClass] alloc] init];
|
| + ASSERT_EQ(nil, item.image);
|
| +
|
| + // Action.
|
| + [item configureCell:cell];
|
| +
|
| + // Tests.
|
| + EXPECT_EQ(nil, cell.imageView.image);
|
| + EXPECT_EQ(title, cell.titleLabel.text);
|
| + EXPECT_EQ(subtitle, cell.subtitleLabel.text);
|
| + EXPECT_OCMOCK_VERIFY(delegateMock);
|
| +}
|
| +
|
| } // namespace
|
|
|