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

Side by Side Diff: chrome/browser/apps/guest_view/web_view_interactive_browsertest.cc

Issue 1934703002: Fix keyboard focus for OOPIF-<webview>. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address nasko@ comments. Created 4 years, 4 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 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <stddef.h> 5 #include <stddef.h>
6 6
7 #include "base/location.h" 7 #include "base/location.h"
8 #include "base/macros.h" 8 #include "base/macros.h"
9 #include "base/single_thread_task_runner.h" 9 #include "base/single_thread_task_runner.h"
10 #include "base/strings/stringprintf.h" 10 #include "base/strings/stringprintf.h"
11 #include "base/strings/utf_string_conversions.h" 11 #include "base/strings/utf_string_conversions.h"
12 #include "base/threading/thread_task_runner_handle.h" 12 #include "base/threading/thread_task_runner_handle.h"
13 #include "build/build_config.h" 13 #include "build/build_config.h"
14 #include "chrome/app/chrome_command_ids.h" 14 #include "chrome/app/chrome_command_ids.h"
15 #include "chrome/browser/apps/app_browsertest_util.h" 15 #include "chrome/browser/apps/app_browsertest_util.h"
16 #include "chrome/browser/chrome_content_browser_client.h" 16 #include "chrome/browser/chrome_content_browser_client.h"
17 #include "chrome/browser/profiles/profile.h" 17 #include "chrome/browser/profiles/profile.h"
18 #include "chrome/browser/renderer_context_menu/render_view_context_menu_browsert est_util.h" 18 #include "chrome/browser/renderer_context_menu/render_view_context_menu_browsert est_util.h"
19 #include "chrome/browser/renderer_context_menu/render_view_context_menu_test_uti l.h" 19 #include "chrome/browser/renderer_context_menu/render_view_context_menu_test_uti l.h"
20 #include "chrome/test/base/interactive_test_utils.h" 20 #include "chrome/test/base/interactive_test_utils.h"
21 #include "chrome/test/base/test_launcher_utils.h" 21 #include "chrome/test/base/test_launcher_utils.h"
22 #include "chrome/test/base/ui_test_utils.h" 22 #include "chrome/test/base/ui_test_utils.h"
23 #include "components/guest_view/browser/guest_view_base.h" 23 #include "components/guest_view/browser/guest_view_base.h"
24 #include "components/guest_view/browser/guest_view_manager.h" 24 #include "components/guest_view/browser/guest_view_manager.h"
25 #include "components/guest_view/browser/guest_view_manager_delegate.h" 25 #include "components/guest_view/browser/guest_view_manager_delegate.h"
26 #include "components/guest_view/browser/guest_view_manager_factory.h" 26 #include "components/guest_view/browser/guest_view_manager_factory.h"
27 #include "components/guest_view/browser/test_guest_view_manager.h" 27 #include "components/guest_view/browser/test_guest_view_manager.h"
28 #include "content/public/browser/notification_service.h" 28 #include "content/public/browser/notification_service.h"
29 #include "content/public/browser/render_frame_host.h"
29 #include "content/public/browser/render_process_host.h" 30 #include "content/public/browser/render_process_host.h"
30 #include "content/public/browser/render_view_host.h" 31 #include "content/public/browser/render_view_host.h"
31 #include "content/public/browser/render_widget_host.h" 32 #include "content/public/browser/render_widget_host.h"
32 #include "content/public/browser/render_widget_host_iterator.h" 33 #include "content/public/browser/render_widget_host_iterator.h"
33 #include "content/public/browser/render_widget_host_view.h" 34 #include "content/public/browser/render_widget_host_view.h"
34 #include "content/public/browser/web_contents.h" 35 #include "content/public/browser/web_contents.h"
35 #include "content/public/common/content_switches.h" 36 #include "content/public/common/content_switches.h"
36 #include "content/public/test/browser_test_utils.h" 37 #include "content/public/test/browser_test_utils.h"
37 #include "extensions/browser/api/extensions_api_client.h" 38 #include "extensions/browser/api/extensions_api_client.h"
38 #include "extensions/browser/app_window/app_window.h" 39 #include "extensions/browser/app_window/app_window.h"
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
220 void TestHelper(const std::string& test_name, 221 void TestHelper(const std::string& test_name,
221 const std::string& app_location, 222 const std::string& app_location,
222 TestServer test_server) { 223 TestServer test_server) {
223 content::WebContents* embedder_web_contents = NULL; 224 content::WebContents* embedder_web_contents = NULL;
224 std::unique_ptr<ExtensionTestMessageListener> done_listener(RunAppHelper( 225 std::unique_ptr<ExtensionTestMessageListener> done_listener(RunAppHelper(
225 test_name, app_location, test_server, &embedder_web_contents)); 226 test_name, app_location, test_server, &embedder_web_contents));
226 227
227 ASSERT_TRUE(done_listener); 228 ASSERT_TRUE(done_listener);
228 ASSERT_TRUE(done_listener->WaitUntilSatisfied()); 229 ASSERT_TRUE(done_listener->WaitUntilSatisfied());
229 230
231 embedder_web_contents_ = embedder_web_contents;
230 guest_web_contents_ = GetGuestViewManager()->WaitForSingleGuestCreated(); 232 guest_web_contents_ = GetGuestViewManager()->WaitForSingleGuestCreated();
231 } 233 }
232 234
233 void SendMessageToEmbedder(const std::string& message) { 235 void SendMessageToEmbedder(const std::string& message) {
234 ASSERT_TRUE(content::ExecuteScript( 236 ASSERT_TRUE(content::ExecuteScript(
235 GetFirstAppWindowWebContents(), 237 GetFirstAppWindowWebContents(),
236 base::StringPrintf("onAppMessage('%s');", message.c_str()))); 238 base::StringPrintf("onAppMessage('%s');", message.c_str())));
237 } 239 }
238 240
239 void SetupTest(const std::string& app_name, 241 void SetupTest(const std::string& app_name,
(...skipping 1106 matching lines...) Expand 10 before | Expand all | Expand 10 after
1346 // this time. 1348 // this time.
1347 for (size_t i = 0; i < 4; ++i) 1349 for (size_t i = 0; i < 4; ++i)
1348 SendKeyPressToPlatformApp(ui::VKEY_TAB); 1350 SendKeyPressToPlatformApp(ui::VKEY_TAB);
1349 ExtensionTestMessageListener webview_button_not_focused_listener( 1351 ExtensionTestMessageListener webview_button_not_focused_listener(
1350 "WebViewInteractiveTest.WebViewButtonWasNotFocused", false); 1352 "WebViewInteractiveTest.WebViewButtonWasNotFocused", false);
1351 webview_button_not_focused_listener.set_failure_message( 1353 webview_button_not_focused_listener.set_failure_message(
1352 "WebViewInteractiveTest.WebViewButtonWasFocused"); 1354 "WebViewInteractiveTest.WebViewButtonWasFocused");
1353 SendMessageToEmbedder("verify"); 1355 SendMessageToEmbedder("verify");
1354 EXPECT_TRUE(webview_button_not_focused_listener.WaitUntilSatisfied()); 1356 EXPECT_TRUE(webview_button_not_focused_listener.WaitUntilSatisfied());
1355 } 1357 }
1358
1359 IN_PROC_BROWSER_TEST_P(WebViewInteractiveTest, KeyboardFocus) {
1360 TestHelper("testKeyboardFocus", "web_view/focus", NO_TEST_SERVER);
1361
1362 EXPECT_EQ(embedder_web_contents()->GetFocusedFrame(),
1363 embedder_web_contents()->GetMainFrame());
1364 content::FrameFocusedObserver focus_observer(
1365 guest_web_contents()->GetMainFrame());
1366 ExtensionTestMessageListener next_step_listener("TEST_STEP_PASSED", false);
1367 next_step_listener.set_failure_message("TEST_STEP_FAILED");
1368 {
1369 gfx::Rect offset = embedder_web_contents()->GetContainerBounds();
1370 // Click the <input> element inside the <webview>.
1371 // If we wanted, we could ask the embedder to compute an appropriate point.
1372 MoveMouseInsideWindow(gfx::Point(offset.x() + 40, offset.y() + 40));
1373 SendMouseClick(ui_controls::LEFT);
1374 }
1375
1376 // Waits for the renderer to know the input has focus.
1377 ASSERT_TRUE(next_step_listener.WaitUntilSatisfied());
1378 // Wait for the browser to know which frame has focus.
1379 focus_observer.Wait();
1380 if (GetParam())
1381 EXPECT_EQ(embedder_web_contents()->GetFocusedFrame(), nullptr);
1382
1383 ASSERT_TRUE(ui_test_utils::SendKeyPressToWindowSync(
1384 GetPlatformAppWindow(), ui::VKEY_A, false, false, false, false));
1385 ASSERT_TRUE(ui_test_utils::SendKeyPressToWindowSync(
1386 GetPlatformAppWindow(), ui::VKEY_B, false, true, false, false));
1387 ASSERT_TRUE(ui_test_utils::SendKeyPressToWindowSync(
1388 GetPlatformAppWindow(), ui::VKEY_C, false, false, false, false));
1389
1390 next_step_listener.Reset();
1391 EXPECT_TRUE(content::ExecuteScript(
1392 embedder_web_contents(),
1393 "window.runCommand('testKeyboardFocusRunNextStep', 'aBc');"));
1394
1395 ASSERT_TRUE(next_step_listener.WaitUntilSatisfied());
1396 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698