| Index: ios/chrome/browser/infobars/infobar_picker_view_controller_unittest.mm
|
| diff --git a/ios/chrome/browser/infobars/infobar_picker_view_controller_unittest.mm b/ios/chrome/browser/infobars/infobar_picker_view_controller_unittest.mm
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..cfbc6a8960674fb3ae6ccf83fb4bf5e576c61c18
|
| --- /dev/null
|
| +++ b/ios/chrome/browser/infobars/infobar_picker_view_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_view_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(InfoBarPickerViewControllerTest, Done) {
|
| + InfoBarPickerViewController* infobar_picker_controller =
|
| + [[[InfoBarPickerViewController 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(InfoBarPickerViewControllerTest, Cancel) {
|
| + InfoBarPickerViewController* infobar_picker_controller =
|
| + [[[InfoBarPickerViewController 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(InfoBarPickerViewControllerTest, Delegate) {
|
| + InfoBarPickerViewController* infobar_picker_controller =
|
| + [[[InfoBarPickerViewController alloc] initWithNibName:nil bundle:nil]
|
| + autorelease];
|
| + NSString* account1 = @"account1";
|
| + NSString* account2 = @"account2";
|
| + NSString* account3 = @"account3";
|
| +
|
| + id delegate = [OCMockObject
|
| + mockForProtocol:@protocol(InfoBarPickerViewControllerDelegate)];
|
| + [[[delegate stub] andReturn:account1]
|
| + infoBarPickerViewController:infobar_picker_controller
|
| + textForRow:0];
|
| + [[[delegate stub] andReturn:account2]
|
| + infoBarPickerViewController:infobar_picker_controller
|
| + textForRow:1];
|
| + [[[delegate stub] andReturn:account3]
|
| + infoBarPickerViewController:infobar_picker_controller
|
| + textForRow:2];
|
| + [[[delegate stub] andReturnValue:@3]
|
| + infoBarPickerViewControllerNumberOfRows:infobar_picker_controller];
|
| + [[[delegate stub] andReturnValue:@1]
|
| + infoBarPickerViewControllerInitialRow:infobar_picker_controller];
|
| + [[[delegate stub] andReturnValue:@2]
|
| + infoBarPickerViewControllerDisabledRow: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);
|
| +}
|
|
|