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