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

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

Issue 2761753002: Cleanup ContentSuggestions cells (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
(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/content_suggestions_footer_it em.h"
6
7 #include "testing/gtest/include/gtest/gtest.h"
8 #import "third_party/ocmock/OCMock/OCMock.h"
9 #import "third_party/ocmock/gtest_support.h"
10
11 #if !defined(__has_feature) || !__has_feature(objc_arc)
12 #error "This file requires ARC support."
13 #endif
14
15 namespace {
16
17 // Tests that configureCell: sets the title of the button and the action.
18 TEST(ContentSuggestionsFooterItemTest, CellIsConfigured) {
19 // Setup.
20 NSString* title = @"testTitle";
21 __block BOOL hasBeenCalled = NO;
22 ProceduralBlock block = ^void() {
23 hasBeenCalled = YES;
24 };
25 ContentSuggestionsFooterItem* item =
26 [[ContentSuggestionsFooterItem alloc] initWithType:0
27 title:title
28 block:block];
29 ContentSuggestionsFooterCell* cell = [[[item cellClass] alloc] init];
30 ASSERT_EQ([ContentSuggestionsFooterCell class], [cell class]);
31 ASSERT_EQ(nil, [cell.button titleForState:UIControlStateNormal]);
32
33 // Action.
34 [item configureCell:cell];
35
36 // Tests.
37 ASSERT_EQ(title, [cell.button titleForState:UIControlStateNormal]);
38 ASSERT_FALSE(hasBeenCalled);
39 [cell.button sendActionsForControlEvents:UIControlEventTouchUpInside];
40 ASSERT_TRUE(hasBeenCalled);
41 }
42
43 // Tests that when the cell is reused the button's block is removed.
44 TEST(ContentSuggestionsFooterItemTest, ReuseCell) {
45 __block BOOL hasBeenCalled = NO;
46 ProceduralBlock block = ^void() {
47 hasBeenCalled = YES;
48 };
49 ContentSuggestionsFooterItem* item =
50 [[ContentSuggestionsFooterItem alloc] initWithType:0
51 title:@""
52 block:block];
53 ContentSuggestionsFooterCell* cell = [[[item cellClass] alloc] init];
54 [item configureCell:cell];
55
56 // Action.
57 [cell prepareForReuse];
58
59 // Test.
60 ASSERT_FALSE(hasBeenCalled);
61 [cell.button sendActionsForControlEvents:UIControlEventTouchUpInside];
62 ASSERT_FALSE(hasBeenCalled);
63 }
64 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698