Enforce minimum visibility only for normal and panel windows
[chromium-blink-merge.git] / remoting / ios / key_input_unittest.mm
blobb893b9f94d30794f8e5d41897f733a4552c33dee
1 // Copyright 2014 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.
5 #if !defined(__has_feature) || !__has_feature(objc_arc)
6 #error "This file requires ARC support."
7 #endif
9 #import "remoting/ios/key_input.h"
10 #import "remoting/ios/key_map_us.h"
12 #include <vector>
14 #import "base/compiler_specific.h"
15 #import "testing/gtest_mac.h"
17 @interface KeyInputDelegateTester : NSObject<KeyInputDelegate> {
18  @private
19   std::vector<uint32_t> _keyList;
22 @property(nonatomic, assign) int numKeysDown;
23 @property(nonatomic, assign) BOOL wasDismissed;
25 - (std::vector<uint32_t>&)getKeyList;
27 @end
29 @implementation KeyInputDelegateTester
31 - (std::vector<uint32_t>&)getKeyList {
32   return _keyList;
35 - (void)keyboardDismissed {
36   // This can not be tested, because we can not set |keyInput_| as
37   // FirstResponder in this test harness
38   _wasDismissed = true;
41 - (void)keyboardActionKeyCode:(uint32_t)keyPressed isKeyDown:(BOOL)keyDown {
42   if (keyDown) {
43     _keyList.push_back(keyPressed);
44     _numKeysDown++;
45   } else {
46     _numKeysDown--;
47   }
50 @end
52 namespace remoting {
54 class KeyInputTest : public ::testing::Test {
55  protected:
56   virtual void SetUp() OVERRIDE {
57     keyInput_ = [[KeyInput allocWithZone:nil] init];
58     delegateTester_ = [[KeyInputDelegateTester alloc] init];
59     keyInput_.delegate = delegateTester_;
60   }
62   KeyInput* keyInput_;
63   KeyInputDelegateTester* delegateTester_;
66 TEST_F(KeyInputTest, SendKey) {
67   // Empty
68   [keyInput_ insertText:@""];
69   ASSERT_EQ(0, delegateTester_.numKeysDown);
70   ASSERT_EQ(0, [delegateTester_ getKeyList].size());
72   // Value is out of bounds
73   [keyInput_ insertText:@"รณ"];
74   ASSERT_EQ(0, delegateTester_.numKeysDown);
75   ASSERT_EQ(0, [delegateTester_ getKeyList].size());
77   // Lower case
78   [keyInput_ insertText:@"a"];
79   ASSERT_EQ(0, delegateTester_.numKeysDown);
80   ASSERT_EQ(1, [delegateTester_ getKeyList].size());
81   ASSERT_EQ(kKeyCodeUS['a'], [delegateTester_ getKeyList][0]);
82   // Upper Case
83   [delegateTester_ getKeyList].clear();
84   [keyInput_ insertText:@"A"];
85   ASSERT_EQ(0, delegateTester_.numKeysDown);
86   ASSERT_EQ(2, [delegateTester_ getKeyList].size());
87   ASSERT_EQ(kKeyCodeUS[kShiftIndex], [delegateTester_ getKeyList][0]);
88   ASSERT_EQ(kKeyCodeUS['A'], [delegateTester_ getKeyList][1]);
90   // Multiple characters and mixed case
91   [delegateTester_ getKeyList].clear();
92   [keyInput_ insertText:@"ABCabc"];
93   ASSERT_EQ(0, delegateTester_.numKeysDown);
94   ASSERT_EQ(9, [delegateTester_ getKeyList].size());
95   ASSERT_EQ(kKeyCodeUS[kShiftIndex], [delegateTester_ getKeyList][0]);
96   ASSERT_EQ(kKeyCodeUS['A'], [delegateTester_ getKeyList][1]);
97   ASSERT_EQ(kKeyCodeUS[kShiftIndex], [delegateTester_ getKeyList][2]);
98   ASSERT_EQ(kKeyCodeUS['B'], [delegateTester_ getKeyList][3]);
99   ASSERT_EQ(kKeyCodeUS[kShiftIndex], [delegateTester_ getKeyList][4]);
100   ASSERT_EQ(kKeyCodeUS['C'], [delegateTester_ getKeyList][5]);
101   ASSERT_EQ(kKeyCodeUS['a'], [delegateTester_ getKeyList][6]);
102   ASSERT_EQ(kKeyCodeUS['b'], [delegateTester_ getKeyList][7]);
103   ASSERT_EQ(kKeyCodeUS['c'], [delegateTester_ getKeyList][8]);
106 TEST_F(KeyInputTest, CtrlAltDel) {
107   [keyInput_ ctrlAltDel];
109   ASSERT_EQ(0, delegateTester_.numKeysDown);
110   ASSERT_EQ(3, [delegateTester_ getKeyList].size());
111   ASSERT_EQ(kKeyCodeUS[kCtrlIndex], [delegateTester_ getKeyList][0]);
112   ASSERT_EQ(kKeyCodeUS[kAltIndex], [delegateTester_ getKeyList][1]);
113   ASSERT_EQ(kKeyCodeUS[kDelIndex], [delegateTester_ getKeyList][2]);
116 TEST_F(KeyInputTest, Backspace) {
117   [keyInput_ deleteBackward];
119   ASSERT_EQ(0, delegateTester_.numKeysDown);
120   ASSERT_EQ(1, [delegateTester_ getKeyList].size());
121   ASSERT_EQ(kKeyCodeUS[kBackspaceIndex], [delegateTester_ getKeyList][0]);
124 }  // namespace remoting