Chromium Code Reviews| Index: ios/chrome/browser/ui/content_suggestions/content_suggestions_footer_item_unittest.mm |
| diff --git a/ios/chrome/browser/ui/content_suggestions/content_suggestions_footer_item_unittest.mm b/ios/chrome/browser/ui/content_suggestions/content_suggestions_footer_item_unittest.mm |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..2d7e19f63da5a6d57664a0eacac5f211a469d5ff |
| --- /dev/null |
| +++ b/ios/chrome/browser/ui/content_suggestions/content_suggestions_footer_item_unittest.mm |
| @@ -0,0 +1,64 @@ |
| +// Copyright 2017 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#import "ios/chrome/browser/ui/content_suggestions/content_suggestions_footer_item.h" |
| + |
| +#include "testing/gtest/include/gtest/gtest.h" |
| +#import "third_party/ocmock/OCMock/OCMock.h" |
| +#import "third_party/ocmock/gtest_support.h" |
| + |
| +#if !defined(__has_feature) || !__has_feature(objc_arc) |
| +#error "This file requires ARC support." |
| +#endif |
| + |
| +namespace { |
| + |
| +// Tests that configureCell: sets the title of the button and the action. |
|
lpromero
2017/03/14 10:16:19
block
gambard
2017/03/14 11:02:24
Done.
|
| +TEST(ContentSuggestionsFooterItemTest, CellIsConfigured) { |
| + // Setup. |
| + NSString* title = @"testTitle"; |
| + __block BOOL hasBeenCalled = NO; |
| + void (^action)() = ^void() { |
|
lpromero
2017/03/14 10:16:19
block
gambard
2017/03/14 11:02:24
Done.
|
| + hasBeenCalled = YES; |
| + }; |
| + ContentSuggestionsFooterItem* item = |
| + [[ContentSuggestionsFooterItem alloc] initWithType:0 |
| + title:title |
| + action:action]; |
| + ContentSuggestionsFooterCell* cell = [[[item cellClass] alloc] init]; |
| + ASSERT_EQ([ContentSuggestionsFooterCell class], [cell class]); |
| + ASSERT_EQ(nil, [cell.actionButton titleForState:UIControlStateNormal]); |
| + |
| + // Action. |
| + [item configureCell:cell]; |
| + |
| + // Tests. |
| + ASSERT_EQ(title, [cell.actionButton titleForState:UIControlStateNormal]); |
| + ASSERT_FALSE(hasBeenCalled); |
| + [cell.actionButton sendActionsForControlEvents:UIControlEventTouchUpInside]; |
| + ASSERT_TRUE(hasBeenCalled); |
| +} |
| + |
| +// Tests that when the cell is reused the button action is removed. |
|
lpromero
2017/03/14 10:16:19
button's block or button's action.
gambard
2017/03/14 11:02:24
Done.
|
| +TEST(ContentSuggestionsFooterItemTest, ReuseCell) { |
| + __block BOOL hasBeenCalled = NO; |
| + void (^action)() = ^void() { |
|
lpromero
2017/03/14 10:16:19
block
gambard
2017/03/14 11:02:24
Done.
|
| + hasBeenCalled = YES; |
| + }; |
| + ContentSuggestionsFooterItem* item = |
| + [[ContentSuggestionsFooterItem alloc] initWithType:0 |
| + title:@"" |
| + action:action]; |
| + ContentSuggestionsFooterCell* cell = [[[item cellClass] alloc] init]; |
| + [item configureCell:cell]; |
| + |
| + // Action. |
| + [cell prepareForReuse]; |
| + |
| + // Test. |
| + ASSERT_FALSE(hasBeenCalled); |
| + [cell.actionButton sendActionsForControlEvents:UIControlEventTouchUpInside]; |
| + ASSERT_FALSE(hasBeenCalled); |
| +} |
| +} |