| 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/content_suggestions/content_suggestions_article_i
tem.h" | 5 #import "ios/chrome/browser/ui/content_suggestions/content_suggestions_article_i
tem.h" |
| 6 | 6 |
| 7 #include "testing/gtest/include/gtest/gtest.h" | 7 #include "testing/gtest/include/gtest/gtest.h" |
| 8 #import "third_party/ocmock/OCMock/OCMock.h" | 8 #import "third_party/ocmock/OCMock/OCMock.h" |
| 9 #import "third_party/ocmock/gtest_support.h" | 9 #import "third_party/ocmock/gtest_support.h" |
| 10 #include "url/gurl.h" | 10 #include "url/gurl.h" |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 ContentSuggestionsArticleItem* item = | 27 ContentSuggestionsArticleItem* item = |
| 28 [[ContentSuggestionsArticleItem alloc] initWithType:0 | 28 [[ContentSuggestionsArticleItem alloc] initWithType:0 |
| 29 title:title | 29 title:title |
| 30 subtitle:subtitle | 30 subtitle:subtitle |
| 31 delegate:delegateMock | 31 delegate:delegateMock |
| 32 url:url]; | 32 url:url]; |
| 33 OCMExpect([delegateMock loadImageForArticleItem:item]); | 33 OCMExpect([delegateMock loadImageForArticleItem:item]); |
| 34 ContentSuggestionsArticleCell* cell = [[[item cellClass] alloc] init]; | 34 ContentSuggestionsArticleCell* cell = [[[item cellClass] alloc] init]; |
| 35 ASSERT_EQ([ContentSuggestionsArticleCell class], [cell class]); | 35 ASSERT_EQ([ContentSuggestionsArticleCell class], [cell class]); |
| 36 ASSERT_EQ(url, item.articleURL); | 36 ASSERT_EQ(url, item.articleURL); |
| 37 ASSERT_EQ(nil, item.image); | 37 ASSERT_NE(nil, item.image); |
| 38 | 38 |
| 39 // Action. | 39 // Action. |
| 40 [item configureCell:cell]; | 40 [item configureCell:cell]; |
| 41 | 41 |
| 42 // Tests. | 42 // Tests. |
| 43 EXPECT_EQ(nil, cell.imageView.image); | 43 EXPECT_EQ(item.image, cell.imageView.image); |
| 44 EXPECT_EQ(title, cell.titleLabel.text); | 44 EXPECT_EQ(title, cell.titleLabel.text); |
| 45 EXPECT_EQ(subtitle, cell.subtitleLabel.text); | 45 EXPECT_EQ(subtitle, cell.subtitleLabel.text); |
| 46 EXPECT_OCMOCK_VERIFY(delegateMock); | 46 EXPECT_OCMOCK_VERIFY(delegateMock); |
| 47 } | 47 } |
| 48 | 48 |
| 49 // Tests that configureCell: set all the fields of the cell with an image and | |
| 50 // does not call the delegate. | |
| 51 TEST(ContentSuggestionsArticleItemTest, CellIsConfiguredWithImage) { | |
| 52 // Setup. | |
| 53 NSString* title = @"testTitle"; | |
| 54 NSString* subtitle = @"testSubtitle"; | |
| 55 UIImage* image = [[UIImage alloc] init]; | |
| 56 GURL url = GURL("http://chromium.org"); | |
| 57 id delegateMock = | |
| 58 OCMStrictProtocolMock(@protocol(ContentSuggestionsArticleItemDelegate)); | |
| 59 ContentSuggestionsArticleItem* item = | |
| 60 [[ContentSuggestionsArticleItem alloc] initWithType:0 | |
| 61 title:title | |
| 62 subtitle:subtitle | |
| 63 delegate:delegateMock | |
| 64 url:url]; | |
| 65 item.image = image; | |
| 66 ContentSuggestionsArticleCell* cell = [[[item cellClass] alloc] init]; | |
| 67 | |
| 68 // Action. | |
| 69 [item configureCell:cell]; | |
| 70 | |
| 71 // Tests. | |
| 72 EXPECT_EQ(image, cell.imageView.image); | |
| 73 EXPECT_EQ(title, cell.titleLabel.text); | |
| 74 EXPECT_EQ(subtitle, cell.subtitleLabel.text); | |
| 75 EXPECT_EQ(image, cell.imageView.image); | |
| 76 } | |
| 77 | |
| 78 // Tests that configureCell: does not call the delegate if it fetched the image | 49 // Tests that configureCell: does not call the delegate if it fetched the image |
| 79 // once. | 50 // once. |
| 80 TEST(ContentSuggestionsArticleItemTest, DontFetchImageIsImageIsBeingFetched) { | 51 TEST(ContentSuggestionsArticleItemTest, DontFetchImageIsImageIsBeingFetched) { |
| 81 // Setup. | 52 // Setup. |
| 82 NSString* title = @"testTitle"; | 53 NSString* title = @"testTitle"; |
| 83 NSString* subtitle = @"testSubtitle"; | 54 NSString* subtitle = @"testSubtitle"; |
| 84 GURL url = GURL("http://chromium.org"); | 55 GURL url = GURL("http://chromium.org"); |
| 85 id niceDelegateMock = | 56 id niceDelegateMock = |
| 86 OCMProtocolMock(@protocol(ContentSuggestionsArticleItemDelegate)); | 57 OCMProtocolMock(@protocol(ContentSuggestionsArticleItemDelegate)); |
| 87 ContentSuggestionsArticleItem* item = | 58 ContentSuggestionsArticleItem* item = |
| 88 [[ContentSuggestionsArticleItem alloc] initWithType:0 | 59 [[ContentSuggestionsArticleItem alloc] initWithType:0 |
| 89 title:title | 60 title:title |
| 90 subtitle:subtitle | 61 subtitle:subtitle |
| 91 delegate:niceDelegateMock | 62 delegate:niceDelegateMock |
| 92 url:url]; | 63 url:url]; |
| 93 | 64 |
| 94 OCMExpect([niceDelegateMock loadImageForArticleItem:item]); | 65 OCMExpect([niceDelegateMock loadImageForArticleItem:item]); |
| 95 ContentSuggestionsArticleCell* cell = [[[item cellClass] alloc] init]; | 66 ContentSuggestionsArticleCell* cell = [[[item cellClass] alloc] init]; |
| 96 ASSERT_EQ(nil, item.image); | 67 ASSERT_NE(nil, item.image); |
| 97 [item configureCell:cell]; | 68 [item configureCell:cell]; |
| 98 ASSERT_OCMOCK_VERIFY(niceDelegateMock); | 69 ASSERT_OCMOCK_VERIFY(niceDelegateMock); |
| 99 | 70 |
| 100 id strictDelegateMock = | 71 id strictDelegateMock = |
| 101 OCMStrictProtocolMock(@protocol(ContentSuggestionsArticleItemDelegate)); | 72 OCMStrictProtocolMock(@protocol(ContentSuggestionsArticleItemDelegate)); |
| 102 item.delegate = strictDelegateMock; | 73 item.delegate = strictDelegateMock; |
| 103 | 74 |
| 104 // Action. | 75 // Action. |
| 105 [item configureCell:cell]; | 76 [item configureCell:cell]; |
| 106 | 77 |
| 107 // Tests. | 78 // Tests. |
| 108 EXPECT_EQ(nil, cell.imageView.image); | 79 EXPECT_EQ(item.image, cell.imageView.image); |
| 109 EXPECT_EQ(title, cell.titleLabel.text); | 80 EXPECT_EQ(title, cell.titleLabel.text); |
| 110 EXPECT_EQ(subtitle, cell.subtitleLabel.text); | 81 EXPECT_EQ(subtitle, cell.subtitleLabel.text); |
| 111 } | 82 } |
| 112 | 83 |
| 113 } // namespace | 84 } // namespace |
| OLD | NEW |