Update parsing of dumpsys batterystats
[chromium-blink-merge.git] / ash / keyboard_overlay / keyboard_overlay_view_unittest.cc
blob8875f0ee75e0abb04e5c8ca614f3c10bdc511281
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 false);
42 EXPECT_TRUE(view.IsCancelingKeyEvent(&open_key));
46 // Verifies that there are no redunduant keys in the canceling keys.
47 TEST_F(KeyboardOverlayViewTest, NoRedundantCancelingKeys) {
48 std::vector<KeyboardOverlayView::KeyEventData> open_keys;
49 for (size_t i = 0; i < kAcceleratorDataLength; ++i) {
50 if (kAcceleratorData[i].action != SHOW_KEYBOARD_OVERLAY)
51 continue;
52 // Escape is used just for canceling.
53 KeyboardOverlayView::KeyEventData open_key = {
54 kAcceleratorData[i].keycode,
55 kAcceleratorData[i].modifiers,
57 open_keys.push_back(open_key);
60 std::vector<KeyboardOverlayView::KeyEventData> canceling_keys;
61 KeyboardOverlayView::GetCancelingKeysForTesting(&canceling_keys);
63 // Escape is used just for canceling, so exclude it from the comparison with
64 // open keys.
65 KeyboardOverlayView::KeyEventData escape = { ui::VKEY_ESCAPE, ui::EF_NONE };
66 std::vector<KeyboardOverlayView::KeyEventData>::iterator escape_itr =
67 std::find(canceling_keys.begin(), canceling_keys.end(), escape);
68 canceling_keys.erase(escape_itr);
70 // Other canceling keys should be same as opening keys.
71 EXPECT_EQ(open_keys.size(), canceling_keys.size());
72 for (size_t i = 0; i < canceling_keys.size(); ++i) {
73 EXPECT_NE(std::find(open_keys.begin(), open_keys.end(), canceling_keys[i]),
74 open_keys.end());
78 } // namespace ash