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

Side by Side Diff: chrome/browser/chromeos/extensions/virtual_keyboard_browsertest.cc

Issue 247883002: Adds browser test framework for the IME keyboard, and some basic typing tests. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Run tests on full layout. Created 6 years, 7 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
OLDNEW
1 /* 1 /*
2 * Copyright 2013 The Chromium Authors. All rights reserved. 2 * Copyright 2013 The Chromium Authors. All rights reserved.
3 * Use of this source code is governed by a BSD-style license that can be 3 * Use of this source code is governed by a BSD-style license that can be
4 * found in the LICENSE file. 4 * found in the LICENSE file.
5 */ 5 */
6 #include "chrome/browser/chromeos/extensions/virtual_keyboard_browsertest.h"
6 7
7 #include <vector> 8 #include <vector>
8 9
9 #include "ash/shell.h" 10 #include "ash/shell.h"
10 #include "base/command_line.h" 11 #include "base/command_line.h"
11 #include "chrome/browser/ui/browser.h" 12 #include "chrome/browser/ui/browser.h"
12 #include "chrome/browser/ui/tabs/tab_strip_model.h" 13 #include "chrome/browser/ui/tabs/tab_strip_model.h"
13 #include "chrome/test/base/in_process_browser_test.h" 14 #include "chrome/test/base/in_process_browser_test.h"
14 #include "chrome/test/base/ui_test_utils.h" 15 #include "chrome/test/base/ui_test_utils.h"
15 #include "content/public/browser/render_view_host.h" 16 #include "content/public/browser/render_view_host.h"
16 #include "content/public/browser/render_widget_host_iterator.h" 17 #include "content/public/browser/render_widget_host_iterator.h"
17 #include "content/public/browser/site_instance.h" 18 #include "content/public/browser/site_instance.h"
18 #include "content/public/browser/web_contents.h" 19 #include "content/public/browser/web_contents.h"
19 #include "content/public/test/browser_test_utils.h" 20 #include "content/public/test/browser_test_utils.h"
20 #include "ui/aura/client/aura_constants.h" 21 #include "ui/aura/client/aura_constants.h"
21 #include "ui/base/ime/input_method.h" 22 #include "ui/base/ime/input_method.h"
22 #include "ui/keyboard/keyboard_controller.h" 23 #include "ui/keyboard/keyboard_controller.h"
23 #include "ui/keyboard/keyboard_switches.h" 24 #include "ui/keyboard/keyboard_switches.h"
24 25
25 namespace { 26 namespace {
27 const base::FilePath::CharType kWebuiTestDir[] = FILE_PATH_LITERAL("webui");
26 28
27 const base::FilePath kWebuiTestDir = 29 const base::FilePath::CharType kMockController[] =
28 base::FilePath(FILE_PATH_LITERAL("webui")); 30 FILE_PATH_LITERAL("mock_controller.js");
29 31
30 const base::FilePath kVirtualKeyboardTestDir = 32 const base::FilePath::CharType kMockTimer[] =
31 base::FilePath(FILE_PATH_LITERAL("chromeos/virtual_keyboard")); 33 FILE_PATH_LITERAL("mock_timer.js");
32 34
33 const base::FilePath kMockController = 35 const std::string kVirtualKeyboardTestDir = "chromeos/virtual_keyboard";
34 base::FilePath(FILE_PATH_LITERAL("mock_controller.js"));
35 36
36 const base::FilePath kMockTimer = 37 const std::string kBaseKeyboardTestFramework = "virtual_keyboard_test_base.js";
37 base::FilePath(FILE_PATH_LITERAL("mock_timer.js"));
38 38
39 const base::FilePath kBaseKeyboardTestFramework = 39 const std::string kExtensionId = "mppnpdlheglhdfmldimlhpnegondlapf";
40 base::FilePath(FILE_PATH_LITERAL("virtual_keyboard_test_base.js")); 40
41 const std::string kVirtualKeyboardURL = "chrome://keyboard";
41 42
42 } // namespace 43 } // namespace
43 44
44 class VirtualKeyboardBrowserTest : public InProcessBrowserTest { 45 VirtualKeyboardBrowserTestHelper::VirtualKeyboardBrowserTestHelper()
Jeffrey Yasskin 2014/05/02 22:09:37 The header file should mention the default values,
rsadam 2014/05/05 17:44:42 Done.
45 public: 46 : base_framework_(kBaseKeyboardTestFramework),
47 extension_id_(kExtensionId),
48 test_dir_(kVirtualKeyboardTestDir),
49 url_(kVirtualKeyboardURL) {
50 }
46 51
47 // Ensure that the virtual keyboard is enabled. 52 VirtualKeyboardBrowserTestHelper::~VirtualKeyboardBrowserTestHelper() {};
48 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
49 command_line->AppendSwitch(
50 keyboard::switches::kEnableVirtualKeyboard);
51 }
52 53
53 // Injects javascript in |file| into the keyboard page and runs test methods. 54 void VirtualKeyboardBrowserTest::SetUpCommandLine(CommandLine* command_line) {
54 void RunTest(const base::FilePath& file) { 55 command_line->AppendSwitch(keyboard::switches::kEnableVirtualKeyboard);
55 ui_test_utils::NavigateToURL(browser(), GURL("chrome://keyboard")); 56 }
56 57
57 content::WebContents* web_contents = 58 void VirtualKeyboardBrowserTest::RunTest(
58 browser()->tab_strip_model()->GetActiveWebContents(); 59 const base::FilePath& file,
59 ASSERT_TRUE(web_contents); 60 const VirtualKeyboardBrowserTestHelper& helper) {
61 ui_test_utils::NavigateToURL(browser(), GURL(helper.url()));
62 content::WebContents* web_contents =
63 browser()->tab_strip_model()->GetActiveWebContents();
64 content::WaitForLoadStop(web_contents);
65 ASSERT_TRUE(web_contents);
60 66
61 // Inject testing scripts. 67 // Inject testing scripts.
62 InjectJavascript(kWebuiTestDir, kMockController); 68 InjectJavascript(base::FilePath(kWebuiTestDir),
63 InjectJavascript(kWebuiTestDir, kMockTimer); 69 base::FilePath(kMockController));
64 InjectJavascript(kVirtualKeyboardTestDir, kBaseKeyboardTestFramework); 70 InjectJavascript(base::FilePath(kWebuiTestDir), base::FilePath(kMockTimer));
65 InjectJavascript(kVirtualKeyboardTestDir, file); 71 InjectJavascript(base::FilePath(FILE_PATH_LITERAL(helper.test_dir())),
72 base::FilePath(FILE_PATH_LITERAL(helper.base_framework())));
73 InjectJavascript(base::FilePath(FILE_PATH_LITERAL(helper.test_dir())), file);
66 74
67 ASSERT_TRUE(content::ExecuteScript(web_contents, utf8_content_)); 75 ASSERT_TRUE(content::ExecuteScript(web_contents, utf8_content_));
68 76
69 // Inject DOM-automation test harness and run tests. 77 // Inject DOM-automation test harness and run tests.
70 std::vector<int> resource_ids; 78 std::vector<int> resource_ids;
71 EXPECT_TRUE(ExecuteWebUIResourceTest(web_contents, resource_ids)); 79 EXPECT_TRUE(ExecuteWebUIResourceTest(web_contents, resource_ids));
72 } 80 }
73 81
74 void showVirtualKeyboard() { 82 void VirtualKeyboardBrowserTest::ShowVirtualKeyboard() {
75 aura::Window *window = ash::Shell::GetPrimaryRootWindow(); 83 aura::Window* window = ash::Shell::GetPrimaryRootWindow();
76 ui::InputMethod* input_method = window->GetProperty( 84 ui::InputMethod* input_method =
77 aura::client::kRootWindowInputMethodKey); 85 window->GetProperty(aura::client::kRootWindowInputMethodKey);
78 ASSERT_TRUE(input_method); 86 ASSERT_TRUE(input_method);
79 input_method->ShowImeIfNeeded(); 87 input_method->ShowImeIfNeeded();
80 } 88 }
81 89
82 content::RenderViewHost* GetKeyboardRenderViewHost() { 90 content::RenderViewHost* VirtualKeyboardBrowserTest::GetKeyboardRenderViewHost(
83 showVirtualKeyboard(); 91 const std::string id) {
Jeffrey Yasskin 2014/05/02 22:09:37 Take std::strings as "const std::string&", unless
rsadam 2014/05/05 17:44:42 Done.
84 std::string kVirtualKeyboardURL = 92 ShowVirtualKeyboard();
85 "chrome-extension://mppnpdlheglhdfmldimlhpnegondlapf/"; 93 std::string url = "chrome-extension://" + id + "/";
Jeffrey Yasskin 2014/05/02 22:09:37 This should probably be "Extension::GetBaseURLFrom
rsadam 2014/05/05 17:44:42 Done.
86 scoped_ptr<content::RenderWidgetHostIterator> widgets( 94 scoped_ptr<content::RenderWidgetHostIterator> widgets(
87 content::RenderWidgetHost::GetRenderWidgetHosts()); 95 content::RenderWidgetHost::GetRenderWidgetHosts());
88 while (content::RenderWidgetHost* widget = widgets->GetNextHost()) { 96 while (content::RenderWidgetHost* widget = widgets->GetNextHost()) {
89 if (widget->IsRenderView()) { 97 if (widget->IsRenderView()) {
90 content::RenderViewHost* view = content::RenderViewHost::From(widget); 98 content::RenderViewHost* view = content::RenderViewHost::From(widget);
91 std::string url = view->GetSiteInstance()->GetSiteURL().spec(); 99 if (url == view->GetSiteInstance()->GetSiteURL().spec()) {
92 if (url == kVirtualKeyboardURL) { 100 content::WebContents* wc =
93 content::WebContents* wc = 101 content::WebContents::FromRenderViewHost(view);
94 content::WebContents::FromRenderViewHost(view); 102 // Waits for Polymer to load.
95 // Waits for Polymer to load. 103 content::WaitForLoadStop(wc);
96 content::WaitForLoadStop(wc); 104 return view;
97 return view;
98 }
99 } 105 }
100 } 106 }
101 return NULL;
102 } 107 }
108 LOG(ERROR) << "Extension not found:" << url;
109 return NULL;
110 }
103 111
104 private: 112 void VirtualKeyboardBrowserTest::InjectJavascript(const base::FilePath& dir,
105 113 const base::FilePath& file) {
106 // Injects javascript into the keyboard page. The test |file| is in 114 base::FilePath path = ui_test_utils::GetTestFilePath(dir, file);
107 // directory |dir| relative to the root testing directory. 115 std::string library_content;
108 void InjectJavascript(const base::FilePath& dir, 116 ASSERT_TRUE(base::ReadFileToString(path, &library_content)) << path.value();
109 const base::FilePath& file) { 117 utf8_content_.append(library_content);
110 base::FilePath path = ui_test_utils::GetTestFilePath(dir, file); 118 utf8_content_.append(";\n");
111 std::string library_content; 119 }
112 ASSERT_TRUE(base::ReadFileToString(path, &library_content))
113 << path.value();
114 utf8_content_.append(library_content);
115 utf8_content_.append(";\n");
116 }
117
118 std::string utf8_content_;
119 };
120 120
121 // crbug.com/367817. Either this feature or just the test are depending 121 // crbug.com/367817. Either this feature or just the test are depending
122 // on the presense of Object.observe which is presently disabled by default. 122 // on the presense of Object.observe which is presently disabled by default.
123 IN_PROC_BROWSER_TEST_F(VirtualKeyboardBrowserTest, DISABLED_AttributesTest) { 123 IN_PROC_BROWSER_TEST_F(VirtualKeyboardBrowserTest, DISABLED_AttributesTest) {
124 RunTest(base::FilePath(FILE_PATH_LITERAL("attributes_test.js"))); 124 RunTest(base::FilePath(FILE_PATH_LITERAL("attributes_test.js")),
125 VirtualKeyboardBrowserTestHelper());
125 } 126 }
126 127
127 IN_PROC_BROWSER_TEST_F(VirtualKeyboardBrowserTest, TypingTest) { 128 IN_PROC_BROWSER_TEST_F(VirtualKeyboardBrowserTest, TypingTest) {
128 RunTest(base::FilePath(FILE_PATH_LITERAL("typing_test.js"))); 129 RunTest(base::FilePath(FILE_PATH_LITERAL("typing_test.js")),
130 VirtualKeyboardBrowserTestHelper());
129 } 131 }
130 132
131 IN_PROC_BROWSER_TEST_F(VirtualKeyboardBrowserTest, ControlKeysTest) { 133 IN_PROC_BROWSER_TEST_F(VirtualKeyboardBrowserTest, ControlKeysTest) {
132 RunTest(base::FilePath(FILE_PATH_LITERAL("control_keys_test.js"))); 134 RunTest(base::FilePath(FILE_PATH_LITERAL("control_keys_test.js")),
135 VirtualKeyboardBrowserTestHelper());
133 } 136 }
134 137
135 IN_PROC_BROWSER_TEST_F(VirtualKeyboardBrowserTest, HideKeyboardKeyTest) { 138 IN_PROC_BROWSER_TEST_F(VirtualKeyboardBrowserTest, HideKeyboardKeyTest) {
136 RunTest(base::FilePath(FILE_PATH_LITERAL("hide_keyboard_key_test.js"))); 139 RunTest(base::FilePath(FILE_PATH_LITERAL("hide_keyboard_key_test.js")),
140 VirtualKeyboardBrowserTestHelper());
137 } 141 }
138 142
139 IN_PROC_BROWSER_TEST_F(VirtualKeyboardBrowserTest, KeysetTransitionTest) { 143 IN_PROC_BROWSER_TEST_F(VirtualKeyboardBrowserTest, KeysetTransitionTest) {
140 RunTest(base::FilePath(FILE_PATH_LITERAL("keyset_transition_test.js"))); 144 RunTest(base::FilePath(FILE_PATH_LITERAL("keyset_transition_test.js")),
145 VirtualKeyboardBrowserTestHelper());
141 } 146 }
142 147
143 IN_PROC_BROWSER_TEST_F(VirtualKeyboardBrowserTest, IsKeyboardLoaded) { 148 IN_PROC_BROWSER_TEST_F(VirtualKeyboardBrowserTest, IsKeyboardLoaded) {
144 content::RenderViewHost* keyboard_rvh = GetKeyboardRenderViewHost(); 149 content::RenderViewHost* keyboard_rvh =
150 GetKeyboardRenderViewHost(kExtensionId);
145 ASSERT_TRUE(keyboard_rvh); 151 ASSERT_TRUE(keyboard_rvh);
146 bool loaded = false; 152 bool loaded = false;
147 std::string script = "!!chrome.virtualKeyboardPrivate"; 153 std::string script = "!!chrome.virtualKeyboardPrivate";
148 EXPECT_TRUE(content::ExecuteScriptAndExtractBool( 154 EXPECT_TRUE(content::ExecuteScriptAndExtractBool(
149 keyboard_rvh, 155 keyboard_rvh,
150 "window.domAutomationController.send(" + script + ");", 156 "window.domAutomationController.send(" + script + ");",
151 &loaded)); 157 &loaded));
152 // Catches the regression in crbug.com/308653. 158 // Catches the regression in crbug.com/308653.
153 ASSERT_TRUE(loaded); 159 ASSERT_TRUE(loaded);
154 } 160 }
155 161
156 IN_PROC_BROWSER_TEST_F(VirtualKeyboardBrowserTest, EndToEndTest) { 162 IN_PROC_BROWSER_TEST_F(VirtualKeyboardBrowserTest, EndToEndTest) {
157 // Get the virtual keyboard's render view host. 163 // Get the virtual keyboard's render view host.
158 content::RenderViewHost* keyboard_rvh = GetKeyboardRenderViewHost(); 164 content::RenderViewHost* keyboard_rvh =
165 GetKeyboardRenderViewHost(kExtensionId);
159 ASSERT_TRUE(keyboard_rvh); 166 ASSERT_TRUE(keyboard_rvh);
160 167
161 // Get the test page's render view host. 168 // Get the test page's render view host.
162 content::RenderViewHost* browser_rvh = browser()->tab_strip_model()-> 169 content::RenderViewHost* browser_rvh = browser()->tab_strip_model()->
163 GetActiveWebContents()->GetRenderViewHost(); 170 GetActiveWebContents()->GetRenderViewHost();
164 ASSERT_TRUE(browser_rvh); 171 ASSERT_TRUE(browser_rvh);
165 172
166 // Set up the test page. 173 // Set up the test page.
167 GURL url = ui_test_utils::GetTestUrl( 174 GURL url = ui_test_utils::GetTestUrl(
168 base::FilePath(), 175 base::FilePath(),
169 base::FilePath(FILE_PATH_LITERAL( 176 base::FilePath(FILE_PATH_LITERAL(
170 "chromeos/virtual_keyboard/end_to_end_test.html"))); 177 "chromeos/virtual_keyboard/end_to_end_test.html")));
171 ui_test_utils::NavigateToURL(browser(), url); 178 ui_test_utils::NavigateToURL(browser(), url);
172 179
173 // Press 'a' on keyboard. 180 // Press 'a' on keyboard.
174 base::FilePath path = ui_test_utils::GetTestFilePath( 181 base::FilePath path = ui_test_utils::GetTestFilePath(
175 kVirtualKeyboardTestDir, 182 base::FilePath(FILE_PATH_LITERAL(kVirtualKeyboardTestDir)),
176 base::FilePath(FILE_PATH_LITERAL("end_to_end_test.js"))); 183 base::FilePath(FILE_PATH_LITERAL("end_to_end_test.js")));
177 std::string script; 184 std::string script;
178 ASSERT_TRUE(base::ReadFileToString(path, &script)); 185 ASSERT_TRUE(base::ReadFileToString(path, &script));
179 EXPECT_TRUE(content::ExecuteScript(keyboard_rvh, script)); 186 EXPECT_TRUE(content::ExecuteScript(keyboard_rvh, script));
180 // Verify 'a' appeared on test page. 187 // Verify 'a' appeared on test page.
181 bool success = false; 188 bool success = false;
182 EXPECT_TRUE(content::ExecuteScriptAndExtractBool( 189 EXPECT_TRUE(content::ExecuteScriptAndExtractBool(
183 browser_rvh, 190 browser_rvh,
184 "success ? verifyInput('a') : waitForInput('a');", 191 "success ? verifyInput('a') : waitForInput('a');",
185 &success)); 192 &success));
186 ASSERT_TRUE(success); 193 ASSERT_TRUE(success);
187 } 194 }
188 195
189 // TODO(kevers|rsadam|bshe): Add UI tests for remaining virtual keyboard 196 // TODO(kevers|rsadam|bshe): Add UI tests for remaining virtual keyboard
190 // functionality. 197 // functionality.
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698