| Index: ios/chrome/browser/ui/open_in_toolbar_unittest.mm
|
| diff --git a/ios/chrome/browser/ui/open_in_toolbar_unittest.mm b/ios/chrome/browser/ui/open_in_toolbar_unittest.mm
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..aac8fb7b628fe865f8befbb990e2265c08265e6a
|
| --- /dev/null
|
| +++ b/ios/chrome/browser/ui/open_in_toolbar_unittest.mm
|
| @@ -0,0 +1,61 @@
|
| +// Copyright 2014 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.
|
| +
|
| +#include "base/logging.h"
|
| +#include "base/mac/scoped_nsobject.h"
|
| +#import "ios/chrome/browser/ui/open_in_toolbar.h"
|
| +#include "testing/platform_test.h"
|
| +#import "third_party/ocmock/OCMock/OCMock.h"
|
| +
|
| +// A class that counts the number of times the |dummyMethod:| method is called.
|
| +@interface DummyObserver : NSObject
|
| +
|
| +// The number of times |dummyMethod:| is invoked.
|
| +@property(nonatomic, readonly) int dummyMethodCallCount;
|
| +
|
| +// The method whose invocation increases |dummyMethodCallCount| by one.
|
| +- (void)dummyMethod:(id)parameter;
|
| +
|
| +@end
|
| +
|
| +@implementation DummyObserver
|
| +
|
| +@synthesize dummyMethodCallCount = _dummyMethodCallCount;
|
| +
|
| +- (void)dummyMethod:(id)parameter {
|
| + _dummyMethodCallCount++;
|
| +}
|
| +
|
| +@end
|
| +
|
| +namespace {
|
| +
|
| +class OpenInToolbarTest : public PlatformTest {
|
| + protected:
|
| + UIButton* GetOpenInButtonInToolBar(OpenInToolbar* toolbar) {
|
| + NSArray* subviews = [toolbar subviews];
|
| + // Assumes there is only one UIButton in the toolbar.
|
| + for (UIView* subview in subviews) {
|
| + if ([subview isKindOfClass:[UIButton class]]) {
|
| + return (UIButton*)subview;
|
| + }
|
| + }
|
| + return nil;
|
| + }
|
| +};
|
| +
|
| +TEST_F(OpenInToolbarTest, TestButtonActionAndSelector) {
|
| + base::scoped_nsobject<DummyObserver> dummyObserver(
|
| + [[DummyObserver alloc] init]);
|
| + base::scoped_nsobject<OpenInToolbar> openInToolbar([[OpenInToolbar alloc]
|
| + initWithTarget:dummyObserver
|
| + action:@selector(dummyMethod:)]);
|
| + UIButton* button = GetOpenInButtonInToolBar(openInToolbar);
|
| + ASSERT_TRUE(button);
|
| + EXPECT_EQ([dummyObserver dummyMethodCallCount], 0);
|
| + [button sendActionsForControlEvents:UIControlEventTouchUpInside];
|
| + EXPECT_EQ([dummyObserver dummyMethodCallCount], 1);
|
| +}
|
| +
|
| +} // namespace
|
|
|