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

Side by Side Diff: ios/chrome/browser/infobars/infobar_picker_view_controller_unittest.mm

Issue 2107743002: Add InfoBarPickerController for displaying a picker view from an infobar (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@update_passwords_strings
Patch Set: Rename InfoBarPickerController to InfoBarPickerViewController Created 4 years, 5 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 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/infobars/infobar_picker_view_controller.h"
6
7 #include "base/mac/foundation_util.h"
8 #include "testing/gtest/include/gtest/gtest.h"
9 #import "testing/gtest_mac.h"
10 #include "third_party/ocmock/OCMock/OCMock.h"
11 #include "third_party/ocmock/gtest_support.h"
12
13 @interface TargetObject : NSObject
14 @property BOOL donePressed;
15 @property BOOL cancelPressed;
16
17 - (void)doneButtonPressed:(id)sender;
18 - (void)cancelButtonPressed:(id)sender;
19 @end
20
21 @implementation TargetObject
22 @synthesize donePressed = _donePressed;
23 @synthesize cancelPressed = _cancelPressed;
24
25 - (void)doneButtonPressed:(id)sender {
26 self.donePressed = YES;
27 }
28
29 - (void)cancelButtonPressed:(id)sender {
30 self.cancelPressed = YES;
31 }
32 @end
33
34 // Test that invoking the right bar button action invokes the assigned "Done"
35 // action.
36 TEST(InfoBarPickerViewControllerTest, Done) {
37 InfoBarPickerViewController* infobar_picker_controller =
38 [[[InfoBarPickerViewController alloc] initWithNibName:nil bundle:nil]
39 autorelease];
40 TargetObject* target = [[[TargetObject alloc] init] autorelease];
41 [infobar_picker_controller setDoneTarget:target
42 action:@selector(doneButtonPressed:)];
43 [infobar_picker_controller loadView];
44
45 UIBarButtonItem* rightButton =
46 infobar_picker_controller.navigationBar.topItem.rightBarButtonItem;
47 [rightButton.target performSelector:rightButton.action];
48 EXPECT_TRUE(target.donePressed);
49 }
50
51 // Test that invoking the left bar button action invokes the assigned "Cancel"
52 // action.
53 TEST(InfoBarPickerViewControllerTest, Cancel) {
54 InfoBarPickerViewController* infobar_picker_controller =
55 [[[InfoBarPickerViewController alloc] initWithNibName:nil bundle:nil]
56 autorelease];
57 TargetObject* target = [[[TargetObject alloc] init] autorelease];
58 [infobar_picker_controller setCancelTarget:target
59 action:@selector(cancelButtonPressed:)];
60 [infobar_picker_controller loadView];
61
62 UIBarButtonItem* leftButton =
63 infobar_picker_controller.navigationBar.topItem.leftBarButtonItem;
64 [leftButton.target performSelector:leftButton.action];
65 EXPECT_TRUE(target.cancelPressed);
66 }
67
68 // Test that the picker view is appropriately set up based on delegate provided
69 // values.
70 TEST(InfoBarPickerViewControllerTest, Delegate) {
71 InfoBarPickerViewController* infobar_picker_controller =
72 [[[InfoBarPickerViewController alloc] initWithNibName:nil bundle:nil]
73 autorelease];
74 NSString* account1 = @"account1";
75 NSString* account2 = @"account2";
76 NSString* account3 = @"account3";
77
78 id delegate = [OCMockObject
79 mockForProtocol:@protocol(InfoBarPickerViewControllerDelegate)];
80 [[[delegate stub] andReturn:account1]
81 infoBarPickerViewController:infobar_picker_controller
82 textForRow:0];
83 [[[delegate stub] andReturn:account2]
84 infoBarPickerViewController:infobar_picker_controller
85 textForRow:1];
86 [[[delegate stub] andReturn:account3]
87 infoBarPickerViewController:infobar_picker_controller
88 textForRow:2];
89 [[[delegate stub] andReturnValue:@3]
90 infoBarPickerViewControllerNumberOfRows:infobar_picker_controller];
91 [[[delegate stub] andReturnValue:@1]
92 infoBarPickerViewControllerInitialRow:infobar_picker_controller];
93 [[[delegate stub] andReturnValue:@2]
94 infoBarPickerViewControllerDisabledRow:infobar_picker_controller];
95 infobar_picker_controller.delegate = delegate;
96 [infobar_picker_controller loadView];
97
98 EXPECT_EQ(1, [infobar_picker_controller.pickerView selectedRowInComponent:0]);
99
100 UILabel* row1 = base::mac::ObjCCastStrict<UILabel>(
101 [infobar_picker_controller.pickerView viewForRow:0 forComponent:0]);
102 EXPECT_NSEQ(account1, row1.text);
103 EXPECT_TRUE(row1.enabled);
104
105 UILabel* row2 = base::mac::ObjCCastStrict<UILabel>(
106 [infobar_picker_controller.pickerView viewForRow:1 forComponent:0]);
107 EXPECT_NSEQ(account2, row2.text);
108 EXPECT_TRUE(row2.enabled);
109 EXPECT_TRUE(row2.font.fontDescriptor.symbolicTraits |
110 UIFontDescriptorTraitBold);
111
112 UILabel* row3 = base::mac::ObjCCastStrict<UILabel>(
113 [infobar_picker_controller.pickerView viewForRow:2 forComponent:0]);
114 EXPECT_NSEQ(account3, row3.text);
115 EXPECT_FALSE(row3.enabled);
116 }
OLDNEW
« no previous file with comments | « ios/chrome/browser/infobars/infobar_picker_view_controller.mm ('k') | ios/chrome/ios_chrome.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698