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

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: 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"
21 #include "extensions/common/extension.h"
20 #include "ui/aura/client/aura_constants.h" 22 #include "ui/aura/client/aura_constants.h"
21 #include "ui/base/ime/input_method.h" 23 #include "ui/base/ime/input_method.h"
22 #include "ui/keyboard/keyboard_controller.h" 24 #include "ui/keyboard/keyboard_controller.h"
23 #include "ui/keyboard/keyboard_switches.h" 25 #include "ui/keyboard/keyboard_switches.h"
24 26
25 namespace { 27 namespace {
28 const base::FilePath::CharType kWebuiTestDir[] = FILE_PATH_LITERAL("webui");
26 29
27 const base::FilePath kWebuiTestDir = 30 const base::FilePath::CharType kMockController[] =
28 base::FilePath(FILE_PATH_LITERAL("webui")); 31 FILE_PATH_LITERAL("mock_controller.js");
29 32
30 const base::FilePath kVirtualKeyboardTestDir = 33 const base::FilePath::CharType kMockTimer[] =
31 base::FilePath(FILE_PATH_LITERAL("chromeos/virtual_keyboard")); 34 FILE_PATH_LITERAL("mock_timer.js");
32 35
33 const base::FilePath kMockController = 36 const char kVirtualKeyboardTestDir[] = "chromeos/virtual_keyboard";
34 base::FilePath(FILE_PATH_LITERAL("mock_controller.js"));
35 37
36 const base::FilePath kMockTimer = 38 const char kBaseKeyboardTestFramework[] = "virtual_keyboard_test_base.js";
37 base::FilePath(FILE_PATH_LITERAL("mock_timer.js"));
38 39
39 const base::FilePath kBaseKeyboardTestFramework = 40 const char kExtensionId[] = "mppnpdlheglhdfmldimlhpnegondlapf";
40 base::FilePath(FILE_PATH_LITERAL("virtual_keyboard_test_base.js")); 41
42 const char kVirtualKeyboardURL[] = "chrome://keyboard";
41 43
42 } // namespace 44 } // namespace
43 45
44 class VirtualKeyboardBrowserTest : public InProcessBrowserTest { 46 VirtualKeyboardBrowserTestConfig::VirtualKeyboardBrowserTestConfig()
45 public: 47 : base_framework_(kBaseKeyboardTestFramework),
48 extension_id_(kExtensionId),
49 test_dir_(kVirtualKeyboardTestDir),
50 url_(kVirtualKeyboardURL) {
51 }
46 52
47 // Ensure that the virtual keyboard is enabled. 53 VirtualKeyboardBrowserTestConfig::~VirtualKeyboardBrowserTestConfig() {};
48 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
49 command_line->AppendSwitch(
50 keyboard::switches::kEnableVirtualKeyboard);
51 }
52 54
53 // Injects javascript in |file| into the keyboard page and runs test methods. 55 void VirtualKeyboardBrowserTest::SetUpCommandLine(CommandLine* command_line) {
54 void RunTest(const base::FilePath& file) { 56 command_line->AppendSwitch(keyboard::switches::kEnableVirtualKeyboard);
55 ui_test_utils::NavigateToURL(browser(), GURL("chrome://keyboard")); 57 }
56 58
57 content::WebContents* web_contents = 59 void VirtualKeyboardBrowserTest::RunTest(
58 browser()->tab_strip_model()->GetActiveWebContents(); 60 const base::FilePath& file,
59 ASSERT_TRUE(web_contents); 61 const VirtualKeyboardBrowserTestConfig& config) {
62 ui_test_utils::NavigateToURL(browser(), GURL(config.url_));
63 content::WebContents* web_contents =
64 browser()->tab_strip_model()->GetActiveWebContents();
65 content::WaitForLoadStop(web_contents);
66 ASSERT_TRUE(web_contents);
60 67
61 // Inject testing scripts. 68 // Inject testing scripts.
62 InjectJavascript(kWebuiTestDir, kMockController); 69 InjectJavascript(base::FilePath(kWebuiTestDir),
63 InjectJavascript(kWebuiTestDir, kMockTimer); 70 base::FilePath(kMockController));
64 InjectJavascript(kVirtualKeyboardTestDir, kBaseKeyboardTestFramework); 71 InjectJavascript(base::FilePath(kWebuiTestDir), base::FilePath(kMockTimer));
65 InjectJavascript(kVirtualKeyboardTestDir, file); 72 InjectJavascript(base::FilePath(FILE_PATH_LITERAL(config.test_dir_)),
73 base::FilePath(FILE_PATH_LITERAL(config.base_framework_)));
74 InjectJavascript(base::FilePath(FILE_PATH_LITERAL(config.test_dir_)), file);
66 75
67 ASSERT_TRUE(content::ExecuteScript(web_contents, utf8_content_)); 76 ASSERT_TRUE(content::ExecuteScript(web_contents, utf8_content_));
68 77
69 // Inject DOM-automation test harness and run tests. 78 // Inject DOM-automation test harness and run tests.
70 std::vector<int> resource_ids; 79 std::vector<int> resource_ids;
71 EXPECT_TRUE(ExecuteWebUIResourceTest(web_contents, resource_ids)); 80 EXPECT_TRUE(ExecuteWebUIResourceTest(web_contents, resource_ids));
72 } 81 }
73 82
74 void showVirtualKeyboard() { 83 void VirtualKeyboardBrowserTest::ShowVirtualKeyboard() {
75 aura::Window *window = ash::Shell::GetPrimaryRootWindow(); 84 aura::Window* window = ash::Shell::GetPrimaryRootWindow();
76 ui::InputMethod* input_method = window->GetProperty( 85 ui::InputMethod* input_method =
77 aura::client::kRootWindowInputMethodKey); 86 window->GetProperty(aura::client::kRootWindowInputMethodKey);
78 ASSERT_TRUE(input_method); 87 ASSERT_TRUE(input_method);
79 input_method->ShowImeIfNeeded(); 88 input_method->ShowImeIfNeeded();
80 } 89 }
81 90
82 content::RenderViewHost* GetKeyboardRenderViewHost() { 91 content::RenderViewHost* VirtualKeyboardBrowserTest::GetKeyboardRenderViewHost(
83 showVirtualKeyboard(); 92 const std::string& id) {
84 std::string kVirtualKeyboardURL = 93 ShowVirtualKeyboard();
85 "chrome-extension://mppnpdlheglhdfmldimlhpnegondlapf/"; 94 GURL url = extensions::Extension::GetBaseURLFromExtensionId(id);
86 scoped_ptr<content::RenderWidgetHostIterator> widgets( 95 scoped_ptr<content::RenderWidgetHostIterator> widgets(
87 content::RenderWidgetHost::GetRenderWidgetHosts()); 96 content::RenderWidgetHost::GetRenderWidgetHosts());
88 while (content::RenderWidgetHost* widget = widgets->GetNextHost()) { 97 while (content::RenderWidgetHost* widget = widgets->GetNextHost()) {
89 if (widget->IsRenderView()) { 98 if (widget->IsRenderView()) {
90 content::RenderViewHost* view = content::RenderViewHost::From(widget); 99 content::RenderViewHost* view = content::RenderViewHost::From(widget);
91 std::string url = view->GetSiteInstance()->GetSiteURL().spec(); 100 if (url == view->GetSiteInstance()->GetSiteURL()) {
92 if (url == kVirtualKeyboardURL) { 101 content::WebContents* wc =
93 content::WebContents* wc = 102 content::WebContents::FromRenderViewHost(view);
94 content::WebContents::FromRenderViewHost(view); 103 // Waits for Polymer to load.
95 // Waits for Polymer to load. 104 content::WaitForLoadStop(wc);
96 content::WaitForLoadStop(wc); 105 return view;
97 return view;
98 }
99 } 106 }
100 } 107 }
101 return NULL;
102 } 108 }
109 LOG(ERROR) << "Extension not found:" << url;
110 return NULL;
111 }
103 112
104 private: 113 void VirtualKeyboardBrowserTest::InjectJavascript(const base::FilePath& dir,
105 114 const base::FilePath& file) {
106 // Injects javascript into the keyboard page. The test |file| is in 115 base::FilePath path = ui_test_utils::GetTestFilePath(dir, file);
107 // directory |dir| relative to the root testing directory. 116 std::string library_content;
108 void InjectJavascript(const base::FilePath& dir, 117 ASSERT_TRUE(base::ReadFileToString(path, &library_content)) << path.value();
109 const base::FilePath& file) { 118 utf8_content_.append(library_content);
110 base::FilePath path = ui_test_utils::GetTestFilePath(dir, file); 119 utf8_content_.append(";\n");
111 std::string library_content; 120 }
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 121
121 // crbug.com/367817. Either this feature or just the test are depending 122 // 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. 123 // on the presense of Object.observe which is presently disabled by default.
123 IN_PROC_BROWSER_TEST_F(VirtualKeyboardBrowserTest, DISABLED_AttributesTest) { 124 IN_PROC_BROWSER_TEST_F(VirtualKeyboardBrowserTest, DISABLED_AttributesTest) {
124 RunTest(base::FilePath(FILE_PATH_LITERAL("attributes_test.js"))); 125 RunTest(base::FilePath(FILE_PATH_LITERAL("attributes_test.js")),
126 VirtualKeyboardBrowserTestConfig());
125 } 127 }
126 128
127 IN_PROC_BROWSER_TEST_F(VirtualKeyboardBrowserTest, TypingTest) { 129 IN_PROC_BROWSER_TEST_F(VirtualKeyboardBrowserTest, TypingTest) {
128 RunTest(base::FilePath(FILE_PATH_LITERAL("typing_test.js"))); 130 RunTest(base::FilePath(FILE_PATH_LITERAL("typing_test.js")),
131 VirtualKeyboardBrowserTestConfig());
129 } 132 }
130 133
131 IN_PROC_BROWSER_TEST_F(VirtualKeyboardBrowserTest, ControlKeysTest) { 134 IN_PROC_BROWSER_TEST_F(VirtualKeyboardBrowserTest, ControlKeysTest) {
132 RunTest(base::FilePath(FILE_PATH_LITERAL("control_keys_test.js"))); 135 RunTest(base::FilePath(FILE_PATH_LITERAL("control_keys_test.js")),
136 VirtualKeyboardBrowserTestConfig());
133 } 137 }
134 138
135 IN_PROC_BROWSER_TEST_F(VirtualKeyboardBrowserTest, HideKeyboardKeyTest) { 139 IN_PROC_BROWSER_TEST_F(VirtualKeyboardBrowserTest, HideKeyboardKeyTest) {
136 RunTest(base::FilePath(FILE_PATH_LITERAL("hide_keyboard_key_test.js"))); 140 RunTest(base::FilePath(FILE_PATH_LITERAL("hide_keyboard_key_test.js")),
141 VirtualKeyboardBrowserTestConfig());
137 } 142 }
138 143
139 IN_PROC_BROWSER_TEST_F(VirtualKeyboardBrowserTest, KeysetTransitionTest) { 144 IN_PROC_BROWSER_TEST_F(VirtualKeyboardBrowserTest, KeysetTransitionTest) {
140 RunTest(base::FilePath(FILE_PATH_LITERAL("keyset_transition_test.js"))); 145 RunTest(base::FilePath(FILE_PATH_LITERAL("keyset_transition_test.js")),
146 VirtualKeyboardBrowserTestConfig());
141 } 147 }
142 148
143 // Fails when enabling Object.observe. See http://crbug.com/370004 149 // Fails when enabling Object.observe. See http://crbug.com/370004
144 #if defined(OS_CHROMEOS) 150 #if defined(OS_CHROMEOS)
145 #define MAYBE_IsKeyboardLoaded DISABLED_IsKeyboardLoaded 151 #define MAYBE_IsKeyboardLoaded DISABLED_IsKeyboardLoaded
146 #else 152 #else
147 #define MAYBE_IsKeyboardLoaded IsKeyboardLoaded 153 #define MAYBE_IsKeyboardLoaded IsKeyboardLoaded
148 #endif 154 #endif
149 IN_PROC_BROWSER_TEST_F(VirtualKeyboardBrowserTest, MAYBE_IsKeyboardLoaded) { 155 IN_PROC_BROWSER_TEST_F(VirtualKeyboardBrowserTest, MAYBE_IsKeyboardLoaded) {
150 content::RenderViewHost* keyboard_rvh = GetKeyboardRenderViewHost(); 156 content::RenderViewHost* keyboard_rvh =
157 GetKeyboardRenderViewHost(kExtensionId);
151 ASSERT_TRUE(keyboard_rvh); 158 ASSERT_TRUE(keyboard_rvh);
152 bool loaded = false; 159 bool loaded = false;
153 std::string script = "!!chrome.virtualKeyboardPrivate"; 160 std::string script = "!!chrome.virtualKeyboardPrivate";
154 EXPECT_TRUE(content::ExecuteScriptAndExtractBool( 161 EXPECT_TRUE(content::ExecuteScriptAndExtractBool(
155 keyboard_rvh, 162 keyboard_rvh,
156 "window.domAutomationController.send(" + script + ");", 163 "window.domAutomationController.send(" + script + ");",
157 &loaded)); 164 &loaded));
158 // Catches the regression in crbug.com/308653. 165 // Catches the regression in crbug.com/308653.
159 ASSERT_TRUE(loaded); 166 ASSERT_TRUE(loaded);
160 } 167 }
161 168
162 IN_PROC_BROWSER_TEST_F(VirtualKeyboardBrowserTest, DISABLED_EndToEndTest) { 169 IN_PROC_BROWSER_TEST_F(VirtualKeyboardBrowserTest, DISABLED_EndToEndTest) {
163 // Get the virtual keyboard's render view host. 170 // Get the virtual keyboard's render view host.
164 content::RenderViewHost* keyboard_rvh = GetKeyboardRenderViewHost(); 171 content::RenderViewHost* keyboard_rvh =
172 GetKeyboardRenderViewHost(kExtensionId);
165 ASSERT_TRUE(keyboard_rvh); 173 ASSERT_TRUE(keyboard_rvh);
166 174
167 // Get the test page's render view host. 175 // Get the test page's render view host.
168 content::RenderViewHost* browser_rvh = browser()->tab_strip_model()-> 176 content::RenderViewHost* browser_rvh = browser()->tab_strip_model()->
169 GetActiveWebContents()->GetRenderViewHost(); 177 GetActiveWebContents()->GetRenderViewHost();
170 ASSERT_TRUE(browser_rvh); 178 ASSERT_TRUE(browser_rvh);
171 179
172 // Set up the test page. 180 // Set up the test page.
173 GURL url = ui_test_utils::GetTestUrl( 181 GURL url = ui_test_utils::GetTestUrl(
174 base::FilePath(), 182 base::FilePath(),
175 base::FilePath(FILE_PATH_LITERAL( 183 base::FilePath(FILE_PATH_LITERAL(
176 "chromeos/virtual_keyboard/end_to_end_test.html"))); 184 "chromeos/virtual_keyboard/end_to_end_test.html")));
177 ui_test_utils::NavigateToURL(browser(), url); 185 ui_test_utils::NavigateToURL(browser(), url);
178 186
179 // Press 'a' on keyboard. 187 // Press 'a' on keyboard.
180 base::FilePath path = ui_test_utils::GetTestFilePath( 188 base::FilePath path = ui_test_utils::GetTestFilePath(
181 kVirtualKeyboardTestDir, 189 base::FilePath(FILE_PATH_LITERAL(kVirtualKeyboardTestDir)),
182 base::FilePath(FILE_PATH_LITERAL("end_to_end_test.js"))); 190 base::FilePath(FILE_PATH_LITERAL("end_to_end_test.js")));
183 std::string script; 191 std::string script;
184 ASSERT_TRUE(base::ReadFileToString(path, &script)); 192 ASSERT_TRUE(base::ReadFileToString(path, &script));
185 EXPECT_TRUE(content::ExecuteScript(keyboard_rvh, script)); 193 EXPECT_TRUE(content::ExecuteScript(keyboard_rvh, script));
186 // Verify 'a' appeared on test page. 194 // Verify 'a' appeared on test page.
187 bool success = false; 195 bool success = false;
188 EXPECT_TRUE(content::ExecuteScriptAndExtractBool( 196 EXPECT_TRUE(content::ExecuteScriptAndExtractBool(
189 browser_rvh, 197 browser_rvh,
190 "success ? verifyInput('a') : waitForInput('a');", 198 "success ? verifyInput('a') : waitForInput('a');",
191 &success)); 199 &success));
192 ASSERT_TRUE(success); 200 ASSERT_TRUE(success);
193 } 201 }
194 202
195 // TODO(kevers|rsadam|bshe): Add UI tests for remaining virtual keyboard 203 // TODO(kevers|rsadam|bshe): Add UI tests for remaining virtual keyboard
196 // functionality. 204 // functionality.
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/extensions/virtual_keyboard_browsertest.h ('k') | chrome/chrome_tests.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698