Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(36)

Side by Side Diff: chrome/browser/ui/ash/keyboard_end_to_end_browsertest.cc

Issue 2702933002: Add an end to end test: virtual keyboard opens on click of text input (Closed)
Patch Set: Updated the test so to simulate user's click. Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | chrome/test/BUILD.gn » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 #include "base/command_line.h"
6 #include "base/files/file.h"
7 #include "chrome/browser/ui/browser.h"
8 #include "chrome/browser/ui/tabs/tab_strip_model.h"
9 #include "chrome/test/base/in_process_browser_test.h"
10 #include "chrome/test/base/ui_test_utils.h"
11 #include "content/public/test/browser_test_utils.h"
12 #include "ui/keyboard/content/keyboard_constants.h"
13 #include "ui/keyboard/keyboard_controller.h"
14 #include "ui/keyboard/keyboard_switches.h"
15 #include "ui/keyboard/keyboard_test_util.h"
16
17 namespace {
18
19 bool IsKeyboardVisible() {
20 return keyboard::KeyboardController::GetInstance()->keyboard_visible();
21 }
22
23 // Simulates a click on the middle of the DOM element with the given |id|.
24 void ClickElementWithId(content::WebContents* web_contents,
25 const std::string& id) {
26 int x;
27 ASSERT_TRUE(content::ExecuteScriptAndExtractInt(
28 web_contents,
29 "var bounds = document.getElementById('" + id +
30 "').getBoundingClientRect();"
31 "domAutomationController.send("
32 " Math.floor(bounds.left + bounds.width / 2));",
33 &x));
34 int y;
35 ASSERT_TRUE(content::ExecuteScriptAndExtractInt(
36 web_contents,
37 "var bounds = document.getElementById('" + id +
38 "').getBoundingClientRect();"
39 "domAutomationController.send("
40 " Math.floor(bounds.top + bounds.height / 2));",
41 &y));
42 content::SimulateMouseClickAt(
43 web_contents, 0, blink::WebMouseEvent::Button::Left, gfx::Point(x, y));
44 }
45
46 } // namespace
47
48 namespace keyboard {
49
50 class KeyboardEndToEndTest : public InProcessBrowserTest {
51 public:
52 KeyboardEndToEndTest() {}
53 ~KeyboardEndToEndTest() override {}
54
55 // Ensure that the virtual keyboard is enabled.
56 void SetUpCommandLine(base::CommandLine* command_line) override {
57 command_line->AppendSwitch(keyboard::switches::kEnableVirtualKeyboard);
58 }
59 };
60
61 IN_PROC_BROWSER_TEST_F(KeyboardEndToEndTest, OpenIfFocusedOnClick) {
62 GURL test_url =
63 ui_test_utils::GetTestUrl(base::FilePath("chromeos/virtual_keyboard"),
64 base::FilePath("inputs.html"));
65 ui_test_utils::NavigateToURL(browser(), test_url);
66 content::WebContents* web_contents =
67 browser()->tab_strip_model()->GetActiveWebContents();
68 ASSERT_TRUE(web_contents);
69
70 EXPECT_FALSE(IsKeyboardVisible());
71
72 ClickElementWithId(web_contents, "text");
73
74 ASSERT_TRUE(keyboard::WaitUntilShown());
75 EXPECT_TRUE(IsKeyboardVisible());
76
77 ClickElementWithId(web_contents, "blur");
78 ASSERT_TRUE(keyboard::WaitUntilHidden());
79 EXPECT_FALSE(IsKeyboardVisible());
80 }
81
82 } // namespace keyboard
OLDNEW
« no previous file with comments | « no previous file | chrome/test/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698