| OLD | NEW |
| 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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 #include "ui/base/test/ui_controls.h" | 44 #include "ui/base/test/ui_controls.h" |
| 45 #include "ui/events/keycodes/keyboard_codes.h" | 45 #include "ui/events/keycodes/keyboard_codes.h" |
| 46 | 46 |
| 47 using extensions::AppWindow; | 47 using extensions::AppWindow; |
| 48 using extensions::ExtensionsAPIClient; | 48 using extensions::ExtensionsAPIClient; |
| 49 using guest_view::GuestViewBase; | 49 using guest_view::GuestViewBase; |
| 50 using guest_view::GuestViewManager; | 50 using guest_view::GuestViewManager; |
| 51 using guest_view::TestGuestViewManager; | 51 using guest_view::TestGuestViewManager; |
| 52 using guest_view::TestGuestViewManagerFactory; | 52 using guest_view::TestGuestViewManagerFactory; |
| 53 | 53 |
| 54 namespace { | |
| 55 // A helper class which polls the text input state of the given WebContents. | |
| 56 class TextInputStateHelper { | |
| 57 public: | |
| 58 using Predicate = | |
| 59 base::Callback<bool(const content::TextInputStateTestExport&)>; | |
| 60 | |
| 61 static void WaitForDesiredState(content::WebContents* web_contents, | |
| 62 const Predicate& predicate) { | |
| 63 content::TextInputStateTestExport state = | |
| 64 content::TextInputStateTestExport::FromWebContents(web_contents); | |
| 65 while (!predicate.Run(state)) { | |
| 66 scoped_refptr<content::MessageLoopRunner> loop = | |
| 67 new content::MessageLoopRunner(); | |
| 68 content::BrowserThread::PostDelayedTask( | |
| 69 content::BrowserThread::UI, FROM_HERE, loop->QuitClosure(), | |
| 70 base::TimeDelta::FromMilliseconds(100LL)); | |
| 71 loop->Run(); | |
| 72 state = content::TextInputStateTestExport::FromWebContents(web_contents); | |
| 73 } | |
| 74 } | |
| 75 | |
| 76 static bool IsStateOfGivenType( | |
| 77 ui::TextInputType type, | |
| 78 const content::TextInputStateTestExport& state) { | |
| 79 return type == state.type(); | |
| 80 } | |
| 81 | |
| 82 static bool HasGivenValue(const std::string& value, | |
| 83 const content::TextInputStateTestExport& state) { | |
| 84 return value == state.value(); | |
| 85 } | |
| 86 }; | |
| 87 | |
| 88 } // namespace | |
| 89 | |
| 90 class WebViewInteractiveTestBase : public extensions::PlatformAppBrowserTest { | 54 class WebViewInteractiveTestBase : public extensions::PlatformAppBrowserTest { |
| 91 public: | 55 public: |
| 92 WebViewInteractiveTestBase() | 56 WebViewInteractiveTestBase() |
| 93 : guest_web_contents_(NULL), | 57 : guest_web_contents_(NULL), |
| 94 embedder_web_contents_(NULL), | 58 embedder_web_contents_(NULL), |
| 95 corner_(gfx::Point()), | 59 corner_(gfx::Point()), |
| 96 mouse_click_result_(false), | 60 mouse_click_result_(false), |
| 97 first_click_(true) { | 61 first_click_(true) { |
| 98 GuestViewManager::set_factory_for_testing(&factory_); | 62 GuestViewManager::set_factory_for_testing(&factory_); |
| 99 } | 63 } |
| (...skipping 440 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 540 class WebViewNewWindowInteractiveTest : public WebViewInteractiveTest {}; | 504 class WebViewNewWindowInteractiveTest : public WebViewInteractiveTest {}; |
| 541 | 505 |
| 542 // The following class of tests do not work for OOPIF <webview>. | 506 // The following class of tests do not work for OOPIF <webview>. |
| 543 // TODO(ekaramad): Make this tests work with OOPIF and replace the test classes | 507 // TODO(ekaramad): Make this tests work with OOPIF and replace the test classes |
| 544 // with WebViewInteractiveTest (see crbug.com/582562). | 508 // with WebViewInteractiveTest (see crbug.com/582562). |
| 545 class WebViewFocusInteractiveTest : public WebViewInteractiveTestBase {}; | 509 class WebViewFocusInteractiveTest : public WebViewInteractiveTestBase {}; |
| 546 class WebViewPopupInteractiveTest : public WebViewInteractiveTestBase {}; | 510 class WebViewPopupInteractiveTest : public WebViewInteractiveTestBase {}; |
| 547 class WebViewContextMenuInteractiveTest : public WebViewInteractiveTestBase {}; | 511 class WebViewContextMenuInteractiveTest : public WebViewInteractiveTestBase {}; |
| 548 class WebViewPointerLockInteractiveTest : public WebViewInteractiveTestBase {}; | 512 class WebViewPointerLockInteractiveTest : public WebViewInteractiveTestBase {}; |
| 549 class WebViewDragDropInteractiveTest : public WebViewInteractiveTestBase {}; | 513 class WebViewDragDropInteractiveTest : public WebViewInteractiveTestBase {}; |
| 550 // TODO(ekaramad): The following tests fail of OOPIF due to focus issues. | |
| 551 // see crbug.com/61060. | |
| 552 class WebViewTextInputStateInteractiveTest : public WebViewInteractiveTest {}; | |
| 553 | 514 |
| 554 INSTANTIATE_TEST_CASE_P(WebViewInteractiveTests, | 515 INSTANTIATE_TEST_CASE_P(WebViewInteractiveTests, |
| 555 WebViewInteractiveTest, | 516 WebViewInteractiveTest, |
| 556 testing::Bool()); | 517 testing::Bool()); |
| 557 | 518 |
| 558 INSTANTIATE_TEST_CASE_P(WebViewInteractiveTests, | 519 INSTANTIATE_TEST_CASE_P(WebViewInteractiveTests, |
| 559 WebViewNewWindowInteractiveTest, | 520 WebViewNewWindowInteractiveTest, |
| 560 testing::Bool()); | 521 testing::Bool()); |
| 561 | 522 |
| 562 INSTANTIATE_TEST_CASE_P(WebViewInteractiveTests, | |
| 563 WebViewTextInputStateInteractiveTest, | |
| 564 testing::Values(false)); | |
| 565 | |
| 566 // ui_test_utils::SendMouseMoveSync doesn't seem to work on OS_MACOSX, and | 523 // ui_test_utils::SendMouseMoveSync doesn't seem to work on OS_MACOSX, and |
| 567 // likely won't work on many other platforms as well, so for now this test | 524 // likely won't work on many other platforms as well, so for now this test |
| 568 // is for Windows and Linux only. As of Sept 17th, 2013 this test is disabled | 525 // is for Windows and Linux only. As of Sept 17th, 2013 this test is disabled |
| 569 // on Windows due to flakines, see http://crbug.com/293445. | 526 // on Windows due to flakines, see http://crbug.com/293445. |
| 570 | 527 |
| 571 // Disabled on Linux Aura because pointer lock does not work on Linux Aura. | 528 // Disabled on Linux Aura because pointer lock does not work on Linux Aura. |
| 572 // crbug.com/341876 | 529 // crbug.com/341876 |
| 573 | 530 |
| 574 #if defined(OS_LINUX) | 531 #if defined(OS_LINUX) |
| 575 // flaky http://crbug.com/412086 | 532 // flaky http://crbug.com/412086 |
| (...skipping 792 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1368 // this time. | 1325 // this time. |
| 1369 for (size_t i = 0; i < 4; ++i) | 1326 for (size_t i = 0; i < 4; ++i) |
| 1370 SendKeyPressToPlatformApp(ui::VKEY_TAB); | 1327 SendKeyPressToPlatformApp(ui::VKEY_TAB); |
| 1371 ExtensionTestMessageListener webview_button_not_focused_listener( | 1328 ExtensionTestMessageListener webview_button_not_focused_listener( |
| 1372 "WebViewInteractiveTest.WebViewButtonWasNotFocused", false); | 1329 "WebViewInteractiveTest.WebViewButtonWasNotFocused", false); |
| 1373 webview_button_not_focused_listener.set_failure_message( | 1330 webview_button_not_focused_listener.set_failure_message( |
| 1374 "WebViewInteractiveTest.WebViewButtonWasFocused"); | 1331 "WebViewInteractiveTest.WebViewButtonWasFocused"); |
| 1375 SendMessageToEmbedder("verify"); | 1332 SendMessageToEmbedder("verify"); |
| 1376 EXPECT_TRUE(webview_button_not_focused_listener.WaitUntilSatisfied()); | 1333 EXPECT_TRUE(webview_button_not_focused_listener.WaitUntilSatisfied()); |
| 1377 } | 1334 } |
| 1378 | |
| 1379 // TODO(crbug.com/602954) Test is flaky. | |
| 1380 #if defined(OS_WIN) || defined(OS_MACOSX) | |
| 1381 #define MAYBE_TopLevelWebContentsTracksCorrectly \ | |
| 1382 DISABLED_TopLevelWebContentsTracksCorrectly | |
| 1383 #else | |
| 1384 #define MAYBE_TopLevelWebContentsTracksCorrectly \ | |
| 1385 TopLevelWebContentsTracksCorrectly | |
| 1386 #endif | |
| 1387 IN_PROC_BROWSER_TEST_P(WebViewTextInputStateInteractiveTest, | |
| 1388 MAYBE_TopLevelWebContentsTracksCorrectly) { | |
| 1389 SetupTest("web_view/text_input_state", | |
| 1390 "/extensions/platform_apps/web_view/text_input_state/guest.html"); | |
| 1391 | |
| 1392 auto press_tab_to_focus = [](WebViewTextInputStateInteractiveTest* test, | |
| 1393 const std::string& message) { | |
| 1394 ExtensionTestMessageListener listener(message, false); | |
| 1395 test->SendKeyPressToPlatformApp(ui::VKEY_TAB); | |
| 1396 listener.WaitUntilSatisfied(); | |
| 1397 }; | |
| 1398 | |
| 1399 auto get_type_checker = [](ui::TextInputType target) { | |
| 1400 return base::Bind(&TextInputStateHelper::IsStateOfGivenType, target); | |
| 1401 }; | |
| 1402 | |
| 1403 // Press the tab key. The <input> in the embedder should get focused. | |
| 1404 // Top level state type should be number. | |
| 1405 press_tab_to_focus(this, "EMBEDDER-FOCUSED-1"); | |
| 1406 TextInputStateHelper::WaitForDesiredState( | |
| 1407 embedder_web_contents(), get_type_checker(ui::TEXT_INPUT_TYPE_NUMBER)); | |
| 1408 | |
| 1409 // Press the tab key again and the <input> inside <webview> gets focused. The | |
| 1410 // input type should text now. | |
| 1411 press_tab_to_focus(this, "GUEST-FOCUSED"); | |
| 1412 TextInputStateHelper::WaitForDesiredState( | |
| 1413 embedder_web_contents(), get_type_checker(ui::TEXT_INPUT_TYPE_TEXT)); | |
| 1414 | |
| 1415 // Press the tab key one more time to get back to embedder's second <input>. | |
| 1416 // The value should be "last one". | |
| 1417 press_tab_to_focus(this, "EMBEDDER-FOCUSED-2"); | |
| 1418 TextInputStateHelper::WaitForDesiredState( | |
| 1419 embedder_web_contents(), | |
| 1420 base::Bind(&TextInputStateHelper::HasGivenValue, "last one")); | |
| 1421 } | |
| 1422 | |
| 1423 IN_PROC_BROWSER_TEST_P(WebViewTextInputStateInteractiveTest, | |
| 1424 CrashingWebViewResetsState) { | |
| 1425 SetupTest("web_view/text_input_state", | |
| 1426 "/extensions/platform_apps/web_view/text_input_state/guest.html"); | |
| 1427 | |
| 1428 // Press tab key twice to end up in the <input> of the <webview>. | |
| 1429 ExtensionTestMessageListener listener("GUEST-FOCUSED", false); | |
| 1430 for (size_t i = 0; i < 2; ++i) | |
| 1431 SendKeyPressToPlatformApp(ui::VKEY_TAB); | |
| 1432 | |
| 1433 listener.WaitUntilSatisfied(); | |
| 1434 | |
| 1435 // Now wait for a text input state change. | |
| 1436 TextInputStateHelper::WaitForDesiredState( | |
| 1437 embedder_web_contents(), | |
| 1438 base::Bind(&TextInputStateHelper::HasGivenValue, "guest")); | |
| 1439 | |
| 1440 // Now crash the <webview>. | |
| 1441 guest_web_contents()->GetRenderProcessHost()->Shutdown(false, 0); | |
| 1442 | |
| 1443 // Wait for the outer WebContentsImpl |text_input_state_->type| to be reset to | |
| 1444 // none. | |
| 1445 TextInputStateHelper::WaitForDesiredState( | |
| 1446 embedder_web_contents(), | |
| 1447 base::Bind(&TextInputStateHelper::IsStateOfGivenType, | |
| 1448 ui::TEXT_INPUT_TYPE_NONE)); | |
| 1449 } | |
| 1450 | |
| 1451 // This test creates a <webview> with a text input field inside, gives focus to | |
| 1452 // the input field, and then detaches the <webview>. It monitors the embedder | |
| 1453 // WebContents text input state to make sure it tracks the state properly. | |
| 1454 IN_PROC_BROWSER_TEST_P(WebViewTextInputStateInteractiveTest, | |
| 1455 OuterWebContentsResetsStateAfterDetach) { | |
| 1456 SetupTest("web_view/text_input_state", | |
| 1457 "/extensions/platform_apps/web_view/text_input_state/guest.html"); | |
| 1458 | |
| 1459 // Press tab key twice to end up in the <input> of the <webview>. | |
| 1460 ExtensionTestMessageListener listener("GUEST-FOCUSED", false); | |
| 1461 for (size_t i = 0; i < 2; ++i) | |
| 1462 SendKeyPressToPlatformApp(ui::VKEY_TAB); | |
| 1463 | |
| 1464 listener.WaitUntilSatisfied(); | |
| 1465 | |
| 1466 // Now wait for a text input state change. | |
| 1467 TextInputStateHelper::WaitForDesiredState( | |
| 1468 embedder_web_contents(), | |
| 1469 base::Bind(&TextInputStateHelper::HasGivenValue, "guest")); | |
| 1470 | |
| 1471 // Now detach the <webview>. | |
| 1472 ExtensionTestMessageListener detach_listener("detached", false); | |
| 1473 detach_listener.set_failure_message("failed-to-detach"); | |
| 1474 EXPECT_TRUE( | |
| 1475 content::ExecuteScript(embedder_web_contents(), "detachWebView();")); | |
| 1476 detach_listener.WaitUntilSatisfied(); | |
| 1477 | |
| 1478 // Wait for the outer WebContentsImpl |text_input_state_->type| to be reset to | |
| 1479 // none. | |
| 1480 TextInputStateHelper::WaitForDesiredState( | |
| 1481 embedder_web_contents(), | |
| 1482 base::Bind(&TextInputStateHelper::IsStateOfGivenType, | |
| 1483 ui::TEXT_INPUT_TYPE_NONE)); | |
| 1484 } | |
| OLD | NEW |