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

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

Issue 11594008: Revert 173477 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 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 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
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/memory/scoped_ptr.h" 12 #include "base/memory/scoped_ptr.h"
13 #include "base/message_loop.h" 13 #include "base/message_loop.h"
14 #include "chrome/browser/chromeos/input_method/input_method_util.h" 14 #include "chrome/browser/chromeos/input_method/input_method_util.h"
15 #include "chrome/browser/chromeos/input_method/input_method_whitelist.h" 15 #include "chrome/browser/chromeos/input_method/input_method_whitelist.h"
16 #include "chrome/browser/chromeos/input_method/mock_input_method_delegate.h" 16 #include "chrome/browser/chromeos/input_method/mock_input_method_delegate.h"
17 #include "chrome/browser/chromeos/input_method/mock_sequenced_task_runner.h" 17 #include "content/public/test/test_browser_thread.h"
18 #include "testing/gtest/include/gtest/gtest.h" 18 #include "testing/gtest/include/gtest/gtest.h"
19 #include "ui/base/x/x11_util.h" 19 #include "ui/base/x/x11_util.h"
20 20
21 #include <X11/Xlib.h> 21 #include <X11/Xlib.h>
22 22
23 using content::BrowserThread;
24
23 namespace chromeos { 25 namespace chromeos {
24 namespace input_method { 26 namespace input_method {
25 27
26 namespace { 28 namespace {
27 29
28 class XKeyboardTest : public testing::Test { 30 class XKeyboardTest : public testing::Test {
29 public: 31 public:
30 XKeyboardTest() 32 XKeyboardTest()
31 : util_(&delegate_, whitelist_.GetSupportedInputMethods()), 33 : util_(&delegate_, whitelist_.GetSupportedInputMethods()),
32 mock_task_runner_(new MockSequencedTaskRunner) { 34 ui_thread_(BrowserThread::UI, &message_loop_) {
33 } 35 }
34 36
35 virtual void SetUp() { 37 virtual void SetUp() {
36 xkey_.reset(XKeyboard::Create(util_, mock_task_runner_)); 38 xkey_.reset(XKeyboard::Create(util_));
37 } 39 }
38 40
39 virtual void TearDown() { 41 virtual void TearDown() {
40 xkey_.reset(); 42 xkey_.reset();
41 } 43 }
42 44
43 MockInputMethodDelegate delegate_; 45 MockInputMethodDelegate delegate_;
44 InputMethodWhitelist whitelist_; 46 InputMethodWhitelist whitelist_;
45 InputMethodUtil util_; 47 InputMethodUtil util_;
46 scoped_refptr<MockSequencedTaskRunner> mock_task_runner_;
47 scoped_ptr<XKeyboard> xkey_; 48 scoped_ptr<XKeyboard> xkey_;
49
50 MessageLoopForUI message_loop_;
51 content::TestBrowserThread ui_thread_;
48 }; 52 };
49 53
50 // Returns true if X display is available. 54 // Returns true if X display is available.
51 bool DisplayAvailable() { 55 bool DisplayAvailable() {
52 return ui::GetXDisplay() ? true : false; 56 return ui::GetXDisplay() ? true : false;
53 } 57 }
54 58
55 } // namespace 59 } // namespace
56 60
57 // Tests CheckLayoutName() function. 61 // Tests CheckLayoutName() function.
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 // No-op GetLockedModifiers call. Confirm it does not crash. 182 // No-op GetLockedModifiers call. Confirm it does not crash.
179 xkey_->GetLockedModifiers(NULL, NULL); 183 xkey_->GetLockedModifiers(NULL, NULL);
180 } 184 }
181 185
182 TEST_F(XKeyboardTest, TestSetAutoRepeatEnabled) { 186 TEST_F(XKeyboardTest, TestSetAutoRepeatEnabled) {
183 if (!DisplayAvailable()) { 187 if (!DisplayAvailable()) {
184 DVLOG(1) << "X server is not available. Skip the test."; 188 DVLOG(1) << "X server is not available. Skip the test.";
185 return; 189 return;
186 } 190 }
187 const bool state = XKeyboard::GetAutoRepeatEnabledForTesting(); 191 const bool state = XKeyboard::GetAutoRepeatEnabledForTesting();
188 xkey_->SetAutoRepeatEnabled(!state); 192 XKeyboard::SetAutoRepeatEnabled(!state);
189 EXPECT_EQ(!state, XKeyboard::GetAutoRepeatEnabledForTesting()); 193 EXPECT_EQ(!state, XKeyboard::GetAutoRepeatEnabledForTesting());
190 // Restore the initial state. 194 // Restore the initial state.
191 xkey_->SetAutoRepeatEnabled(state); 195 XKeyboard::SetAutoRepeatEnabled(state);
192 EXPECT_EQ(state, XKeyboard::GetAutoRepeatEnabledForTesting()); 196 EXPECT_EQ(state, XKeyboard::GetAutoRepeatEnabledForTesting());
193 } 197 }
194 198
195 TEST_F(XKeyboardTest, TestSetAutoRepeatRate) { 199 TEST_F(XKeyboardTest, TestSetAutoRepeatRate) {
196 if (!DisplayAvailable()) { 200 if (!DisplayAvailable()) {
197 DVLOG(1) << "X server is not available. Skip the test."; 201 DVLOG(1) << "X server is not available. Skip the test.";
198 return; 202 return;
199 } 203 }
200 AutoRepeatRate rate; 204 AutoRepeatRate rate;
201 EXPECT_TRUE(XKeyboard::GetAutoRepeatRateForTesting(&rate)); 205 EXPECT_TRUE(XKeyboard::GetAutoRepeatRateForTesting(&rate));
202 206
203 AutoRepeatRate tmp(rate); 207 AutoRepeatRate tmp(rate);
204 ++tmp.initial_delay_in_ms; 208 ++tmp.initial_delay_in_ms;
205 ++tmp.repeat_interval_in_ms; 209 ++tmp.repeat_interval_in_ms;
206 EXPECT_TRUE(xkey_->SetAutoRepeatRate(tmp)); 210 EXPECT_TRUE(XKeyboard::SetAutoRepeatRate(tmp));
207 EXPECT_TRUE(XKeyboard::GetAutoRepeatRateForTesting(&tmp)); 211 EXPECT_TRUE(XKeyboard::GetAutoRepeatRateForTesting(&tmp));
208 EXPECT_EQ(rate.initial_delay_in_ms + 1, tmp.initial_delay_in_ms); 212 EXPECT_EQ(rate.initial_delay_in_ms + 1, tmp.initial_delay_in_ms);
209 EXPECT_EQ(rate.repeat_interval_in_ms + 1, tmp.repeat_interval_in_ms); 213 EXPECT_EQ(rate.repeat_interval_in_ms + 1, tmp.repeat_interval_in_ms);
210 214
211 // Restore the initial state. 215 // Restore the initial state.
212 EXPECT_TRUE(xkey_->SetAutoRepeatRate(rate)); 216 EXPECT_TRUE(XKeyboard::SetAutoRepeatRate(rate));
213 EXPECT_TRUE(XKeyboard::GetAutoRepeatRateForTesting(&tmp)); 217 EXPECT_TRUE(XKeyboard::GetAutoRepeatRateForTesting(&tmp));
214 EXPECT_EQ(rate.initial_delay_in_ms, tmp.initial_delay_in_ms); 218 EXPECT_EQ(rate.initial_delay_in_ms, tmp.initial_delay_in_ms);
215 EXPECT_EQ(rate.repeat_interval_in_ms, tmp.repeat_interval_in_ms); 219 EXPECT_EQ(rate.repeat_interval_in_ms, tmp.repeat_interval_in_ms);
216 } 220 }
217 221
218 } // namespace input_method 222 } // namespace input_method
219 } // namespace chromeos 223 } // 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