| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #import "ios/chrome/browser/ui/key_commands_provider.h" | 5 #import "ios/chrome/browser/ui/key_commands_provider.h" |
| 6 | 6 |
| 7 #import "base/mac/scoped_nsobject.h" | |
| 8 #include "testing/gtest/include/gtest/gtest.h" | 7 #include "testing/gtest/include/gtest/gtest.h" |
| 9 #include "testing/platform_test.h" | 8 #include "testing/platform_test.h" |
| 10 #include "third_party/ocmock/OCMock/OCMock.h" | 9 #include "third_party/ocmock/OCMock/OCMock.h" |
| 11 #include "third_party/ocmock/gtest_support.h" | 10 #include "third_party/ocmock/gtest_support.h" |
| 12 #import "third_party/ocmock/ocmock_extensions.h" | 11 #import "third_party/ocmock/ocmock_extensions.h" |
| 13 | 12 |
| 13 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 14 #error "This file requires ARC support." |
| 15 #endif |
| 16 |
| 14 namespace { | 17 namespace { |
| 15 | 18 |
| 16 typedef PlatformTest KeyCommandsProviderTest; | 19 typedef PlatformTest KeyCommandsProviderTest; |
| 17 | 20 |
| 18 TEST(KeyCommandsProviderTest, NoTabs_EditingText_ReturnsObjects) { | 21 TEST(KeyCommandsProviderTest, NoTabs_EditingText_ReturnsObjects) { |
| 19 base::scoped_nsobject<KeyCommandsProvider> provider( | 22 KeyCommandsProvider* provider = [[KeyCommandsProvider alloc] init]; |
| 20 [[KeyCommandsProvider alloc] init]); | |
| 21 id mockConsumer = | 23 id mockConsumer = |
| 22 [OCMockObject mockForProtocol:@protocol(KeyCommandsPlumbing)]; | 24 [OCMockObject mockForProtocol:@protocol(KeyCommandsPlumbing)]; |
| 23 [[[mockConsumer expect] andReturnUnsignedInteger:0] tabsCount]; | 25 [[[mockConsumer expect] andReturnUnsignedInteger:0] tabsCount]; |
| 24 | 26 |
| 25 EXPECT_NE(nil, | 27 EXPECT_NE(nil, |
| 26 [provider keyCommandsForConsumer:mockConsumer editingText:YES]); | 28 [provider keyCommandsForConsumer:mockConsumer editingText:YES]); |
| 27 } | 29 } |
| 28 | 30 |
| 29 TEST(KeyCommandsProviderTest, ReturnsKeyCommandsObjects) { | 31 TEST(KeyCommandsProviderTest, ReturnsKeyCommandsObjects) { |
| 30 base::scoped_nsobject<KeyCommandsProvider> provider( | 32 KeyCommandsProvider* provider = [[KeyCommandsProvider alloc] init]; |
| 31 [[KeyCommandsProvider alloc] init]); | |
| 32 id mockConsumer = | 33 id mockConsumer = |
| 33 [OCMockObject mockForProtocol:@protocol(KeyCommandsPlumbing)]; | 34 [OCMockObject mockForProtocol:@protocol(KeyCommandsPlumbing)]; |
| 34 [[[mockConsumer expect] andReturnUnsignedInteger:0] tabsCount]; | 35 [[[mockConsumer expect] andReturnUnsignedInteger:0] tabsCount]; |
| 35 | 36 |
| 36 for (id element in | 37 for (id element in |
| 37 [provider keyCommandsForConsumer:mockConsumer editingText:YES]) { | 38 [provider keyCommandsForConsumer:mockConsumer editingText:YES]) { |
| 38 EXPECT_TRUE([element isKindOfClass:[UIKeyCommand class]]); | 39 EXPECT_TRUE([element isKindOfClass:[UIKeyCommand class]]); |
| 39 } | 40 } |
| 40 } | 41 } |
| 41 | 42 |
| 42 TEST(KeyCommandsProviderTest, MoreKeyboardCommandsWhenTabs) { | 43 TEST(KeyCommandsProviderTest, MoreKeyboardCommandsWhenTabs) { |
| 43 base::scoped_nsobject<KeyCommandsProvider> provider( | 44 KeyCommandsProvider* provider = [[KeyCommandsProvider alloc] init]; |
| 44 [[KeyCommandsProvider alloc] init]); | |
| 45 id mockConsumer = | 45 id mockConsumer = |
| 46 [OCMockObject mockForProtocol:@protocol(KeyCommandsPlumbing)]; | 46 [OCMockObject mockForProtocol:@protocol(KeyCommandsPlumbing)]; |
| 47 | 47 |
| 48 // No tabs. | 48 // No tabs. |
| 49 [[[mockConsumer expect] andReturnUnsignedInteger:0] tabsCount]; | 49 [[[mockConsumer expect] andReturnUnsignedInteger:0] tabsCount]; |
| 50 NSUInteger numberOfKeyCommandsWithoutTabs = | 50 NSUInteger numberOfKeyCommandsWithoutTabs = |
| 51 [[provider keyCommandsForConsumer:mockConsumer editingText:NO] count]; | 51 [[provider keyCommandsForConsumer:mockConsumer editingText:NO] count]; |
| 52 | 52 |
| 53 // Tabs. | 53 // Tabs. |
| 54 [[[mockConsumer expect] andReturnUnsignedInteger:1] tabsCount]; | 54 [[[mockConsumer expect] andReturnUnsignedInteger:1] tabsCount]; |
| 55 NSUInteger numberOfKeyCommandsWithTabs = | 55 NSUInteger numberOfKeyCommandsWithTabs = |
| 56 [[provider keyCommandsForConsumer:mockConsumer editingText:NO] count]; | 56 [[provider keyCommandsForConsumer:mockConsumer editingText:NO] count]; |
| 57 | 57 |
| 58 EXPECT_GT(numberOfKeyCommandsWithTabs, numberOfKeyCommandsWithoutTabs); | 58 EXPECT_GT(numberOfKeyCommandsWithTabs, numberOfKeyCommandsWithoutTabs); |
| 59 } | 59 } |
| 60 | 60 |
| 61 TEST(KeyCommandsProviderTest, LessKeyCommandsWhenTabsAndEditingText) { | 61 TEST(KeyCommandsProviderTest, LessKeyCommandsWhenTabsAndEditingText) { |
| 62 base::scoped_nsobject<KeyCommandsProvider> provider( | 62 KeyCommandsProvider* provider = [[KeyCommandsProvider alloc] init]; |
| 63 [[KeyCommandsProvider alloc] init]); | |
| 64 id mockConsumer = | 63 id mockConsumer = |
| 65 [OCMockObject mockForProtocol:@protocol(KeyCommandsPlumbing)]; | 64 [OCMockObject mockForProtocol:@protocol(KeyCommandsPlumbing)]; |
| 66 | 65 |
| 67 // Not editing text. | 66 // Not editing text. |
| 68 [[[mockConsumer expect] andReturnUnsignedInteger:1] tabsCount]; | 67 [[[mockConsumer expect] andReturnUnsignedInteger:1] tabsCount]; |
| 69 NSUInteger numberOfKeyCommandsWhenNotEditingText = | 68 NSUInteger numberOfKeyCommandsWhenNotEditingText = |
| 70 [[provider keyCommandsForConsumer:mockConsumer editingText:NO] count]; | 69 [[provider keyCommandsForConsumer:mockConsumer editingText:NO] count]; |
| 71 | 70 |
| 72 // Editing text. | 71 // Editing text. |
| 73 [[[mockConsumer expect] andReturnUnsignedInteger:1] tabsCount]; | 72 [[[mockConsumer expect] andReturnUnsignedInteger:1] tabsCount]; |
| 74 NSUInteger numberOfKeyCommandsWhenEditingText = | 73 NSUInteger numberOfKeyCommandsWhenEditingText = |
| 75 [[provider keyCommandsForConsumer:mockConsumer editingText:YES] count]; | 74 [[provider keyCommandsForConsumer:mockConsumer editingText:YES] count]; |
| 76 | 75 |
| 77 EXPECT_LT(numberOfKeyCommandsWhenEditingText, | 76 EXPECT_LT(numberOfKeyCommandsWhenEditingText, |
| 78 numberOfKeyCommandsWhenNotEditingText); | 77 numberOfKeyCommandsWhenNotEditingText); |
| 79 } | 78 } |
| 80 | 79 |
| 81 } // namespace | 80 } // namespace |
| OLD | NEW |