Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(461)

Side by Side Diff: ios/chrome/browser/ui/content_suggestions/content_suggestions_article_item_unittest.mm

Issue 2720423003: Get Suggestions image only if it is not empty (Closed)
Patch Set: Fix tests Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 // Action. 68 // Action.
69 [item configureCell:cell]; 69 [item configureCell:cell];
70 70
71 // Tests. 71 // Tests.
72 EXPECT_EQ(image, cell.imageView.image); 72 EXPECT_EQ(image, cell.imageView.image);
73 EXPECT_EQ(title, cell.titleLabel.text); 73 EXPECT_EQ(title, cell.titleLabel.text);
74 EXPECT_EQ(subtitle, cell.subtitleLabel.text); 74 EXPECT_EQ(subtitle, cell.subtitleLabel.text);
75 EXPECT_EQ(image, cell.imageView.image); 75 EXPECT_EQ(image, cell.imageView.image);
76 } 76 }
77 77
78 // Tests that configureCell: does not call the delegate is |imageBeingFetched| 78 // Tests that configureCell: does not call the delegate if it fetched the image
79 // is YES even if there is no image. 79 // once.
80 TEST(ContentSuggestionsArticleItemTest, DontFetchImageIsImageIsBeingFetched) { 80 TEST(ContentSuggestionsArticleItemTest, DontFetchImageIsImageIsBeingFetched) {
81 // Setup. 81 // Setup.
82 NSString* title = @"testTitle"; 82 NSString* title = @"testTitle";
83 NSString* subtitle = @"testSubtitle"; 83 NSString* subtitle = @"testSubtitle";
84 GURL url = GURL("http://chromium.org"); 84 GURL url = GURL("http://chromium.org");
85 id delegateMock = 85 id niceDelegateMock =
86 OCMStrictProtocolMock(@protocol(ContentSuggestionsArticleItemDelegate)); 86 OCMProtocolMock(@protocol(ContentSuggestionsArticleItemDelegate));
87 ContentSuggestionsArticleItem* item = 87 ContentSuggestionsArticleItem* item =
88 [[ContentSuggestionsArticleItem alloc] initWithType:0 88 [[ContentSuggestionsArticleItem alloc] initWithType:0
89 title:title 89 title:title
90 subtitle:subtitle 90 subtitle:subtitle
91 delegate:delegateMock 91 delegate:niceDelegateMock
92 url:url]; 92 url:url];
93 item.imageBeingFetched = YES; 93
94 OCMExpect([niceDelegateMock loadImageForArticleItem:item]);
94 ContentSuggestionsArticleCell* cell = [[[item cellClass] alloc] init]; 95 ContentSuggestionsArticleCell* cell = [[[item cellClass] alloc] init];
95 ASSERT_EQ(nil, item.image); 96 ASSERT_EQ(nil, item.image);
97 [item configureCell:cell];
98 ASSERT_OCMOCK_VERIFY(niceDelegateMock);
99
100 id strictDelegateMock =
101 OCMStrictProtocolMock(@protocol(ContentSuggestionsArticleItemDelegate));
102 item.delegate = strictDelegateMock;
96 103
97 // Action. 104 // Action.
98 [item configureCell:cell]; 105 [item configureCell:cell];
99 106
100 // Tests. 107 // Tests.
101 EXPECT_EQ(nil, cell.imageView.image); 108 EXPECT_EQ(nil, cell.imageView.image);
102 EXPECT_EQ(title, cell.titleLabel.text); 109 EXPECT_EQ(title, cell.titleLabel.text);
103 EXPECT_EQ(subtitle, cell.subtitleLabel.text); 110 EXPECT_EQ(subtitle, cell.subtitleLabel.text);
104 EXPECT_OCMOCK_VERIFY(delegateMock);
105 } 111 }
106 112
107 } // namespace 113 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698