| Index: ios/chrome/browser/ui/collection_view/cells/collection_view_switch_item_unittest.mm
|
| diff --git a/ios/chrome/browser/ui/collection_view/cells/collection_view_switch_item_unittest.mm b/ios/chrome/browser/ui/collection_view/cells/collection_view_switch_item_unittest.mm
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..65bb7b4dc557ed1ce5be124887fd1dede3e9c664
|
| --- /dev/null
|
| +++ b/ios/chrome/browser/ui/collection_view/cells/collection_view_switch_item_unittest.mm
|
| @@ -0,0 +1,98 @@
|
| +// Copyright 2016 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/collection_view/cells/collection_view_switch_item.h"
|
| +
|
| +#include "testing/gtest/include/gtest/gtest.h"
|
| +#include "testing/gtest_mac.h"
|
| +
|
| +#if !defined(__has_feature) || !__has_feature(objc_arc)
|
| +#error "This file requires ARC support."
|
| +#endif
|
| +
|
| +namespace {
|
| +
|
| +// Tests that the label and switch values are set properly after a call to
|
| +// |configureCell:|.
|
| +TEST(CollectionViewSwitchItemTest, ConfigureCell) {
|
| + CollectionViewSwitchItem* item =
|
| + [[CollectionViewSwitchItem alloc] initWithType:0];
|
| + NSString* text = @"Test Switch";
|
| +
|
| + item.text = text;
|
| + item.on = YES;
|
| +
|
| + id cell = [[[item cellClass] alloc] init];
|
| + ASSERT_TRUE([cell isMemberOfClass:[CollectionViewSwitchCell class]]);
|
| +
|
| + CollectionViewSwitchCell* switchCell =
|
| + static_cast<CollectionViewSwitchCell*>(cell);
|
| + EXPECT_FALSE(switchCell.textLabel.text);
|
| + EXPECT_FALSE(switchCell.switchView.isOn);
|
| +
|
| + [item configureCell:cell];
|
| + EXPECT_NSEQ(text, switchCell.textLabel.text);
|
| + EXPECT_TRUE(switchCell.switchView.isOn);
|
| +}
|
| +
|
| +// Tests that the text color and enabled state of the switch are set correctly
|
| +// by a call to |configureCell:|.
|
| +TEST(CollectionViewSwitchItemTest, EnabledAndDisabled) {
|
| + CollectionViewSwitchCell* cell = [[CollectionViewSwitchCell alloc] init];
|
| + CollectionViewSwitchItem* item =
|
| + [[CollectionViewSwitchItem alloc] initWithType:0];
|
| + item.text = @"Test Switch";
|
| +
|
| + // Text color possibilities.
|
| + UIColor* enabledColor =
|
| + [CollectionViewSwitchCell defaultTextColorForState:UIControlStateNormal];
|
| + UIColor* disabledColor = [CollectionViewSwitchCell
|
| + defaultTextColorForState:UIControlStateDisabled];
|
| +
|
| + // Enabled and off.
|
| + item.on = NO;
|
| + item.enabled = YES;
|
| + [item configureCell:cell];
|
| + EXPECT_FALSE(cell.switchView.isOn);
|
| + EXPECT_NSEQ(enabledColor, cell.textLabel.textColor);
|
| +
|
| + // Enabled and on.
|
| + item.on = YES;
|
| + item.enabled = YES;
|
| + [item configureCell:cell];
|
| + EXPECT_TRUE(cell.switchView.isOn);
|
| + EXPECT_NSEQ(enabledColor, cell.textLabel.textColor);
|
| +
|
| + // Disabled and off.
|
| + item.on = NO;
|
| + item.enabled = NO;
|
| + [item configureCell:cell];
|
| + EXPECT_FALSE(cell.switchView.isOn);
|
| + EXPECT_NSEQ(disabledColor, cell.textLabel.textColor);
|
| +
|
| + // Disabled and on. In this case, the switch should draw in the "off" state,
|
| + // because it is disabled.
|
| + item.on = YES;
|
| + item.enabled = NO;
|
| + [item configureCell:cell];
|
| + EXPECT_FALSE(cell.switchView.isOn);
|
| + EXPECT_NSEQ(disabledColor, cell.textLabel.textColor);
|
| +}
|
| +
|
| +TEST(CollectionViewSwitchItemTest, PrepareForReuseClearsActions) {
|
| + CollectionViewSwitchCell* cell = [[CollectionViewSwitchCell alloc] init];
|
| + UISwitch* switchView = cell.switchView;
|
| + NSArray* target = [NSArray array];
|
| +
|
| + EXPECT_EQ(0U, [[switchView allTargets] count]);
|
| + [switchView addTarget:target
|
| + action:@selector(count)
|
| + forControlEvents:UIControlEventValueChanged];
|
| + EXPECT_EQ(1U, [[switchView allTargets] count]);
|
| +
|
| + [cell prepareForReuse];
|
| + EXPECT_EQ(0U, [[switchView allTargets] count]);
|
| +}
|
| +
|
| +} // namespace
|
|
|