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

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

Issue 2451143003: <webview>: Correctly shift focus between WebContents. (Closed)
Patch Set: Add fix for MacOS hang. Created 4 years, 1 month 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"
(...skipping 1346 matching lines...) Expand 10 before | Expand all | Expand 10 after
1357 for (size_t i = 0; i < 4; ++i) 1357 for (size_t i = 0; i < 4; ++i)
1358 SendKeyPressToPlatformApp(ui::VKEY_TAB); 1358 SendKeyPressToPlatformApp(ui::VKEY_TAB);
1359 ExtensionTestMessageListener webview_button_not_focused_listener( 1359 ExtensionTestMessageListener webview_button_not_focused_listener(
1360 "WebViewInteractiveTest.WebViewButtonWasNotFocused", false); 1360 "WebViewInteractiveTest.WebViewButtonWasNotFocused", false);
1361 webview_button_not_focused_listener.set_failure_message( 1361 webview_button_not_focused_listener.set_failure_message(
1362 "WebViewInteractiveTest.WebViewButtonWasFocused"); 1362 "WebViewInteractiveTest.WebViewButtonWasFocused");
1363 SendMessageToEmbedder("verify"); 1363 SendMessageToEmbedder("verify");
1364 EXPECT_TRUE(webview_button_not_focused_listener.WaitUntilSatisfied()); 1364 EXPECT_TRUE(webview_button_not_focused_listener.WaitUntilSatisfied());
1365 } 1365 }
1366 1366
1367 IN_PROC_BROWSER_TEST_P(WebViewInteractiveTest, KeyboardFocus) { 1367 IN_PROC_BROWSER_TEST_P(WebViewInteractiveTest, KeyboardFocusSimple) {
1368 TestHelper("testKeyboardFocus", "web_view/focus", NO_TEST_SERVER); 1368 TestHelper("testKeyboardFocusSimple", "web_view/focus", NO_TEST_SERVER);
1369 1369
1370 EXPECT_EQ(embedder_web_contents()->GetFocusedFrame(), 1370 EXPECT_EQ(embedder_web_contents()->GetFocusedFrame(),
1371 embedder_web_contents()->GetMainFrame()); 1371 embedder_web_contents()->GetMainFrame());
1372 content::FrameFocusedObserver focus_observer(
1373 guest_web_contents()->GetMainFrame());
1374 ExtensionTestMessageListener next_step_listener("TEST_STEP_PASSED", false); 1372 ExtensionTestMessageListener next_step_listener("TEST_STEP_PASSED", false);
1375 next_step_listener.set_failure_message("TEST_STEP_FAILED"); 1373 next_step_listener.set_failure_message("TEST_STEP_FAILED");
1376 { 1374 {
1377 gfx::Rect offset = embedder_web_contents()->GetContainerBounds(); 1375 gfx::Rect offset = embedder_web_contents()->GetContainerBounds();
1378 // Click the <input> element inside the <webview>. 1376 // Click the <input> element inside the <webview>.
1379 // If we wanted, we could ask the embedder to compute an appropriate point. 1377 // If we wanted, we could ask the embedder to compute an appropriate point.
1380 MoveMouseInsideWindow(gfx::Point(offset.x() + 40, offset.y() + 40)); 1378 MoveMouseInsideWindow(gfx::Point(offset.x() + 40, offset.y() + 40));
1381 SendMouseClick(ui_controls::LEFT); 1379 SendMouseClick(ui_controls::LEFT);
1382 } 1380 }
1383 1381
1384 // Waits for the renderer to know the input has focus. 1382 // Waits for the renderer to know the input has focus.
1385 ASSERT_TRUE(next_step_listener.WaitUntilSatisfied()); 1383 ASSERT_TRUE(next_step_listener.WaitUntilSatisfied());
1386 // Wait for the browser to know which frame has focus.
1387 focus_observer.Wait();
1388 if (GetParam())
1389 EXPECT_EQ(embedder_web_contents()->GetFocusedFrame(), nullptr);
1390 1384
1391 ASSERT_TRUE(ui_test_utils::SendKeyPressToWindowSync( 1385 ASSERT_TRUE(ui_test_utils::SendKeyPressToWindowSync(
1392 GetPlatformAppWindow(), ui::VKEY_A, false, false, false, false)); 1386 GetPlatformAppWindow(), ui::VKEY_A, false, false, false, false));
1393 ASSERT_TRUE(ui_test_utils::SendKeyPressToWindowSync( 1387 ASSERT_TRUE(ui_test_utils::SendKeyPressToWindowSync(
1394 GetPlatformAppWindow(), ui::VKEY_B, false, true, false, false)); 1388 GetPlatformAppWindow(), ui::VKEY_B, false, true, false, false));
1395 ASSERT_TRUE(ui_test_utils::SendKeyPressToWindowSync( 1389 ASSERT_TRUE(ui_test_utils::SendKeyPressToWindowSync(
1396 GetPlatformAppWindow(), ui::VKEY_C, false, false, false, false)); 1390 GetPlatformAppWindow(), ui::VKEY_C, false, false, false, false));
1397 1391
1398 next_step_listener.Reset(); 1392 next_step_listener.Reset();
1399 EXPECT_TRUE(content::ExecuteScript( 1393 EXPECT_TRUE(content::ExecuteScript(
1400 embedder_web_contents(), 1394 embedder_web_contents(),
1401 "window.runCommand('testKeyboardFocusRunNextStep', 'aBc');")); 1395 "window.runCommand('testKeyboardFocusRunNextStep', 'aBc');"));
1402 1396
1403 ASSERT_TRUE(next_step_listener.WaitUntilSatisfied()); 1397 ASSERT_TRUE(next_step_listener.WaitUntilSatisfied());
1404 } 1398 }
1399
1400 // Ensures that input is not routed to the webview when the container is blurred
1401 // and restored on focus
Charlie Reis 2016/11/16 20:28:23 nit: End with period.
avallee 2016/11/16 21:18:10 Done.
1402 IN_PROC_BROWSER_TEST_P(WebViewInteractiveTest, KeyboardFocusWindowCycle) {
1403 TestHelper("testKeyboardFocusWindowFocusCycle", "web_view/focus",
1404 NO_TEST_SERVER);
1405
1406 EXPECT_EQ(embedder_web_contents()->GetFocusedFrame(),
1407 embedder_web_contents()->GetMainFrame());
1408 ExtensionTestMessageListener next_step_listener("TEST_STEP_PASSED", false);
1409 next_step_listener.set_failure_message("TEST_STEP_FAILED");
1410 {
1411 gfx::Rect offset = embedder_web_contents()->GetContainerBounds();
1412 // Click the <input> element inside the <webview>.
1413 // If we wanted, we could ask the embedder to compute an appropriate point.
1414 MoveMouseInsideWindow(gfx::Point(offset.x() + 40, offset.y() + 40));
1415 SendMouseClick(ui_controls::LEFT);
1416 }
1417
1418 // Waits for the renderer to know the input has focus.
1419 ASSERT_TRUE(next_step_listener.WaitUntilSatisfied());
1420
1421 ASSERT_TRUE(ui_test_utils::SendKeyPressToWindowSync(
1422 GetPlatformAppWindow(), ui::VKEY_A, false, false, false, false));
1423 ASSERT_TRUE(ui_test_utils::SendKeyPressToWindowSync(
1424 GetPlatformAppWindow(), ui::VKEY_B, false, true, false, false));
1425 ASSERT_TRUE(ui_test_utils::SendKeyPressToWindowSync(
1426 GetPlatformAppWindow(), ui::VKEY_C, false, false, false, false));
1427
1428 const extensions::Extension* extension =
1429 LoadAndLaunchPlatformApp("minimal", "Launched");
1430 extensions::AppWindow* window = GetFirstAppWindowForApp(extension->id());
1431 EXPECT_TRUE(content::ExecuteScript(
1432 embedder_web_contents(),
1433 "window.runCommand('monitorGuestEvent', 'focus');"));
1434
1435 ASSERT_TRUE(ui_test_utils::SendKeyPressToWindowSync(
1436 GetPlatformAppWindow(), ui::VKEY_F, false, false, false, false));
1437 ASSERT_TRUE(ui_test_utils::SendKeyPressToWindowSync(
1438 GetPlatformAppWindow(), ui::VKEY_O, false, true, false, false));
1439 ASSERT_TRUE(ui_test_utils::SendKeyPressToWindowSync(
1440 GetPlatformAppWindow(), ui::VKEY_O, false, true, false, false));
1441
1442 // Close the other window and wait for the webview to regain focus.
1443 CloseAppWindow(window);
1444 #if defined(OS_MACOSX)
1445 ASSERT_TRUE(ui_test_utils::ShowAndFocusNativeWindow(GetPlatformAppWindow()));
1446 #endif
1447 next_step_listener.Reset();
1448 EXPECT_TRUE(
1449 content::ExecuteScript(embedder_web_contents(),
1450 "window.runCommand('waitGuestEvent', 'focus');"));
1451 ASSERT_TRUE(next_step_listener.WaitUntilSatisfied());
1452
1453 ASSERT_TRUE(ui_test_utils::SendKeyPressToWindowSync(
1454 GetPlatformAppWindow(), ui::VKEY_X, false, false, false, false));
1455 ASSERT_TRUE(ui_test_utils::SendKeyPressToWindowSync(
1456 GetPlatformAppWindow(), ui::VKEY_Y, false, true, false, false));
1457 ASSERT_TRUE(ui_test_utils::SendKeyPressToWindowSync(
1458 GetPlatformAppWindow(), ui::VKEY_Z, false, false, false, false));
1459
1460 next_step_listener.Reset();
1461 EXPECT_TRUE(content::ExecuteScript(
1462 embedder_web_contents(),
1463 "window.runCommand('testKeyboardFocusRunNextStep', 'aBcxYz');"));
1464
1465 ASSERT_TRUE(next_step_listener.WaitUntilSatisfied());
1466 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698