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

Side by Side Diff: chrome/browser/chromeos/input_method/xkeyboard_unittest.cc

Issue 10416028: Rename chromeos::input_method::kLeftControl to chromeos::input_method::kControl. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 7 months 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 #include "chrome/browser/chromeos/input_method/xkeyboard.h" 5 #include "chrome/browser/chromeos/input_method/xkeyboard.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <set> 8 #include <set>
9 #include <string> 9 #include <string>
10 10
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 InputMethodWhitelist whitelist_; 44 InputMethodWhitelist whitelist_;
45 InputMethodUtil util_; 45 InputMethodUtil util_;
46 scoped_ptr<XKeyboard> xkey_; 46 scoped_ptr<XKeyboard> xkey_;
47 47
48 MessageLoopForUI message_loop_; 48 MessageLoopForUI message_loop_;
49 content::TestBrowserThread ui_thread_; 49 content::TestBrowserThread ui_thread_;
50 }; 50 };
51 51
52 // Returns a ModifierMap object that contains the following mapping: 52 // Returns a ModifierMap object that contains the following mapping:
53 // - kSearchKey is mapped to |search|. 53 // - kSearchKey is mapped to |search|.
54 // - kLeftControl key is mapped to |control|. 54 // - kControl key is mapped to |control|.
55 // - kLeftAlt key is mapped to |alt|. 55 // - kAlt key is mapped to |alt|.
56 ModifierMap GetMap(ModifierKey search, ModifierKey control, ModifierKey alt) { 56 ModifierMap GetMap(ModifierKey search, ModifierKey control, ModifierKey alt) {
57 ModifierMap modifier_key; 57 ModifierMap modifier_key;
58 // Use the Search key as |search|. 58 // Use the Search key as |search|.
59 modifier_key.push_back(ModifierKeyPair(kSearchKey, search)); 59 modifier_key.push_back(ModifierKeyPair(kSearchKey, search));
60 modifier_key.push_back(ModifierKeyPair(kLeftControlKey, control)); 60 modifier_key.push_back(ModifierKeyPair(kControlKey, control));
61 modifier_key.push_back(ModifierKeyPair(kLeftAltKey, alt)); 61 modifier_key.push_back(ModifierKeyPair(kAltKey, alt));
62 return modifier_key; 62 return modifier_key;
63 } 63 }
64 64
65 // Checks |modifier_map| and returns true if the following conditions are met: 65 // Checks |modifier_map| and returns true if the following conditions are met:
66 // - kSearchKey is mapped to |search|. 66 // - kSearchKey is mapped to |search|.
67 // - kLeftControl key is mapped to |control|. 67 // - kControl key is mapped to |control|.
68 // - kLeftAlt key is mapped to |alt|. 68 // - kAlt key is mapped to |alt|.
69 bool CheckMap(const ModifierMap& modifier_map, 69 bool CheckMap(const ModifierMap& modifier_map,
70 ModifierKey search, ModifierKey control, ModifierKey alt) { 70 ModifierKey search, ModifierKey control, ModifierKey alt) {
71 ModifierMap::const_iterator begin = modifier_map.begin(); 71 ModifierMap::const_iterator begin = modifier_map.begin();
72 ModifierMap::const_iterator end = modifier_map.end(); 72 ModifierMap::const_iterator end = modifier_map.end();
73 if ((std::count(begin, end, ModifierKeyPair(kSearchKey, search)) == 1) && 73 if ((std::count(begin, end, ModifierKeyPair(kSearchKey, search)) == 1) &&
74 (std::count(begin, end, 74 (std::count(begin, end,
75 ModifierKeyPair(kLeftControlKey, control)) == 1) && 75 ModifierKeyPair(kControlKey, control)) == 1) &&
76 (std::count(begin, end, ModifierKeyPair(kLeftAltKey, alt)) == 1)) { 76 (std::count(begin, end, ModifierKeyPair(kAltKey, alt)) == 1)) {
77 return true; 77 return true;
78 } 78 }
79 return false; 79 return false;
80 } 80 }
81 81
82 // Returns true if X display is available. 82 // Returns true if X display is available.
83 bool DisplayAvailable() { 83 bool DisplayAvailable() {
84 return ui::GetXDisplay() ? true : false; 84 return ui::GetXDisplay() ? true : false;
85 } 85 }
86 86
(...skipping 12 matching lines...) Expand all
99 // CreateFullXkbLayoutName should not accept an incomplete ModifierMap. 99 // CreateFullXkbLayoutName should not accept an incomplete ModifierMap.
100 ModifierMap tmp_map = GetMap(kVoidKey, kVoidKey, kVoidKey); 100 ModifierMap tmp_map = GetMap(kVoidKey, kVoidKey, kVoidKey);
101 tmp_map.pop_back(); 101 tmp_map.pop_back();
102 EXPECT_STREQ("", xkey_->CreateFullXkbLayoutName("us", tmp_map).c_str()); 102 EXPECT_STREQ("", xkey_->CreateFullXkbLayoutName("us", tmp_map).c_str());
103 103
104 // CreateFullXkbLayoutName should not accept redundant ModifierMaps. 104 // CreateFullXkbLayoutName should not accept redundant ModifierMaps.
105 tmp_map = GetMap(kVoidKey, kVoidKey, kVoidKey); 105 tmp_map = GetMap(kVoidKey, kVoidKey, kVoidKey);
106 tmp_map.push_back(ModifierKeyPair(kSearchKey, kVoidKey)); // two search maps 106 tmp_map.push_back(ModifierKeyPair(kSearchKey, kVoidKey)); // two search maps
107 EXPECT_STREQ("", xkey_->CreateFullXkbLayoutName("us", tmp_map).c_str()); 107 EXPECT_STREQ("", xkey_->CreateFullXkbLayoutName("us", tmp_map).c_str());
108 tmp_map = GetMap(kVoidKey, kVoidKey, kVoidKey); 108 tmp_map = GetMap(kVoidKey, kVoidKey, kVoidKey);
109 tmp_map.push_back(ModifierKeyPair(kLeftControlKey, kVoidKey)); // two ctrls 109 tmp_map.push_back(ModifierKeyPair(kControlKey, kVoidKey)); // two ctrls
110 EXPECT_STREQ("", xkey_->CreateFullXkbLayoutName("us", tmp_map).c_str()); 110 EXPECT_STREQ("", xkey_->CreateFullXkbLayoutName("us", tmp_map).c_str());
111 tmp_map = GetMap(kVoidKey, kVoidKey, kVoidKey); 111 tmp_map = GetMap(kVoidKey, kVoidKey, kVoidKey);
112 tmp_map.push_back(ModifierKeyPair(kLeftAltKey, kVoidKey)); // two alts. 112 tmp_map.push_back(ModifierKeyPair(kAltKey, kVoidKey)); // two alts.
113 EXPECT_STREQ("", xkey_->CreateFullXkbLayoutName("us", tmp_map).c_str()); 113 EXPECT_STREQ("", xkey_->CreateFullXkbLayoutName("us", tmp_map).c_str());
114 114
115 // CreateFullXkbLayoutName should not accept invalid ModifierMaps. 115 // CreateFullXkbLayoutName should not accept invalid ModifierMaps.
116 tmp_map = GetMap(kVoidKey, kVoidKey, kVoidKey); 116 tmp_map = GetMap(kVoidKey, kVoidKey, kVoidKey);
117 tmp_map.push_back(ModifierKeyPair(kVoidKey, kSearchKey)); // can't remap void 117 tmp_map.push_back(ModifierKeyPair(kVoidKey, kSearchKey)); // can't remap void
118 EXPECT_STREQ("", xkey_->CreateFullXkbLayoutName("us", tmp_map).c_str()); 118 EXPECT_STREQ("", xkey_->CreateFullXkbLayoutName("us", tmp_map).c_str());
119 tmp_map = GetMap(kVoidKey, kVoidKey, kVoidKey); 119 tmp_map = GetMap(kVoidKey, kVoidKey, kVoidKey);
120 tmp_map.push_back(ModifierKeyPair(kCapsLockKey, kSearchKey)); // ditto 120 tmp_map.push_back(ModifierKeyPair(kCapsLockKey, kSearchKey)); // ditto
121 EXPECT_STREQ("", xkey_->CreateFullXkbLayoutName("us", tmp_map).c_str()); 121 EXPECT_STREQ("", xkey_->CreateFullXkbLayoutName("us", tmp_map).c_str());
122 122
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 } 175 }
176 176
177 TEST_F(XKeyboardTest, TestCreateFullXkbLayoutNameKeepCapsLock) { 177 TEST_F(XKeyboardTest, TestCreateFullXkbLayoutNameKeepCapsLock) {
178 EXPECT_STREQ("us(colemak)+chromeos(search_disabled_disabled)", 178 EXPECT_STREQ("us(colemak)+chromeos(search_disabled_disabled)",
179 xkey_->CreateFullXkbLayoutName( 179 xkey_->CreateFullXkbLayoutName(
180 "us(colemak)", 180 "us(colemak)",
181 // The 1st kVoidKey should be ignored. 181 // The 1st kVoidKey should be ignored.
182 GetMap(kVoidKey, kVoidKey, kVoidKey)).c_str()); 182 GetMap(kVoidKey, kVoidKey, kVoidKey)).c_str());
183 EXPECT_STREQ("de(neo)+chromeos(search_leftcontrol_leftcontrol_keepralt)", 183 EXPECT_STREQ("de(neo)+chromeos(search_leftcontrol_leftcontrol_keepralt)",
184 xkey_->CreateFullXkbLayoutName( 184 xkey_->CreateFullXkbLayoutName(
185 // The 1st kLeftControlKey should be ignored. 185 // The 1st kControlKey should be ignored.
186 "de(neo)", GetMap(kLeftControlKey, 186 "de(neo)", GetMap(kControlKey,
187 kLeftControlKey, 187 kControlKey,
188 kLeftControlKey)).c_str()); 188 kControlKey)).c_str());
189 EXPECT_STREQ("gb(extd)+chromeos(disabled_disabled_disabled_keepralt)", 189 EXPECT_STREQ("gb(extd)+chromeos(disabled_disabled_disabled_keepralt)",
190 xkey_->CreateFullXkbLayoutName( 190 xkey_->CreateFullXkbLayoutName(
191 "gb(extd)", 191 "gb(extd)",
192 GetMap(kVoidKey, kVoidKey, kVoidKey)).c_str()); 192 GetMap(kVoidKey, kVoidKey, kVoidKey)).c_str());
193 } 193 }
194 194
195 TEST_F(XKeyboardTest, TestCreateFullXkbLayoutNameKeepAlt) { 195 TEST_F(XKeyboardTest, TestCreateFullXkbLayoutNameKeepAlt) {
196 EXPECT_STREQ("us(intl)+chromeos(disabled_disabled_disabled_keepralt)", 196 EXPECT_STREQ("us(intl)+chromeos(disabled_disabled_disabled_keepralt)",
197 xkey_->CreateFullXkbLayoutName( 197 xkey_->CreateFullXkbLayoutName(
198 "us(intl)", GetMap(kVoidKey, kVoidKey, kVoidKey)).c_str()); 198 "us(intl)", GetMap(kVoidKey, kVoidKey, kVoidKey)).c_str());
199 EXPECT_STREQ("kr(kr104)+" 199 EXPECT_STREQ("kr(kr104)+"
200 "chromeos(leftcontrol_leftcontrol_leftcontrol_keepralt)", 200 "chromeos(leftcontrol_leftcontrol_leftcontrol_keepralt)",
201 xkey_->CreateFullXkbLayoutName( 201 xkey_->CreateFullXkbLayoutName(
202 "kr(kr104)", GetMap(kLeftControlKey, 202 "kr(kr104)", GetMap(kControlKey,
203 kLeftControlKey, 203 kControlKey,
204 kLeftControlKey)).c_str()); 204 kControlKey)).c_str());
205 } 205 }
206 206
207 // Tests if CreateFullXkbLayoutName and ExtractLayoutNameFromFullXkbLayoutName 207 // Tests if CreateFullXkbLayoutName and ExtractLayoutNameFromFullXkbLayoutName
208 // functions could handle all combinations of modifier remapping. 208 // functions could handle all combinations of modifier remapping.
209 TEST_F(XKeyboardTest, TestCreateFullXkbLayoutNameModifierKeys) { 209 TEST_F(XKeyboardTest, TestCreateFullXkbLayoutNameModifierKeys) {
210 std::set<std::string> layouts; 210 std::set<std::string> layouts;
211 for (int i = 0; i < static_cast<int>(kNumModifierKeys); ++i) { 211 for (int i = 0; i < static_cast<int>(kNumModifierKeys); ++i) {
212 for (int j = 0; j < static_cast<int>(kNumModifierKeys); ++j) { 212 for (int j = 0; j < static_cast<int>(kNumModifierKeys); ++j) {
213 for (int k = 0; k < static_cast<int>(kNumModifierKeys); ++k) { 213 for (int k = 0; k < static_cast<int>(kNumModifierKeys); ++k) {
214 const std::string layout = xkey_->CreateFullXkbLayoutName( 214 const std::string layout = xkey_->CreateFullXkbLayoutName(
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
370 370
371 // Restore the initial state. 371 // Restore the initial state.
372 EXPECT_TRUE(XKeyboard::SetAutoRepeatRate(rate)); 372 EXPECT_TRUE(XKeyboard::SetAutoRepeatRate(rate));
373 EXPECT_TRUE(XKeyboard::GetAutoRepeatRateForTesting(&tmp)); 373 EXPECT_TRUE(XKeyboard::GetAutoRepeatRateForTesting(&tmp));
374 EXPECT_EQ(rate.initial_delay_in_ms, tmp.initial_delay_in_ms); 374 EXPECT_EQ(rate.initial_delay_in_ms, tmp.initial_delay_in_ms);
375 EXPECT_EQ(rate.repeat_interval_in_ms, tmp.repeat_interval_in_ms); 375 EXPECT_EQ(rate.repeat_interval_in_ms, tmp.repeat_interval_in_ms);
376 } 376 }
377 377
378 } // namespace input_method 378 } // namespace input_method
379 } // namespace chromeos 379 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/input_method/xkeyboard.cc ('k') | chrome/browser/chromeos/preferences.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698