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 486 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
497 void SetUpCommandLine(base::CommandLine* command_line) override { | 497 void SetUpCommandLine(base::CommandLine* command_line) override { |
498 WebViewInteractiveTestBase::SetUpCommandLine(command_line); | 498 WebViewInteractiveTestBase::SetUpCommandLine(command_line); |
499 | 499 |
500 bool use_cross_process_frames_for_guests = GetParam(); | 500 bool use_cross_process_frames_for_guests = GetParam(); |
501 if (use_cross_process_frames_for_guests) | 501 if (use_cross_process_frames_for_guests) |
502 command_line->AppendSwitch(switches::kUseCrossProcessFramesForGuests); | 502 command_line->AppendSwitch(switches::kUseCrossProcessFramesForGuests); |
503 } | 503 } |
504 }; | 504 }; |
505 | 505 |
506 class WebViewNewWindowInteractiveTest : public WebViewInteractiveTest {}; | 506 class WebViewNewWindowInteractiveTest : public WebViewInteractiveTest {}; |
507 class WebViewTextInputStateInteractiveTest : public WebViewInteractiveTest {}; | |
507 | 508 |
508 // The following class of tests do not work for OOPIF <webview>. | 509 // The following class of tests do not work for OOPIF <webview>. |
509 // TODO(ekaramad): Make this tests work with OOPIF and replace the test classes | 510 // TODO(ekaramad): Make this tests work with OOPIF and replace the test classes |
510 // with WebViewInteractiveTest (see crbug.com/582562). | 511 // with WebViewInteractiveTest (see crbug.com/582562). |
511 class WebViewFocusInteractiveTest : public WebViewInteractiveTestBase {}; | 512 class WebViewFocusInteractiveTest : public WebViewInteractiveTestBase {}; |
512 class WebViewPopupInteractiveTest : public WebViewInteractiveTestBase {}; | 513 class WebViewPopupInteractiveTest : public WebViewInteractiveTestBase {}; |
513 class WebViewContextMenuInteractiveTest : public WebViewInteractiveTestBase {}; | 514 class WebViewContextMenuInteractiveTest : public WebViewInteractiveTestBase {}; |
514 class WebViewPointerLockInteractiveTest : public WebViewInteractiveTestBase {}; | 515 class WebViewPointerLockInteractiveTest : public WebViewInteractiveTestBase {}; |
515 class WebViewDragDropInteractiveTest : public WebViewInteractiveTestBase {}; | 516 class WebViewDragDropInteractiveTest : public WebViewInteractiveTestBase {}; |
516 | 517 |
517 INSTANTIATE_TEST_CASE_P(WebViewInteractiveTests, | 518 INSTANTIATE_TEST_CASE_P(WebViewInteractiveTests, |
518 WebViewInteractiveTest, | 519 WebViewInteractiveTest, |
519 testing::Bool()); | 520 testing::Bool()); |
520 | 521 |
521 INSTANTIATE_TEST_CASE_P(WebViewInteractiveTests, | 522 INSTANTIATE_TEST_CASE_P(WebViewInteractiveTests, |
522 WebViewNewWindowInteractiveTest, | 523 WebViewNewWindowInteractiveTest, |
523 testing::Bool()); | 524 testing::Bool()); |
524 | 525 |
526 INSTANTIATE_TEST_CASE_P(WebViewInteractiveTests, | |
527 WebViewTextInputStateInteractiveTest, | |
528 testing::Bool()); | |
lazyboy
2016/04/06 02:39:53
testing::Values(false), since all the tests in thi
EhsanK
2016/04/06 16:04:50
Done.
| |
529 | |
525 // ui_test_utils::SendMouseMoveSync doesn't seem to work on OS_MACOSX, and | 530 // ui_test_utils::SendMouseMoveSync doesn't seem to work on OS_MACOSX, and |
526 // likely won't work on many other platforms as well, so for now this test | 531 // likely won't work on many other platforms as well, so for now this test |
527 // is for Windows and Linux only. As of Sept 17th, 2013 this test is disabled | 532 // is for Windows and Linux only. As of Sept 17th, 2013 this test is disabled |
528 // on Windows due to flakines, see http://crbug.com/293445. | 533 // on Windows due to flakines, see http://crbug.com/293445. |
529 | 534 |
530 // Disabled on Linux Aura because pointer lock does not work on Linux Aura. | 535 // Disabled on Linux Aura because pointer lock does not work on Linux Aura. |
531 // crbug.com/341876 | 536 // crbug.com/341876 |
532 | 537 |
533 #if defined(OS_LINUX) | 538 #if defined(OS_LINUX) |
534 // flaky http://crbug.com/412086 | 539 // flaky http://crbug.com/412086 |
(...skipping 804 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1339 // this time. | 1344 // this time. |
1340 for (size_t i = 0; i < 4; ++i) | 1345 for (size_t i = 0; i < 4; ++i) |
1341 SendKeyPressToPlatformApp(ui::VKEY_TAB); | 1346 SendKeyPressToPlatformApp(ui::VKEY_TAB); |
1342 ExtensionTestMessageListener webview_button_not_focused_listener( | 1347 ExtensionTestMessageListener webview_button_not_focused_listener( |
1343 "WebViewInteractiveTest.WebViewButtonWasNotFocused", false); | 1348 "WebViewInteractiveTest.WebViewButtonWasNotFocused", false); |
1344 webview_button_not_focused_listener.set_failure_message( | 1349 webview_button_not_focused_listener.set_failure_message( |
1345 "WebViewInteractiveTest.WebViewButtonWasFocused"); | 1350 "WebViewInteractiveTest.WebViewButtonWasFocused"); |
1346 SendMessageToEmbedder("verify"); | 1351 SendMessageToEmbedder("verify"); |
1347 EXPECT_TRUE(webview_button_not_focused_listener.WaitUntilSatisfied()); | 1352 EXPECT_TRUE(webview_button_not_focused_listener.WaitUntilSatisfied()); |
1348 } | 1353 } |
1354 | |
1355 // A helper class which polls the text input state of the given WebContents. | |
1356 class TextInputStateHelper { | |
lazyboy
2016/04/06 02:39:54
Move this class to a anonymous namespace and put i
EhsanK
2016/04/06 16:04:50
Done.
| |
1357 public: | |
1358 using Predicate = | |
1359 base::Callback<bool(const content::TextInputStateTestExport&)>; | |
1360 | |
1361 static void WaitForDesiredState(content::WebContents* web_contents, | |
1362 const Predicate& predicate) { | |
1363 content::TextInputStateTestExport state = | |
1364 content::TextInputStateTestExport::FromWebContents(web_contents); | |
1365 while (!predicate.Run(state)) { | |
1366 scoped_refptr<content::MessageLoopRunner> loop = | |
1367 new content::MessageLoopRunner(); | |
1368 content::BrowserThread::PostDelayedTask( | |
1369 content::BrowserThread::UI, FROM_HERE, loop->QuitClosure(), | |
1370 base::TimeDelta::FromMilliseconds(1LL)); | |
lazyboy
2016/04/06 02:39:53
1ms is too agressive, I'd do ~100ms, put the value
EhsanK
2016/04/06 16:04:50
Done.
| |
1371 loop->Run(); | |
1372 state = content::TextInputStateTestExport::FromWebContents(web_contents); | |
1373 } | |
1374 } | |
1375 | |
1376 static bool IsStateOfGivenType( | |
1377 ui::TextInputType type, | |
1378 const content::TextInputStateTestExport& state) { | |
1379 return type == state.type(); | |
1380 } | |
1381 | |
1382 static bool HasGivenValue(const std::string& value, | |
1383 const content::TextInputStateTestExport& state) { | |
1384 return value == state.value(); | |
1385 } | |
1386 }; | |
1387 | |
1388 // TODO(ekaramad): Activate this test for OOPIF when input event routing for | |
1389 // OOPIF-<webview> is fixed. | |
1390 IN_PROC_BROWSER_TEST_P(WebViewTextInputStateInteractiveTest, | |
1391 TopLevelWebContentsTracksCorrectly) { | |
1392 if (content::BrowserPluginGuestMode::UseCrossProcessFramesForGuests()) | |
1393 return; | |
1394 | |
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 if (content::BrowserPluginGuestMode::UseCrossProcessFramesForGuests()) | |
1434 return; | |
1435 | |
1436 SetupTest("web_view/text_input_state", | |
1437 "/extensions/platform_apps/web_view/text_input_state/guest.html"); | |
1438 | |
1439 // Press tab key twice to end up in the <input> of the <webview>, | |
1440 ExtensionTestMessageListener listener("GUEST-FOCUSED", false); | |
1441 for (size_t i = 0; i < 2; ++i) | |
1442 SendKeyPressToPlatformApp(ui::VKEY_TAB); | |
1443 | |
1444 listener.WaitUntilSatisfied(); | |
1445 | |
1446 // Now wait for a text input state change. | |
1447 TextInputStateHelper::WaitForDesiredState( | |
1448 embedder_web_contents(), | |
1449 base::Bind(&TextInputStateHelper::HasGivenValue, "guest")); | |
1450 | |
1451 // Now crash the <webview>. | |
1452 guest_web_contents()->GetRenderProcessHost()->Shutdown(false, 0); | |
1453 | |
1454 // State should reset to none. | |
1455 TextInputStateHelper::WaitForDesiredState( | |
1456 embedder_web_contents(), | |
1457 base::Bind(&TextInputStateHelper::IsStateOfGivenType, | |
1458 ui::TEXT_INPUT_TYPE_NONE)); | |
1459 } | |
OLD | NEW |