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 441 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
541 class WebViewNewWindowInteractiveTest : public WebViewInteractiveTest {}; | 505 class WebViewNewWindowInteractiveTest : public WebViewInteractiveTest {}; |
542 | 506 |
543 // The following class of tests do not work for OOPIF <webview>. | 507 // The following class of tests do not work for OOPIF <webview>. |
544 // TODO(ekaramad): Make this tests work with OOPIF and replace the test classes | 508 // TODO(ekaramad): Make this tests work with OOPIF and replace the test classes |
545 // with WebViewInteractiveTest (see crbug.com/582562). | 509 // with WebViewInteractiveTest (see crbug.com/582562). |
546 class WebViewFocusInteractiveTest : public WebViewInteractiveTestBase {}; | 510 class WebViewFocusInteractiveTest : public WebViewInteractiveTestBase {}; |
547 class WebViewPopupInteractiveTest : public WebViewInteractiveTestBase {}; | 511 class WebViewPopupInteractiveTest : public WebViewInteractiveTestBase {}; |
548 class WebViewContextMenuInteractiveTest : public WebViewInteractiveTestBase {}; | 512 class WebViewContextMenuInteractiveTest : public WebViewInteractiveTestBase {}; |
549 class WebViewPointerLockInteractiveTest : public WebViewInteractiveTestBase {}; | 513 class WebViewPointerLockInteractiveTest : public WebViewInteractiveTestBase {}; |
550 class WebViewDragDropInteractiveTest : public WebViewInteractiveTestBase {}; | 514 class WebViewDragDropInteractiveTest : public WebViewInteractiveTestBase {}; |
551 // TODO(ekaramad): The following tests fail of OOPIF due to focus issues. | |
552 // see crbug.com/61060. | |
553 class WebViewTextInputStateInteractiveTest : public WebViewInteractiveTest {}; | |
554 | 515 |
555 INSTANTIATE_TEST_CASE_P(WebViewInteractiveTests, | 516 INSTANTIATE_TEST_CASE_P(WebViewInteractiveTests, |
556 WebViewInteractiveTest, | 517 WebViewInteractiveTest, |
557 testing::Bool()); | 518 testing::Bool()); |
558 | 519 |
559 INSTANTIATE_TEST_CASE_P(WebViewInteractiveTests, | 520 INSTANTIATE_TEST_CASE_P(WebViewInteractiveTests, |
560 WebViewNewWindowInteractiveTest, | 521 WebViewNewWindowInteractiveTest, |
561 testing::Bool()); | 522 testing::Bool()); |
562 | 523 |
563 INSTANTIATE_TEST_CASE_P(WebViewInteractiveTests, | |
564 WebViewTextInputStateInteractiveTest, | |
565 testing::Values(false)); | |
566 | |
567 // ui_test_utils::SendMouseMoveSync doesn't seem to work on OS_MACOSX, and | 524 // ui_test_utils::SendMouseMoveSync doesn't seem to work on OS_MACOSX, and |
568 // likely won't work on many other platforms as well, so for now this test | 525 // likely won't work on many other platforms as well, so for now this test |
569 // is for Windows and Linux only. As of Sept 17th, 2013 this test is disabled | 526 // is for Windows and Linux only. As of Sept 17th, 2013 this test is disabled |
570 // on Windows due to flakines, see http://crbug.com/293445. | 527 // on Windows due to flakines, see http://crbug.com/293445. |
571 | 528 |
572 // Disabled on Linux Aura because pointer lock does not work on Linux Aura. | 529 // Disabled on Linux Aura because pointer lock does not work on Linux Aura. |
573 // crbug.com/341876 | 530 // crbug.com/341876 |
574 | 531 |
575 #if defined(OS_LINUX) | 532 #if defined(OS_LINUX) |
576 // flaky http://crbug.com/412086 | 533 // flaky http://crbug.com/412086 |
(...skipping 794 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1371 // this time. | 1328 // this time. |
1372 for (size_t i = 0; i < 4; ++i) | 1329 for (size_t i = 0; i < 4; ++i) |
1373 SendKeyPressToPlatformApp(ui::VKEY_TAB); | 1330 SendKeyPressToPlatformApp(ui::VKEY_TAB); |
1374 ExtensionTestMessageListener webview_button_not_focused_listener( | 1331 ExtensionTestMessageListener webview_button_not_focused_listener( |
1375 "WebViewInteractiveTest.WebViewButtonWasNotFocused", false); | 1332 "WebViewInteractiveTest.WebViewButtonWasNotFocused", false); |
1376 webview_button_not_focused_listener.set_failure_message( | 1333 webview_button_not_focused_listener.set_failure_message( |
1377 "WebViewInteractiveTest.WebViewButtonWasFocused"); | 1334 "WebViewInteractiveTest.WebViewButtonWasFocused"); |
1378 SendMessageToEmbedder("verify"); | 1335 SendMessageToEmbedder("verify"); |
1379 EXPECT_TRUE(webview_button_not_focused_listener.WaitUntilSatisfied()); | 1336 EXPECT_TRUE(webview_button_not_focused_listener.WaitUntilSatisfied()); |
1380 } | 1337 } |
1381 | |
1382 IN_PROC_BROWSER_TEST_P(WebViewTextInputStateInteractiveTest, | |
1383 TopLevelWebContentsTracksCorrectly) { | |
1384 SetupTest("web_view/text_input_state", | |
1385 "/extensions/platform_apps/web_view/text_input_state/guest.html"); | |
1386 | |
1387 auto press_tab_to_focus = [](WebViewTextInputStateInteractiveTest* test, | |
1388 const std::string& message) { | |
1389 ExtensionTestMessageListener listener(message, false); | |
1390 test->SendKeyPressToPlatformApp(ui::VKEY_TAB); | |
1391 listener.WaitUntilSatisfied(); | |
1392 }; | |
1393 | |
1394 auto get_type_checker = [](ui::TextInputType target) { | |
1395 return base::Bind(&TextInputStateHelper::IsStateOfGivenType, target); | |
1396 }; | |
1397 | |
1398 // Press the tab key. The <input> in the embedder should get focused. | |
1399 // Top level state type should be number. | |
1400 press_tab_to_focus(this, "EMBEDDER-FOCUSED-1"); | |
1401 TextInputStateHelper::WaitForDesiredState( | |
1402 embedder_web_contents(), get_type_checker(ui::TEXT_INPUT_TYPE_NUMBER)); | |
1403 | |
1404 // Press the tab key again and the <input> inside <webview> gets focused. The | |
1405 // input type should text now. | |
1406 press_tab_to_focus(this, "GUEST-FOCUSED"); | |
1407 TextInputStateHelper::WaitForDesiredState( | |
1408 embedder_web_contents(), get_type_checker(ui::TEXT_INPUT_TYPE_TEXT)); | |
1409 | |
1410 // Press the tab key one more time to get back to embedder's second <input>. | |
1411 // The value should be "last one". | |
1412 press_tab_to_focus(this, "EMBEDDER-FOCUSED-2"); | |
1413 TextInputStateHelper::WaitForDesiredState( | |
1414 embedder_web_contents(), | |
1415 base::Bind(&TextInputStateHelper::HasGivenValue, "last one")); | |
1416 } | |
1417 | |
1418 // TODO(ekaramad): Activate this test for OOPIF when input event routing for | |
1419 // OOPIF-<webview> is fixed. | |
1420 IN_PROC_BROWSER_TEST_P(WebViewTextInputStateInteractiveTest, | |
1421 CrashingWebViewResetsState) { | |
1422 SetupTest("web_view/text_input_state", | |
1423 "/extensions/platform_apps/web_view/text_input_state/guest.html"); | |
1424 | |
1425 // Press tab key twice to end up in the <input> of the <webview>, | |
1426 ExtensionTestMessageListener listener("GUEST-FOCUSED", false); | |
1427 for (size_t i = 0; i < 2; ++i) | |
1428 SendKeyPressToPlatformApp(ui::VKEY_TAB); | |
1429 | |
1430 listener.WaitUntilSatisfied(); | |
1431 | |
1432 // Now wait for a text input state change. | |
1433 TextInputStateHelper::WaitForDesiredState( | |
1434 embedder_web_contents(), | |
1435 base::Bind(&TextInputStateHelper::HasGivenValue, "guest")); | |
1436 | |
1437 // Now crash the <webview>. | |
1438 guest_web_contents()->GetRenderProcessHost()->Shutdown(false, 0); | |
1439 | |
1440 // State should reset to none. | |
1441 TextInputStateHelper::WaitForDesiredState( | |
1442 embedder_web_contents(), | |
1443 base::Bind(&TextInputStateHelper::IsStateOfGivenType, | |
1444 ui::TEXT_INPUT_TYPE_NONE)); | |
1445 } | |
OLD | NEW |