Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2017 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 #if defined(USE_ASH) | |
|
xiyuan
2017/04/12 16:15:46
chromeos assumes USE_ASH now so no need to check t
wutao
2017/04/12 18:06:08
Removed #if section.
| |
| 6 #include "ash/accelerators/accelerator_table.h" // nogncheck | |
| 7 #endif | |
| 8 #include "chrome/browser/ui/browser.h" | |
| 9 #include "chrome/browser/ui/tabs/tab_strip_model.h" | |
| 10 #include "chrome/browser/ui/webui/web_ui_test_handler.h" | |
| 11 #include "chrome/common/url_constants.h" | |
| 12 #include "chrome/test/base/in_process_browser_test.h" | |
| 13 #include "chrome/test/base/ui_test_utils.h" | |
| 14 #include "content/public/browser/web_contents.h" | |
| 15 #include "content/public/test/browser_test_utils.h" | |
| 16 #include "testing/gmock/include/gmock/gmock.h" | |
| 17 #include "ui/events/keycodes/keyboard_code_conversion.h" | |
| 18 | |
| 19 namespace { | |
| 20 | |
| 21 class TestWebUIMessageHandler : public content::WebUIMessageHandler { | |
| 22 public: | |
| 23 MOCK_METHOD1(HandleDidPaint, void(const base::ListValue*)); | |
| 24 | |
| 25 void RegisterMessages() override { | |
| 26 web_ui()->RegisterMessageCallback( | |
| 27 "didPaint", base::Bind(&TestWebUIMessageHandler::HandleDidPaint, | |
| 28 base::Unretained(this))); | |
| 29 } | |
| 30 }; | |
| 31 | |
| 32 } // namespace | |
| 33 | |
| 34 class KeyboradOverlayUIBrowserTest : public InProcessBrowserTest { | |
|
xiyuan
2017/04/12 16:15:46
It seems like you can just do
using KeyboradOverl
wutao
2017/04/12 18:06:08
Done.
| |
| 35 public: | |
| 36 KeyboradOverlayUIBrowserTest() {} | |
| 37 | |
| 38 void SetUpOnMainThread() override { | |
| 39 InProcessBrowserTest::SetUpOnMainThread(); | |
| 40 } | |
| 41 }; | |
| 42 | |
| 43 IN_PROC_BROWSER_TEST_F(KeyboradOverlayUIBrowserTest, | |
| 44 ShouldHaveKeyboardOverlay) { | |
| 45 ui_test_utils::NavigateToURL(browser(), | |
| 46 GURL(chrome::kChromeUIKeyboardOverlayURL)); | |
| 47 content::WebContents* web_contents = | |
| 48 browser()->tab_strip_model()->GetActiveWebContents(); | |
| 49 content::WebUIMessageHandler* test_handler = new TestWebUIMessageHandler; | |
| 50 web_contents->GetWebUI()->AddMessageHandler(base::WrapUnique(test_handler)); | |
|
xiyuan
2017/04/12 16:15:47
What is the purpose of |test_handler|? It seems no
wutao
2017/04/12 18:06:08
Need TestWebUIMessageHandler to handle message "di
| |
| 51 | |
| 52 #if defined(USE_ASH) | |
|
xiyuan
2017/04/12 16:15:46
get rid of this
wutao
2017/04/12 18:06:08
Done.
| |
| 53 for (size_t j = 0; j < ash::kAcceleratorDataLength; ++j) { | |
|
xiyuan
2017/04/12 16:15:46
for (const auto& entry : ash::kAcceleratorData) {
wutao
2017/04/12 18:06:09
Cannot use incomplete type as a range, so I will c
| |
| 54 const ash::AcceleratorData entry = ash::kAcceleratorData[j]; | |
| 55 if (!(entry.keycode ^ ui::VKEY_MENU) || !(entry.keycode ^ ui::VKEY_LWIN) || | |
| 56 !(entry.modifiers ^ ui::EF_NONE) || | |
| 57 !(entry.modifiers ^ ui::EF_CONTROL_DOWN ^ ui::EF_ALT_DOWN ^ | |
| 58 ui::EF_SHIFT_DOWN)) | |
|
xiyuan
2017/04/12 16:15:46
What this "if" do ? Somehow it does not make a lot
wutao
2017/04/12 18:06:08
Some accelerator is handled in the code, not by th
| |
| 59 continue; | |
|
xiyuan
2017/04/12 16:15:46
nit: wrap with {} since conditions occupy more tha
wutao
2017/04/12 18:06:08
Done.
| |
| 60 | |
| 61 ui::KeyboardCode keyboard_code = entry.keycode; | |
| 62 unsigned int code = (unsigned int)keyboard_code; | |
|
xiyuan
2017/04/12 16:15:47
use static_cast<>. Casting with () is not allowed.
wutao
2017/04/12 18:06:08
Removed.
| |
| 63 std::string shortcut; | |
| 64 ASSERT_TRUE(content::ExecuteScriptAndExtractString( | |
| 65 web_contents, | |
| 66 "domAutomationController.send(" | |
| 67 " (function(number) {" | |
| 68 " if (!!KEYCODE_TO_LABEL[number]) {" | |
| 69 " return KEYCODE_TO_LABEL[number];" | |
| 70 " } else {" | |
| 71 " return 'NONE';" | |
| 72 " }" | |
| 73 " })(" + | |
| 74 std::to_string(code) + | |
| 75 ")" | |
|
xiyuan
2017/04/12 16:15:47
nit: I would fold line 74 and 75 onto line 73 to m
wutao
2017/04/12 18:06:08
git cl format changed this and warn me if I change
| |
| 76 " );", | |
|
xiyuan
2017/04/12 16:15:46
nit: align ");" with the start of "domAutomationCo
wutao
2017/04/12 18:06:08
Done.
| |
| 77 &shortcut)); | |
| 78 if (shortcut == "NONE") { | |
| 79 shortcut = DomCodeToUsLayoutCharacter( | |
| 80 UsLayoutKeyboardCodeToDomCode( | |
| 81 LocatedToNonLocatedKeyboardCode(keyboard_code)), | |
| 82 false); | |
| 83 } | |
| 84 | |
| 85 if (entry.modifiers & ui::EF_ALT_DOWN) | |
|
xiyuan
2017/04/12 16:15:46
nit: document the order of the "if" should not be
wutao
2017/04/12 18:06:08
Done.
| |
| 86 shortcut.append("<>ALT"); | |
| 87 if (entry.modifiers & ui::EF_CONTROL_DOWN) | |
| 88 shortcut.append("<>CTRL"); | |
| 89 if (entry.modifiers & ui::EF_COMMAND_DOWN) | |
| 90 shortcut.append("<>SEARCH"); | |
| 91 if (entry.modifiers & ui::EF_SHIFT_DOWN) | |
| 92 shortcut.append("<>SHIFT"); | |
| 93 | |
| 94 bool is_display_ui_scaling_enabled; | |
| 95 ASSERT_TRUE(content::ExecuteScriptAndExtractBool( | |
| 96 web_contents, | |
| 97 "domAutomationController.send(isDisplayUIScalingEnabled());", | |
|
xiyuan
2017/04/12 16:15:46
This would not change per accelerator. Could you m
wutao
2017/04/12 18:06:08
Good catch! Done.
| |
| 98 &is_display_ui_scaling_enabled)); | |
| 99 if (!is_display_ui_scaling_enabled) { | |
| 100 if (shortcut == "-<>CTRL<>SHIFT" || shortcut == "+<>CTRL<>SHIFT" || | |
| 101 shortcut == "0<>CTRL<>SHIFT") | |
| 102 continue; | |
| 103 } | |
| 104 | |
| 105 bool contains; | |
| 106 ASSERT_TRUE(content::ExecuteScriptAndExtractBool( | |
| 107 web_contents, | |
| 108 "domAutomationController.send(" | |
| 109 " (function() {" | |
|
xiyuan
2017/04/12 16:15:46
nit: the "function" seems not necessary. Can we ju
wutao
2017/04/12 18:06:08
:) Try to make it formal, but yes, I can do it.
| |
| 110 " return !!keyboardOverlayData['shortcut']['" + | |
| 111 shortcut + | |
| 112 "'];" | |
| 113 " })()" | |
| 114 " );", | |
|
xiyuan
2017/04/12 16:15:47
nit: align with "domAutomationController.send("
wutao
2017/04/12 18:06:08
Done.
| |
| 115 &contains)); | |
| 116 ASSERT_TRUE(contains) << "Please add the new accelerators to keyboard " | |
| 117 "overlay. Add one entry '" + | |
| 118 shortcut + | |
| 119 "' in the 'shortcut' section" | |
| 120 " in the file of " | |
| 121 "'/chrome/browser/resources/chromeos/" | |
| 122 "keyboard_overlay_data.js'. Please keep it in " | |
| 123 "alphabetical order."; | |
| 124 } | |
| 125 #endif | |
| 126 } | |
| OLD | NEW |