Separate Simple Backend creation from initialization.
[chromium-blink-merge.git] / ash / keyboard_overlay / keyboard_overlay_view_unittest.cc
blob87afe0572a38c625d5677f6b77fee4b25688a176
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.
5 #include "ash/keyboard_overlay/keyboard_overlay_view.h"
7 #include <algorithm>
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"
16 namespace ash {
18 typedef test::AshTestBase KeyboardOverlayViewTest;
20 bool operator==(const KeyboardOverlayView::KeyEventData& lhs,
21 const KeyboardOverlayView::KeyEventData& rhs) {
22 return (lhs.key_code == rhs.key_code) && (lhs.flags == rhs.flags);
25 // Verifies that the accelerators that open the keyboard overlay close it.
26 TEST_F(KeyboardOverlayViewTest, OpenAcceleratorsClose) {
27 ui::test::TestWebDialogDelegate delegate(GURL("chrome://keyboardoverlay"));
28 KeyboardOverlayView view(
29 Shell::GetInstance()->browser_context(),
30 &delegate,
31 new ui::test::TestWebContentsHandler);
32 for (size_t i = 0; i < kAcceleratorDataLength; ++i) {
33 if (kAcceleratorData[i].action != SHOW_KEYBOARD_OVERLAY)
34 continue;
35 const AcceleratorData& open_key_data = kAcceleratorData[i];
36 ui::KeyEvent open_key(open_key_data.trigger_on_press ?
37 ui::ET_KEY_PRESSED : ui::ET_KEY_RELEASED,
38 open_key_data.keycode,
39 open_key_data.modifiers,
40 false);
41 EXPECT_TRUE(view.IsCancelingKeyEvent(&open_key));
45 // Verifies that there are no redunduant keys in the canceling keys.
46 TEST_F(KeyboardOverlayViewTest, NoRedundantCancelingKeys) {
47 std::vector<KeyboardOverlayView::KeyEventData> open_keys;
48 for (size_t i = 0; i < kAcceleratorDataLength; ++i) {
49 if (kAcceleratorData[i].action != SHOW_KEYBOARD_OVERLAY)
50 continue;
51 // Escape is used just for canceling.
52 KeyboardOverlayView::KeyEventData open_key = {
53 kAcceleratorData[i].keycode,
54 kAcceleratorData[i].modifiers,
56 open_keys.push_back(open_key);
59 std::vector<KeyboardOverlayView::KeyEventData> canceling_keys;
60 KeyboardOverlayView::GetCancelingKeysForTesting(&canceling_keys);
62 // Escape is used just for canceling, so exclude it from the comparison with
63 // open keys.
64 KeyboardOverlayView::KeyEventData escape = { ui::VKEY_ESCAPE, ui::EF_NONE };
65 std::vector<KeyboardOverlayView::KeyEventData>::iterator escape_itr =
66 std::find(canceling_keys.begin(), canceling_keys.end(), escape);
67 canceling_keys.erase(escape_itr);
69 // Other canceling keys should be same as opening keys.
70 EXPECT_EQ(open_keys.size(), canceling_keys.size());
71 for (size_t i = 0; i < canceling_keys.size(); ++i) {
72 EXPECT_NE(std::find(open_keys.begin(), open_keys.end(), canceling_keys[i]),
73 open_keys.end());
77 } // namespace ash