OLD | NEW |
(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/ui/key_commands_provider.h" |
| 6 |
| 7 #import "base/mac/scoped_nsobject.h" |
| 8 #include "testing/gtest/include/gtest/gtest.h" |
| 9 #include "testing/platform_test.h" |
| 10 #include "third_party/ocmock/OCMock/OCMock.h" |
| 11 #include "third_party/ocmock/gtest_support.h" |
| 12 #import "third_party/ocmock/ocmock_extensions.h" |
| 13 |
| 14 namespace { |
| 15 |
| 16 typedef PlatformTest KeyCommandsProviderTest; |
| 17 |
| 18 TEST(KeyCommandsProviderTest, NoTabs_EditingText_ReturnsObjects) { |
| 19 base::scoped_nsobject<KeyCommandsProvider> provider( |
| 20 [[KeyCommandsProvider alloc] init]); |
| 21 id mockConsumer = |
| 22 [OCMockObject mockForProtocol:@protocol(KeyCommandsPlumbing)]; |
| 23 [[[mockConsumer expect] andReturnUnsignedInteger:0] tabsCount]; |
| 24 |
| 25 EXPECT_NE(nil, |
| 26 [provider keyCommandsForConsumer:mockConsumer editingText:YES]); |
| 27 } |
| 28 |
| 29 TEST(KeyCommandsProviderTest, ReturnsKeyCommandsObjects) { |
| 30 base::scoped_nsobject<KeyCommandsProvider> provider( |
| 31 [[KeyCommandsProvider alloc] init]); |
| 32 id mockConsumer = |
| 33 [OCMockObject mockForProtocol:@protocol(KeyCommandsPlumbing)]; |
| 34 [[[mockConsumer expect] andReturnUnsignedInteger:0] tabsCount]; |
| 35 |
| 36 for (id element in |
| 37 [provider keyCommandsForConsumer:mockConsumer editingText:YES]) { |
| 38 EXPECT_TRUE([element isKindOfClass:[UIKeyCommand class]]); |
| 39 } |
| 40 } |
| 41 |
| 42 TEST(KeyCommandsProviderTest, MoreKeyboardCommandsWhenTabs) { |
| 43 base::scoped_nsobject<KeyCommandsProvider> provider( |
| 44 [[KeyCommandsProvider alloc] init]); |
| 45 id mockConsumer = |
| 46 [OCMockObject mockForProtocol:@protocol(KeyCommandsPlumbing)]; |
| 47 |
| 48 // No tabs. |
| 49 [[[mockConsumer expect] andReturnUnsignedInteger:0] tabsCount]; |
| 50 NSUInteger numberOfKeyCommandsWithoutTabs = |
| 51 [[provider keyCommandsForConsumer:mockConsumer editingText:NO] count]; |
| 52 |
| 53 // Tabs. |
| 54 [[[mockConsumer expect] andReturnUnsignedInteger:1] tabsCount]; |
| 55 NSUInteger numberOfKeyCommandsWithTabs = |
| 56 [[provider keyCommandsForConsumer:mockConsumer editingText:NO] count]; |
| 57 |
| 58 EXPECT_GT(numberOfKeyCommandsWithTabs, numberOfKeyCommandsWithoutTabs); |
| 59 } |
| 60 |
| 61 TEST(KeyCommandsProviderTest, LessKeyCommandsWhenTabsAndEditingText) { |
| 62 base::scoped_nsobject<KeyCommandsProvider> provider( |
| 63 [[KeyCommandsProvider alloc] init]); |
| 64 id mockConsumer = |
| 65 [OCMockObject mockForProtocol:@protocol(KeyCommandsPlumbing)]; |
| 66 |
| 67 // Not editing text. |
| 68 [[[mockConsumer expect] andReturnUnsignedInteger:1] tabsCount]; |
| 69 NSUInteger numberOfKeyCommandsWhenNotEditingText = |
| 70 [[provider keyCommandsForConsumer:mockConsumer editingText:NO] count]; |
| 71 |
| 72 // Editing text. |
| 73 [[[mockConsumer expect] andReturnUnsignedInteger:1] tabsCount]; |
| 74 NSUInteger numberOfKeyCommandsWhenEditingText = |
| 75 [[provider keyCommandsForConsumer:mockConsumer editingText:YES] count]; |
| 76 |
| 77 EXPECT_LT(numberOfKeyCommandsWhenEditingText, |
| 78 numberOfKeyCommandsWhenNotEditingText); |
| 79 } |
| 80 |
| 81 } // namespace |
OLD | NEW |