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

Side by Side 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2016 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/settings/cells/sync_switch_item.h"
6
7 #include "testing/gtest/include/gtest/gtest.h"
8 #include "testing/gtest_mac.h"
9
10 #if !defined(__has_feature) || !__has_feature(objc_arc)
11 #error "This file requires ARC support."
12 #endif
13
14 namespace {
15
16 // Tests that the text label and showing status are set properly after a call to
17 // |configureCell:|.
18 TEST(SyncSwitchItemTest, ConfigureCell) {
19 SyncSwitchItem* item = [[SyncSwitchItem alloc] initWithType:0];
20 SyncSwitchCell* cell = [[[item cellClass] alloc] init];
21 EXPECT_TRUE([cell isMemberOfClass:[SyncSwitchCell class]]);
22 EXPECT_NSEQ(nil, cell.textLabel.text);
23
24 NSString* text = @"Test Switch";
25 NSString* detailText = @"Test Switch Detail";
26
27 item.text = text;
28 item.detailText = detailText;
29 item.on = YES;
30
31 EXPECT_FALSE(cell.textLabel.text);
32 EXPECT_FALSE(cell.detailTextLabel.text);
33 EXPECT_FALSE(cell.switchView.isOn);
34
35 [item configureCell:cell];
36 EXPECT_NSEQ(text, cell.textLabel.text);
37 EXPECT_NSEQ(detailText, cell.detailTextLabel.text);
38 EXPECT_TRUE(cell.switchView.isOn);
39 }
40
41 } // namespace
42
43 // Tests that the text color and enabled state of the switch are set correctly
44 // by a call to |configureCell:|.
45 TEST(SyncSwitchItemTest, EnabledAndDisabled) {
46 SyncSwitchCell* cell = [[SyncSwitchCell alloc] init];
47 SyncSwitchItem* item = [[SyncSwitchItem alloc] initWithType:0];
48 item.text = @"Test Switch";
49
50 // Text color possibilities.
51 UIColor* enabledColor =
52 [SyncSwitchCell defaultTextColorForState:UIControlStateNormal];
53 UIColor* disabledColor =
54 [SyncSwitchCell defaultTextColorForState:UIControlStateDisabled];
55
56 // Enabled and off.
57 item.on = NO;
58 item.enabled = YES;
59 [item configureCell:cell];
60 EXPECT_FALSE(cell.switchView.isOn);
61 EXPECT_NSEQ(enabledColor, cell.textLabel.textColor);
62
63 // Enabled and on.
64 item.on = YES;
65 item.enabled = YES;
66 [item configureCell:cell];
67 EXPECT_TRUE(cell.switchView.isOn);
68 EXPECT_NSEQ(enabledColor, cell.textLabel.textColor);
69
70 // Disabled and off.
71 item.on = NO;
72 item.enabled = NO;
73 [item configureCell:cell];
74 EXPECT_FALSE(cell.switchView.isOn);
75 EXPECT_NSEQ(disabledColor, cell.textLabel.textColor);
76
77 // Disabled and on. Disabling shouldn't change the switch's on value.
78 item.on = YES;
79 item.enabled = NO;
80 [item configureCell:cell];
81 EXPECT_TRUE(cell.switchView.isOn);
82 EXPECT_NSEQ(disabledColor, cell.textLabel.textColor);
83 }
84
85 TEST(SyncSwitchItemTest, PrepareForReuseClearsActions) {
86 SyncSwitchCell* cell = [[SyncSwitchCell alloc] init];
87 UISwitch* switchView = cell.switchView;
88 NSArray* target = [NSArray array];
89
90 EXPECT_EQ(0U, [[switchView allTargets] count]);
91 [switchView addTarget:target
92 action:@selector(count)
93 forControlEvents:UIControlEventValueChanged];
94 EXPECT_EQ(1U, [[switchView allTargets] count]);
95
96 [cell prepareForReuse];
97 EXPECT_EQ(0U, [[switchView allTargets] count]);
98 }
OLDNEW
« 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