| OLD | NEW |
| 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 "ui/views/focus/focus_manager.h" | 5 #include "ui/views/focus/focus_manager.h" |
| 6 | 6 |
| 7 #include "base/memory/scoped_ptr.h" |
| 8 #include "base/run_loop.h" |
| 7 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
| 8 #include "ui/views/controls/button/text_button.h" | 10 #include "ui/views/controls/button/text_button.h" |
| 9 #include "ui/views/focus/accelerator_handler.h" | 11 #include "ui/views/focus/accelerator_handler.h" |
| 10 #include "ui/views/focus/focus_manager_test.h" | 12 #include "ui/views/focus/focus_manager_test.h" |
| 11 #include "ui/views/widget/widget.h" | 13 #include "ui/views/widget/widget.h" |
| 12 | 14 |
| 13 namespace views { | 15 namespace views { |
| 14 | 16 |
| 15 namespace { | 17 namespace { |
| 16 | 18 |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 208 MessageTrackingView* mtv = new MessageTrackingView(); | 210 MessageTrackingView* mtv = new MessageTrackingView(); |
| 209 mtv->AddAccelerator(ui::Accelerator(ui::VKEY_0, ui::EF_NONE)); | 211 mtv->AddAccelerator(ui::Accelerator(ui::VKEY_0, ui::EF_NONE)); |
| 210 mtv->AddAccelerator(ui::Accelerator(ui::VKEY_1, ui::EF_NONE)); | 212 mtv->AddAccelerator(ui::Accelerator(ui::VKEY_1, ui::EF_NONE)); |
| 211 GetContentsView()->AddChildView(mtv); | 213 GetContentsView()->AddChildView(mtv); |
| 212 focus_manager->SetFocusedView(mtv); | 214 focus_manager->SetFocusedView(mtv); |
| 213 | 215 |
| 214 // First send a non-accelerator key sequence. | 216 // First send a non-accelerator key sequence. |
| 215 PostKeyDown(ui::VKEY_9); | 217 PostKeyDown(ui::VKEY_9); |
| 216 PostKeyUp(ui::VKEY_9); | 218 PostKeyUp(ui::VKEY_9); |
| 217 AcceleratorHandler accelerator_handler; | 219 AcceleratorHandler accelerator_handler; |
| 218 MessageLoopForUI::current()->PostTask(FROM_HERE, MessageLoop::QuitClosure()); | 220 scoped_ptr<base::RunLoop> run_loop(new base::RunLoop(&accelerator_handler)); |
| 219 MessageLoopForUI::current()->RunWithDispatcher(&accelerator_handler); | 221 run_loop->RunUntilIdle(); |
| 220 // Make sure we get a key-up and key-down. | 222 // Make sure we get a key-up and key-down. |
| 221 ASSERT_EQ(1U, mtv->keys_pressed().size()); | 223 ASSERT_EQ(1U, mtv->keys_pressed().size()); |
| 222 EXPECT_EQ(ui::VKEY_9, mtv->keys_pressed()[0]); | 224 EXPECT_EQ(ui::VKEY_9, mtv->keys_pressed()[0]); |
| 223 ASSERT_EQ(1U, mtv->keys_released().size()); | 225 ASSERT_EQ(1U, mtv->keys_released().size()); |
| 224 EXPECT_EQ(ui::VKEY_9, mtv->keys_released()[0]); | 226 EXPECT_EQ(ui::VKEY_9, mtv->keys_released()[0]); |
| 225 EXPECT_FALSE(mtv->accelerator_pressed()); | 227 EXPECT_FALSE(mtv->accelerator_pressed()); |
| 226 mtv->Reset(); | 228 mtv->Reset(); |
| 227 | 229 |
| 228 // Same thing with repeat and more than one key at once. | 230 // Same thing with repeat and more than one key at once. |
| 229 PostKeyDown(ui::VKEY_9); | 231 PostKeyDown(ui::VKEY_9); |
| 230 PostKeyDown(ui::VKEY_9); | 232 PostKeyDown(ui::VKEY_9); |
| 231 PostKeyDown(ui::VKEY_8); | 233 PostKeyDown(ui::VKEY_8); |
| 232 PostKeyDown(ui::VKEY_9); | 234 PostKeyDown(ui::VKEY_9); |
| 233 PostKeyDown(ui::VKEY_7); | 235 PostKeyDown(ui::VKEY_7); |
| 234 PostKeyUp(ui::VKEY_9); | 236 PostKeyUp(ui::VKEY_9); |
| 235 PostKeyUp(ui::VKEY_7); | 237 PostKeyUp(ui::VKEY_7); |
| 236 PostKeyUp(ui::VKEY_8); | 238 PostKeyUp(ui::VKEY_8); |
| 237 MessageLoopForUI::current()->PostTask(FROM_HERE, MessageLoop::QuitClosure()); | 239 run_loop.reset(new base::RunLoop(&accelerator_handler)); |
| 238 MessageLoopForUI::current()->RunWithDispatcher(&accelerator_handler); | 240 run_loop->RunUntilIdle(); |
| 239 // Make sure we get a key-up and key-down. | 241 // Make sure we get a key-up and key-down. |
| 240 ASSERT_EQ(5U, mtv->keys_pressed().size()); | 242 ASSERT_EQ(5U, mtv->keys_pressed().size()); |
| 241 EXPECT_EQ(ui::VKEY_9, mtv->keys_pressed()[0]); | 243 EXPECT_EQ(ui::VKEY_9, mtv->keys_pressed()[0]); |
| 242 EXPECT_EQ(ui::VKEY_9, mtv->keys_pressed()[1]); | 244 EXPECT_EQ(ui::VKEY_9, mtv->keys_pressed()[1]); |
| 243 EXPECT_EQ(ui::VKEY_8, mtv->keys_pressed()[2]); | 245 EXPECT_EQ(ui::VKEY_8, mtv->keys_pressed()[2]); |
| 244 EXPECT_EQ(ui::VKEY_9, mtv->keys_pressed()[3]); | 246 EXPECT_EQ(ui::VKEY_9, mtv->keys_pressed()[3]); |
| 245 EXPECT_EQ(ui::VKEY_7, mtv->keys_pressed()[4]); | 247 EXPECT_EQ(ui::VKEY_7, mtv->keys_pressed()[4]); |
| 246 ASSERT_EQ(3U, mtv->keys_released().size()); | 248 ASSERT_EQ(3U, mtv->keys_released().size()); |
| 247 EXPECT_EQ(ui::VKEY_9, mtv->keys_released()[0]); | 249 EXPECT_EQ(ui::VKEY_9, mtv->keys_released()[0]); |
| 248 EXPECT_EQ(ui::VKEY_7, mtv->keys_released()[1]); | 250 EXPECT_EQ(ui::VKEY_7, mtv->keys_released()[1]); |
| 249 EXPECT_EQ(ui::VKEY_8, mtv->keys_released()[2]); | 251 EXPECT_EQ(ui::VKEY_8, mtv->keys_released()[2]); |
| 250 EXPECT_FALSE(mtv->accelerator_pressed()); | 252 EXPECT_FALSE(mtv->accelerator_pressed()); |
| 251 mtv->Reset(); | 253 mtv->Reset(); |
| 252 | 254 |
| 253 // Now send an accelerator key sequence. | 255 // Now send an accelerator key sequence. |
| 254 PostKeyDown(ui::VKEY_0); | 256 PostKeyDown(ui::VKEY_0); |
| 255 PostKeyUp(ui::VKEY_0); | 257 PostKeyUp(ui::VKEY_0); |
| 256 MessageLoopForUI::current()->PostTask(FROM_HERE, MessageLoop::QuitClosure()); | 258 run_loop.reset(new base::RunLoop(&accelerator_handler)); |
| 257 MessageLoopForUI::current()->RunWithDispatcher(&accelerator_handler); | 259 run_loop->RunUntilIdle(); |
| 258 EXPECT_TRUE(mtv->keys_pressed().empty()); | 260 EXPECT_TRUE(mtv->keys_pressed().empty()); |
| 259 EXPECT_TRUE(mtv->keys_released().empty()); | 261 EXPECT_TRUE(mtv->keys_released().empty()); |
| 260 EXPECT_TRUE(mtv->accelerator_pressed()); | 262 EXPECT_TRUE(mtv->accelerator_pressed()); |
| 261 mtv->Reset(); | 263 mtv->Reset(); |
| 262 | 264 |
| 263 // Same thing with repeat and more than one key at once. | 265 // Same thing with repeat and more than one key at once. |
| 264 PostKeyDown(ui::VKEY_0); | 266 PostKeyDown(ui::VKEY_0); |
| 265 PostKeyDown(ui::VKEY_1); | 267 PostKeyDown(ui::VKEY_1); |
| 266 PostKeyDown(ui::VKEY_1); | 268 PostKeyDown(ui::VKEY_1); |
| 267 PostKeyDown(ui::VKEY_0); | 269 PostKeyDown(ui::VKEY_0); |
| 268 PostKeyDown(ui::VKEY_0); | 270 PostKeyDown(ui::VKEY_0); |
| 269 PostKeyUp(ui::VKEY_1); | 271 PostKeyUp(ui::VKEY_1); |
| 270 PostKeyUp(ui::VKEY_0); | 272 PostKeyUp(ui::VKEY_0); |
| 271 MessageLoopForUI::current()->PostTask(FROM_HERE, MessageLoop::QuitClosure()); | 273 run_loop.reset(new base::RunLoop(&accelerator_handler)); |
| 272 MessageLoopForUI::current()->RunWithDispatcher(&accelerator_handler); | 274 run_loop->RunUntilIdle(); |
| 273 EXPECT_TRUE(mtv->keys_pressed().empty()); | 275 EXPECT_TRUE(mtv->keys_pressed().empty()); |
| 274 EXPECT_TRUE(mtv->keys_released().empty()); | 276 EXPECT_TRUE(mtv->keys_released().empty()); |
| 275 EXPECT_TRUE(mtv->accelerator_pressed()); | 277 EXPECT_TRUE(mtv->accelerator_pressed()); |
| 276 mtv->Reset(); | 278 mtv->Reset(); |
| 277 } | 279 } |
| 278 | 280 |
| 279 } // namespace views | 281 } // namespace views |
| OLD | NEW |