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

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

Issue 2887433002: Move the ContentSuggestions items to a new target (Closed)
Patch Set: 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
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/cells/content_suggestions_ite m.h" 5 #import "ios/chrome/browser/ui/content_suggestions/cells/content_suggestions_ite m.h"
6 6
7 #include "base/time/time.h" 7 #include "base/time/time.h"
8 #import "ios/chrome/browser/ui/content_suggestions/cells/content_suggestions_cel l.h"
8 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
9 #import "third_party/ocmock/OCMock/OCMock.h" 10 #import "third_party/ocmock/OCMock/OCMock.h"
10 #import "third_party/ocmock/gtest_support.h" 11 #import "third_party/ocmock/gtest_support.h"
11 #include "url/gurl.h" 12 #include "url/gurl.h"
12 13
13 #if !defined(__has_feature) || !__has_feature(objc_arc) 14 #if !defined(__has_feature) || !__has_feature(objc_arc)
14 #error "This file requires ARC support." 15 #error "This file requires ARC support."
15 #endif 16 #endif
16 17
17 namespace { 18 namespace {
18 19
19 // Tests that configureCell: sets all the fields of the cell except the image 20 // Tests that configureCell: sets all the fields of the cell except the image
20 // and fetches the image through the delegate. 21 // and fetches the image through the delegate.
21 TEST(ContentSuggestionsItemTest, CellIsConfiguredWithoutImage) { 22 TEST(ContentSuggestionsItemTest, CellIsConfiguredWithoutImage) {
22 // Setup. 23 // Setup.
23 NSString* title = @"testTitle"; 24 NSString* title = @"testTitle";
24 NSString* subtitle = @"testSubtitle"; 25 NSString* subtitle = @"testSubtitle";
25 GURL url = GURL("http://chromium.org"); 26 GURL url = GURL("http://chromium.org");
26 NSString* publisher = @"publisherName"; 27 NSString* publisher = @"publisherName";
27 base::Time publishTime = base::Time::Now(); 28 base::Time publishTime = base::Time::Now();
29 NSDate* date = [NSDate dateWithTimeIntervalSince1970:publishTime.ToDoubleT()];
28 id delegateMock = OCMProtocolMock(@protocol(SuggestedContentDelegate)); 30 id delegateMock = OCMProtocolMock(@protocol(SuggestedContentDelegate));
29 ContentSuggestionsItem* item = 31 ContentSuggestionsItem* item =
30 [[ContentSuggestionsItem alloc] initWithType:0 32 [[ContentSuggestionsItem alloc] initWithType:0
31 title:title 33 title:title
32 subtitle:subtitle 34 subtitle:subtitle
33 url:url]; 35 url:url];
34 item.delegate = delegateMock; 36 item.delegate = delegateMock;
35 item.hasImage = YES; 37 item.hasImage = YES;
36 item.publisher = publisher; 38 item.publisher = publisher;
37 item.publishDate = publishTime; 39 item.publishDate = publishTime;
38 item.availableOffline = YES; 40 item.availableOffline = YES;
39 OCMExpect([delegateMock loadImageForSuggestedItem:item]); 41 OCMExpect([delegateMock loadImageForSuggestedItem:item]);
40 ContentSuggestionsCell* cell = [[[item cellClass] alloc] init]; 42 ContentSuggestionsCell* cell = [[[item cellClass] alloc] init];
41 ASSERT_EQ([ContentSuggestionsCell class], [cell class]); 43 ASSERT_EQ([ContentSuggestionsCell class], [cell class]);
42 ASSERT_EQ(url, item.URL); 44 ASSERT_EQ(url, item.URL);
43 ASSERT_EQ(nil, item.image); 45 ASSERT_EQ(nil, item.image);
44 id cellMock = OCMPartialMock(cell); 46 id cellMock = OCMPartialMock(cell);
45 OCMExpect([cellMock setContentImage:item.image]); 47 OCMExpect([cellMock setContentImage:item.image]);
46 OCMExpect([cellMock setSubtitleText:subtitle]); 48 OCMExpect([cellMock setSubtitleText:subtitle]);
47 OCMExpect([cellMock setAdditionalInformationWithPublisherName:publisher 49 OCMExpect([cellMock setAdditionalInformationWithPublisherName:publisher
48 date:publishTime 50 date:date
49 offlineAvailability:YES]); 51 offlineAvailability:YES]);
50 52
51 // Action. 53 // Action.
52 [item configureCell:cell]; 54 [item configureCell:cell];
53 55
54 // Tests. 56 // Tests.
55 EXPECT_OCMOCK_VERIFY(cellMock); 57 EXPECT_OCMOCK_VERIFY(cellMock);
56 EXPECT_EQ(title, cell.titleLabel.text); 58 EXPECT_EQ(title, cell.titleLabel.text);
57 EXPECT_OCMOCK_VERIFY(delegateMock); 59 EXPECT_OCMOCK_VERIFY(delegateMock);
58 } 60 }
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 url:url]; 112 url:url];
111 item.delegate = delegateMock; 113 item.delegate = delegateMock;
112 item.hasImage = NO; 114 item.hasImage = NO;
113 ContentSuggestionsCell* cell = [[[item cellClass] alloc] init]; 115 ContentSuggestionsCell* cell = [[[item cellClass] alloc] init];
114 116
115 // Action. 117 // Action.
116 [item configureCell:cell]; 118 [item configureCell:cell];
117 } 119 }
118 120
119 } // namespace 121 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698