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

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

Issue 2865183003: Use the same design for all suggestions (Closed)
Patch Set: Address comments Created 3 years, 7 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
(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/cells/content_suggestions_ite m.h"
6
7 #include "base/time/time.h"
8 #include "testing/gtest/include/gtest/gtest.h"
9 #import "third_party/ocmock/OCMock/OCMock.h"
10 #import "third_party/ocmock/gtest_support.h"
11 #include "url/gurl.h"
12
13 #if !defined(__has_feature) || !__has_feature(objc_arc)
14 #error "This file requires ARC support."
15 #endif
16
17 namespace {
18
19 // Tests that configureCell: sets all the fields of the cell except the image
20 // and fetches the image through the delegate.
21 TEST(ContentSuggestionsItemTest, CellIsConfiguredWithoutImage) {
22 // Setup.
23 NSString* title = @"testTitle";
24 NSString* subtitle = @"testSubtitle";
25 GURL url = GURL("http://chromium.org");
26 NSString* publisher = @"publisherName";
27 base::Time publishTime = base::Time::Now();
28 id delegateMock = OCMProtocolMock(@protocol(ContentSuggestionsItemDelegate));
29 ContentSuggestionsItem* item =
30 [[ContentSuggestionsItem alloc] initWithType:0
31 title:title
32 subtitle:subtitle
33 delegate:delegateMock
34 url:url];
35 item.hasImage = YES;
36 item.publisher = publisher;
37 item.publishDate = publishTime;
38 item.availableOffline = YES;
39 OCMExpect([delegateMock loadImageForSuggestionItem:item]);
40 ContentSuggestionsCell* cell = [[[item cellClass] alloc] init];
41 ASSERT_EQ([ContentSuggestionsCell class], [cell class]);
42 ASSERT_EQ(url, item.URL);
43 ASSERT_EQ(nil, item.image);
44 id cellMock = OCMPartialMock(cell);
45 OCMExpect([cellMock setContentImage:item.image]);
46 OCMExpect([cellMock setSubtitleText:subtitle]);
47 OCMExpect([cellMock setAdditionalInformationWithPublisherName:publisher
48 date:publishTime
49 offlineAvailability:YES]);
50
51 // Action.
52 [item configureCell:cell];
53
54 // Tests.
55 EXPECT_OCMOCK_VERIFY(cellMock);
56 EXPECT_EQ(title, cell.titleLabel.text);
57 EXPECT_OCMOCK_VERIFY(delegateMock);
58 }
59
60 // Tests that configureCell: does not call the delegate if it fetched the image
61 // once.
62 TEST(ContentSuggestionsItemTest, DontFetchImageIsImageIsBeingFetched) {
63 // Setup.
64 NSString* title = @"testTitle";
65 NSString* subtitle = @"testSubtitle";
66 GURL url = GURL("http://chromium.org");
67 id niceDelegateMock =
68 OCMProtocolMock(@protocol(ContentSuggestionsItemDelegate));
69 ContentSuggestionsItem* item =
70 [[ContentSuggestionsItem alloc] initWithType:0
71 title:title
72 subtitle:subtitle
73 delegate:niceDelegateMock
74 url:url];
75 item.hasImage = YES;
76 item.image = [[UIImage alloc] init];
77
78 OCMExpect([niceDelegateMock loadImageForSuggestionItem:item]);
79 ContentSuggestionsCell* cell = [[[item cellClass] alloc] init];
80 ASSERT_NE(nil, item.image);
81 [item configureCell:cell];
82 ASSERT_OCMOCK_VERIFY(niceDelegateMock);
83
84 id strictDelegateMock =
85 OCMStrictProtocolMock(@protocol(ContentSuggestionsItemDelegate));
86 item.delegate = strictDelegateMock;
87 id cellMock = OCMPartialMock(cell);
88 OCMExpect([cellMock setContentImage:item.image]);
89
90 // Action.
91 [item configureCell:cell];
92
93 // Tests.
94 EXPECT_OCMOCK_VERIFY(cellMock);
95 EXPECT_EQ(title, cell.titleLabel.text);
96 }
97
98 // Tests that the delegate is not called when |hasImage| is set to NO. If the
99 // delegate is called an exception is raised.
100 TEST(ContentSuggestionsItemTest, NoDelegateCallWhenHasNotImage) {
101 // Setup.
102 NSString* title = @"testTitle";
103 NSString* subtitle = @"testSubtitle";
104 GURL url = GURL("http://chromium.org");
105 // Strict mock. Raise exception if the load method is called.
106 id delegateMock =
107 OCMStrictProtocolMock(@protocol(ContentSuggestionsItemDelegate));
108 ContentSuggestionsItem* item =
109 [[ContentSuggestionsItem alloc] initWithType:0
110 title:title
111 subtitle:subtitle
112 delegate:delegateMock
113 url:url];
114 item.hasImage = NO;
115 ContentSuggestionsCell* cell = [[[item cellClass] alloc] init];
116
117 // Action.
118 [item configureCell:cell];
119 }
120
121 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698