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

Unified Diff: ios/chrome/browser/ui/key_commands_provider_unittest.mm

Issue 2590473002: Upstream Chrome on iOS source code [5/11]. (Closed)
Patch Set: Created 4 years 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
« no previous file with comments | « ios/chrome/browser/ui/key_commands_provider.mm ('k') | ios/chrome/browser/ui/keyboard_commands_egtest.mm » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ios/chrome/browser/ui/key_commands_provider_unittest.mm
diff --git a/ios/chrome/browser/ui/key_commands_provider_unittest.mm b/ios/chrome/browser/ui/key_commands_provider_unittest.mm
new file mode 100644
index 0000000000000000000000000000000000000000..b94d27bf44a11e87521f89e4bd53fe8dec93549c
--- /dev/null
+++ b/ios/chrome/browser/ui/key_commands_provider_unittest.mm
@@ -0,0 +1,81 @@
+// 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/ui/key_commands_provider.h"
+
+#import "base/mac/scoped_nsobject.h"
+#include "testing/gtest/include/gtest/gtest.h"
+#include "testing/platform_test.h"
+#include "third_party/ocmock/OCMock/OCMock.h"
+#include "third_party/ocmock/gtest_support.h"
+#import "third_party/ocmock/ocmock_extensions.h"
+
+namespace {
+
+typedef PlatformTest KeyCommandsProviderTest;
+
+TEST(KeyCommandsProviderTest, NoTabs_EditingText_ReturnsObjects) {
+ base::scoped_nsobject<KeyCommandsProvider> provider(
+ [[KeyCommandsProvider alloc] init]);
+ id mockConsumer =
+ [OCMockObject mockForProtocol:@protocol(KeyCommandsPlumbing)];
+ [[[mockConsumer expect] andReturnUnsignedInteger:0] tabsCount];
+
+ EXPECT_NE(nil,
+ [provider keyCommandsForConsumer:mockConsumer editingText:YES]);
+}
+
+TEST(KeyCommandsProviderTest, ReturnsKeyCommandsObjects) {
+ base::scoped_nsobject<KeyCommandsProvider> provider(
+ [[KeyCommandsProvider alloc] init]);
+ id mockConsumer =
+ [OCMockObject mockForProtocol:@protocol(KeyCommandsPlumbing)];
+ [[[mockConsumer expect] andReturnUnsignedInteger:0] tabsCount];
+
+ for (id element in
+ [provider keyCommandsForConsumer:mockConsumer editingText:YES]) {
+ EXPECT_TRUE([element isKindOfClass:[UIKeyCommand class]]);
+ }
+}
+
+TEST(KeyCommandsProviderTest, MoreKeyboardCommandsWhenTabs) {
+ base::scoped_nsobject<KeyCommandsProvider> provider(
+ [[KeyCommandsProvider alloc] init]);
+ id mockConsumer =
+ [OCMockObject mockForProtocol:@protocol(KeyCommandsPlumbing)];
+
+ // No tabs.
+ [[[mockConsumer expect] andReturnUnsignedInteger:0] tabsCount];
+ NSUInteger numberOfKeyCommandsWithoutTabs =
+ [[provider keyCommandsForConsumer:mockConsumer editingText:NO] count];
+
+ // Tabs.
+ [[[mockConsumer expect] andReturnUnsignedInteger:1] tabsCount];
+ NSUInteger numberOfKeyCommandsWithTabs =
+ [[provider keyCommandsForConsumer:mockConsumer editingText:NO] count];
+
+ EXPECT_GT(numberOfKeyCommandsWithTabs, numberOfKeyCommandsWithoutTabs);
+}
+
+TEST(KeyCommandsProviderTest, LessKeyCommandsWhenTabsAndEditingText) {
+ base::scoped_nsobject<KeyCommandsProvider> provider(
+ [[KeyCommandsProvider alloc] init]);
+ id mockConsumer =
+ [OCMockObject mockForProtocol:@protocol(KeyCommandsPlumbing)];
+
+ // Not editing text.
+ [[[mockConsumer expect] andReturnUnsignedInteger:1] tabsCount];
+ NSUInteger numberOfKeyCommandsWhenNotEditingText =
+ [[provider keyCommandsForConsumer:mockConsumer editingText:NO] count];
+
+ // Editing text.
+ [[[mockConsumer expect] andReturnUnsignedInteger:1] tabsCount];
+ NSUInteger numberOfKeyCommandsWhenEditingText =
+ [[provider keyCommandsForConsumer:mockConsumer editingText:YES] count];
+
+ EXPECT_LT(numberOfKeyCommandsWhenEditingText,
+ numberOfKeyCommandsWhenNotEditingText);
+}
+
+} // namespace
« no previous file with comments | « ios/chrome/browser/ui/key_commands_provider.mm ('k') | ios/chrome/browser/ui/keyboard_commands_egtest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698