Switch global error menu icon to vectorized MD asset
[chromium-blink-merge.git] / ash / keyboard_overlay / keyboard_overlay_view_unittest.cc
blob19435a802e52da1d60bf7e9372d057d65254b7fb
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/shell_delegate.h"
13 #include "ash/test/ash_test_base.h"
14 #include "ui/web_dialogs/test/test_web_contents_handler.h"
15 #include "ui/web_dialogs/test/test_web_dialog_delegate.h"
17 namespace ash {
19 typedef test::AshTestBase KeyboardOverlayViewTest;
21 bool operator==(const KeyboardOverlayView::KeyEventData& lhs,
22 const KeyboardOverlayView::KeyEventData& rhs) {
23 return (lhs.key_code == rhs.key_code) && (lhs.flags == rhs.flags);
26 // Verifies that the accelerators that open the keyboard overlay close it.
27 TEST_F(KeyboardOverlayViewTest, OpenAcceleratorsClose) {
28 ui::test::TestWebDialogDelegate delegate(GURL("chrome://keyboardoverlay"));
29 KeyboardOverlayView view(
30 Shell::GetInstance()->delegate()->GetActiveBrowserContext(),
31 &delegate,
32 new ui::test::TestWebContentsHandler);
33 for (size_t i = 0; i < kAcceleratorDataLength; ++i) {
34 if (kAcceleratorData[i].action != SHOW_KEYBOARD_OVERLAY)
35 continue;
36 const AcceleratorData& open_key_data = kAcceleratorData[i];
37 ui::KeyEvent open_key(open_key_data.trigger_on_press ?
38 ui::ET_KEY_PRESSED : ui::ET_KEY_RELEASED,
39 open_key_data.keycode,
40 open_key_data.modifiers);
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