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

Unified Diff: ios/chrome/browser/ui/settings/cells/sync_switch_item_unittest.mm

Issue 2589583003: Upstream Chrome on iOS source code [7/11]. (Closed)
Patch Set: Created 4 years 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 side-by-side diff with in-line comments
Download patch
Index: ios/chrome/browser/ui/settings/cells/sync_switch_item_unittest.mm
diff --git a/ios/chrome/browser/ui/settings/cells/sync_switch_item_unittest.mm b/ios/chrome/browser/ui/settings/cells/sync_switch_item_unittest.mm
new file mode 100644
index 0000000000000000000000000000000000000000..5ba1520133ca28728541f06dd5fc89e69c0628c7
--- /dev/null
+++ b/ios/chrome/browser/ui/settings/cells/sync_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/settings/cells/sync_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 text label and showing status are set properly after a call to
+// |configureCell:|.
+TEST(SyncSwitchItemTest, ConfigureCell) {
+ SyncSwitchItem* item = [[SyncSwitchItem alloc] initWithType:0];
+ SyncSwitchCell* cell = [[[item cellClass] alloc] init];
+ EXPECT_TRUE([cell isMemberOfClass:[SyncSwitchCell class]]);
+ EXPECT_NSEQ(nil, cell.textLabel.text);
+
+ NSString* text = @"Test Switch";
+ NSString* detailText = @"Test Switch Detail";
+
+ item.text = text;
+ item.detailText = detailText;
+ item.on = YES;
+
+ EXPECT_FALSE(cell.textLabel.text);
+ EXPECT_FALSE(cell.detailTextLabel.text);
+ EXPECT_FALSE(cell.switchView.isOn);
+
+ [item configureCell:cell];
+ EXPECT_NSEQ(text, cell.textLabel.text);
+ EXPECT_NSEQ(detailText, cell.detailTextLabel.text);
+ EXPECT_TRUE(cell.switchView.isOn);
+}
+
+} // namespace
+
+// Tests that the text color and enabled state of the switch are set correctly
+// by a call to |configureCell:|.
+TEST(SyncSwitchItemTest, EnabledAndDisabled) {
+ SyncSwitchCell* cell = [[SyncSwitchCell alloc] init];
+ SyncSwitchItem* item = [[SyncSwitchItem alloc] initWithType:0];
+ item.text = @"Test Switch";
+
+ // Text color possibilities.
+ UIColor* enabledColor =
+ [SyncSwitchCell defaultTextColorForState:UIControlStateNormal];
+ UIColor* disabledColor =
+ [SyncSwitchCell 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. Disabling shouldn't change the switch's on value.
+ item.on = YES;
+ item.enabled = NO;
+ [item configureCell:cell];
+ EXPECT_TRUE(cell.switchView.isOn);
+ EXPECT_NSEQ(disabledColor, cell.textLabel.textColor);
+}
+
+TEST(SyncSwitchItemTest, PrepareForReuseClearsActions) {
+ SyncSwitchCell* cell = [[SyncSwitchCell 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]);
+}
« no previous file with comments | « ios/chrome/browser/ui/settings/cells/sync_switch_item.mm ('k') | ios/chrome/browser/ui/settings/cells/text_and_error_item.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698