OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "ash/keyboard_overlay/keyboard_overlay_view.h" |
| 6 |
| 7 #include <algorithm> |
| 8 |
| 9 #include "ash/accelerators/accelerator_table.h" |
| 10 #include "ash/keyboard_overlay/keyboard_overlay_delegate.h" |
| 11 #include "ash/shell.h" |
| 12 #include "ash/test/ash_test_base.h" |
| 13 #include "ui/web_dialogs/test/test_web_contents_handler.h" |
| 14 #include "ui/web_dialogs/test/test_web_dialog_delegate.h" |
| 15 |
| 16 namespace ash { |
| 17 |
| 18 typedef test::AshTestBase KeyboardOverlayViewTest; |
| 19 |
| 20 bool operator==(const KeyboardOverlayView::KeyEventData& lhs, |
| 21 const KeyboardOverlayView::KeyEventData& rhs) { |
| 22 return (lhs.key_code == rhs.key_code) && (lhs.flags == rhs.flags); |
| 23 } |
| 24 |
| 25 // Verifies that the accelerators that open the keyboard overlay close it. |
| 26 TEST_F(KeyboardOverlayViewTest, OpenAcceleratorsClose) { |
| 27 KeyboardOverlayView* view = new KeyboardOverlayView( |
| 28 Shell::GetInstance()->browser_context(), |
| 29 new ui::test::TestWebDialogDelegate(GURL("chrome://keyboardoverlay")), |
| 30 new ui::test::TestWebContentsHandler); |
| 31 for (size_t i = 0; i < kAcceleratorDataLength; ++i) { |
| 32 if (kAcceleratorData[i].action != SHOW_KEYBOARD_OVERLAY) |
| 33 continue; |
| 34 const AcceleratorData& open_key_data = kAcceleratorData[i]; |
| 35 ui::KeyEvent open_key(open_key_data.trigger_on_press ? |
| 36 ui::ET_KEY_PRESSED : ui::ET_KEY_RELEASED, |
| 37 open_key_data.keycode, |
| 38 open_key_data.modifiers, |
| 39 false); |
| 40 EXPECT_TRUE(view->IsCancelingKeyEvent(&open_key)); |
| 41 } |
| 42 } |
| 43 |
| 44 // Verifies that there are no redunduant keys in the canceling keys. |
| 45 TEST_F(KeyboardOverlayViewTest, NoRedundantCancelingKeys) { |
| 46 std::vector<KeyboardOverlayView::KeyEventData> open_keys; |
| 47 for (size_t i = 0; i < kAcceleratorDataLength; ++i) { |
| 48 if (kAcceleratorData[i].action != SHOW_KEYBOARD_OVERLAY) |
| 49 continue; |
| 50 // Escape is used just for canceling. |
| 51 KeyboardOverlayView::KeyEventData open_key = { |
| 52 kAcceleratorData[i].keycode, |
| 53 kAcceleratorData[i].modifiers, |
| 54 }; |
| 55 open_keys.push_back(open_key); |
| 56 } |
| 57 |
| 58 std::vector<KeyboardOverlayView::KeyEventData> canceling_keys; |
| 59 KeyboardOverlayView::GetCancelingKeysForTesting(&canceling_keys); |
| 60 |
| 61 // Escape is used just for canceling, so exclude it from the comparison with |
| 62 // open keys. |
| 63 KeyboardOverlayView::KeyEventData escape = { ui::VKEY_ESCAPE, ui::EF_NONE }; |
| 64 std::vector<KeyboardOverlayView::KeyEventData>::iterator escape_itr = |
| 65 std::find(canceling_keys.begin(), canceling_keys.end(), escape); |
| 66 canceling_keys.erase(escape_itr); |
| 67 |
| 68 // Other canceling keys should be same as opening keys. |
| 69 EXPECT_EQ(open_keys.size(), canceling_keys.size()); |
| 70 for (size_t i = 0; i < canceling_keys.size(); ++i) { |
| 71 EXPECT_NE(std::find(open_keys.begin(), open_keys.end(), canceling_keys[i]), |
| 72 open_keys.end()); |
| 73 } |
| 74 } |
| 75 |
| 76 } // namespace ash |
OLD | NEW |