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

Unified Diff: ios/chrome/browser/infobars/infobar_picker_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: Delegate behavior Created 4 years, 6 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 side-by-side diff with in-line comments
Download patch
Index: ios/chrome/browser/infobars/infobar_picker_controller_unittest.mm
diff --git a/ios/chrome/browser/infobars/infobar_picker_controller_unittest.mm b/ios/chrome/browser/infobars/infobar_picker_controller_unittest.mm
new file mode 100644
index 0000000000000000000000000000000000000000..09e241a40e91382e4942fef459dc6bb289a6461d
--- /dev/null
+++ b/ios/chrome/browser/infobars/infobar_picker_controller_unittest.mm
@@ -0,0 +1,116 @@
+// 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/infobars/infobar_picker_controller.h"
+
+#include "base/mac/foundation_util.h"
+#include "testing/gtest/include/gtest/gtest.h"
+#import "testing/gtest_mac.h"
+#include "third_party/ocmock/OCMock/OCMock.h"
+#include "third_party/ocmock/gtest_support.h"
+
+@interface TargetObject : NSObject
+@property BOOL donePressed;
+@property BOOL cancelPressed;
+
+- (void)doneButtonPressed:(id)sender;
+- (void)cancelButtonPressed:(id)sender;
+@end
+
+@implementation TargetObject
+@synthesize donePressed = _donePressed;
+@synthesize cancelPressed = _cancelPressed;
+
+- (void)doneButtonPressed:(id)sender {
+ self.donePressed = YES;
+}
+
+- (void)cancelButtonPressed:(id)sender {
+ self.cancelPressed = YES;
+}
+@end
+
+// Test that invoking the right bar button action invokes the assigned "Done"
+// action.
+TEST(InfoBarPickerControllerTest, Done) {
+ InfoBarPickerController* infobar_picker_controller =
+ [[[InfoBarPickerController alloc] initWithNibName:nil bundle:nil]
+ autorelease];
+ TargetObject* target = [[[TargetObject alloc] init] autorelease];
+ [infobar_picker_controller setDoneTarget:target
+ action:@selector(doneButtonPressed:)];
+ [infobar_picker_controller loadView];
+
+ UIBarButtonItem* rightButton =
+ infobar_picker_controller.navigationBar.topItem.rightBarButtonItem;
+ [rightButton.target performSelector:rightButton.action];
+ EXPECT_TRUE(target.donePressed);
+}
+
+// Test that invoking the left bar button action invokes the assigned "Cancel"
+// action.
+TEST(InfoBarPickerControllerTest, Cancel) {
+ InfoBarPickerController* infobar_picker_controller =
+ [[[InfoBarPickerController alloc] initWithNibName:nil bundle:nil]
+ autorelease];
+ TargetObject* target = [[[TargetObject alloc] init] autorelease];
+ [infobar_picker_controller setCancelTarget:target
+ action:@selector(cancelButtonPressed:)];
+ [infobar_picker_controller loadView];
+
+ UIBarButtonItem* leftButton =
+ infobar_picker_controller.navigationBar.topItem.leftBarButtonItem;
+ [leftButton.target performSelector:leftButton.action];
+ EXPECT_TRUE(target.cancelPressed);
+}
+
+// Test that the picker view is appropriately set up based on delegate provided
+// values.
+TEST(InfoBarPickerControllerTest, Delegate) {
+ InfoBarPickerController* infobar_picker_controller =
+ [[[InfoBarPickerController alloc] initWithNibName:nil bundle:nil]
+ autorelease];
+ NSString* account1 = @"account1";
+ NSString* account2 = @"account2";
+ NSString* account3 = @"account3";
+
+ id delegate =
+ [OCMockObject mockForProtocol:@protocol(InfoBarPickerControllerDelegate)];
+ [[[delegate stub] andReturn:account1]
+ infoBarPickerController:infobar_picker_controller
+ textForRow:0];
+ [[[delegate stub] andReturn:account2]
+ infoBarPickerController:infobar_picker_controller
+ textForRow:1];
+ [[[delegate stub] andReturn:account3]
+ infoBarPickerController:infobar_picker_controller
+ textForRow:2];
+ [[[delegate stub] andReturnValue:@3]
+ infoBarPickerControllerNumberOfRows:infobar_picker_controller];
+ [[[delegate stub] andReturnValue:@1]
+ infoBarPickerControllerInitialRow:infobar_picker_controller];
+ [[[delegate stub] andReturnValue:@2]
+ infoBarPickerControllerDisabledRow:infobar_picker_controller];
+ infobar_picker_controller.delegate = delegate;
+ [infobar_picker_controller loadView];
+
+ EXPECT_EQ(1, [infobar_picker_controller.pickerView selectedRowInComponent:0]);
+
+ UILabel* row1 = base::mac::ObjCCastStrict<UILabel>(
+ [infobar_picker_controller.pickerView viewForRow:0 forComponent:0]);
+ EXPECT_NSEQ(account1, row1.text);
+ EXPECT_TRUE(row1.enabled);
+
+ UILabel* row2 = base::mac::ObjCCastStrict<UILabel>(
+ [infobar_picker_controller.pickerView viewForRow:1 forComponent:0]);
+ EXPECT_NSEQ(account2, row2.text);
+ EXPECT_TRUE(row2.enabled);
+ EXPECT_TRUE(row2.font.fontDescriptor.symbolicTraits |
+ UIFontDescriptorTraitBold);
+
+ UILabel* row3 = base::mac::ObjCCastStrict<UILabel>(
+ [infobar_picker_controller.pickerView viewForRow:2 forComponent:0]);
+ EXPECT_NSEQ(account3, row3.text);
+ EXPECT_FALSE(row3.enabled);
+}

Powered by Google App Engine
This is Rietveld 408576698