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

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

Issue 1652483002: Browser Side Text Input State Tracking for OOPIF. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Merged Created 4 years, 8 months 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
« no previous file with comments | « no previous file | chrome/test/data/extensions/platform_apps/web_view/text_input_state/background.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
55 class WebViewInteractiveTestBase : public extensions::PlatformAppBrowserTest { 91 class WebViewInteractiveTestBase : public extensions::PlatformAppBrowserTest {
56 public: 92 public:
57 WebViewInteractiveTestBase() 93 WebViewInteractiveTestBase()
58 : guest_web_contents_(NULL), 94 : guest_web_contents_(NULL),
59 embedder_web_contents_(NULL), 95 embedder_web_contents_(NULL),
60 corner_(gfx::Point()), 96 corner_(gfx::Point()),
61 mouse_click_result_(false), 97 mouse_click_result_(false),
62 first_click_(true) { 98 first_click_(true) {
63 GuestViewManager::set_factory_for_testing(&factory_); 99 GuestViewManager::set_factory_for_testing(&factory_);
64 } 100 }
(...skipping 441 matching lines...) Expand 10 before | Expand all | Expand 10 after
506 class WebViewNewWindowInteractiveTest : public WebViewInteractiveTest {}; 542 class WebViewNewWindowInteractiveTest : public WebViewInteractiveTest {};
507 543
508 // The following class of tests do not work for OOPIF <webview>. 544 // 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 545 // TODO(ekaramad): Make this tests work with OOPIF and replace the test classes
510 // with WebViewInteractiveTest (see crbug.com/582562). 546 // with WebViewInteractiveTest (see crbug.com/582562).
511 class WebViewFocusInteractiveTest : public WebViewInteractiveTestBase {}; 547 class WebViewFocusInteractiveTest : public WebViewInteractiveTestBase {};
512 class WebViewPopupInteractiveTest : public WebViewInteractiveTestBase {}; 548 class WebViewPopupInteractiveTest : public WebViewInteractiveTestBase {};
513 class WebViewContextMenuInteractiveTest : public WebViewInteractiveTestBase {}; 549 class WebViewContextMenuInteractiveTest : public WebViewInteractiveTestBase {};
514 class WebViewPointerLockInteractiveTest : public WebViewInteractiveTestBase {}; 550 class WebViewPointerLockInteractiveTest : public WebViewInteractiveTestBase {};
515 class WebViewDragDropInteractiveTest : public WebViewInteractiveTestBase {}; 551 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 {};
516 555
517 INSTANTIATE_TEST_CASE_P(WebViewInteractiveTests, 556 INSTANTIATE_TEST_CASE_P(WebViewInteractiveTests,
518 WebViewInteractiveTest, 557 WebViewInteractiveTest,
519 testing::Bool()); 558 testing::Bool());
520 559
521 INSTANTIATE_TEST_CASE_P(WebViewInteractiveTests, 560 INSTANTIATE_TEST_CASE_P(WebViewInteractiveTests,
522 WebViewNewWindowInteractiveTest, 561 WebViewNewWindowInteractiveTest,
523 testing::Bool()); 562 testing::Bool());
524 563
564 INSTANTIATE_TEST_CASE_P(WebViewInteractiveTests,
565 WebViewTextInputStateInteractiveTest,
566 testing::Values(false));
567
525 // ui_test_utils::SendMouseMoveSync doesn't seem to work on OS_MACOSX, and 568 // 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 569 // 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 570 // 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. 571 // on Windows due to flakines, see http://crbug.com/293445.
529 572
530 // Disabled on Linux Aura because pointer lock does not work on Linux Aura. 573 // Disabled on Linux Aura because pointer lock does not work on Linux Aura.
531 // crbug.com/341876 574 // crbug.com/341876
532 575
533 #if defined(OS_LINUX) 576 #if defined(OS_LINUX)
534 // flaky http://crbug.com/412086 577 // flaky http://crbug.com/412086
(...skipping 804 matching lines...) Expand 10 before | Expand all | Expand 10 after
1339 // this time. 1382 // this time.
1340 for (size_t i = 0; i < 4; ++i) 1383 for (size_t i = 0; i < 4; ++i)
1341 SendKeyPressToPlatformApp(ui::VKEY_TAB); 1384 SendKeyPressToPlatformApp(ui::VKEY_TAB);
1342 ExtensionTestMessageListener webview_button_not_focused_listener( 1385 ExtensionTestMessageListener webview_button_not_focused_listener(
1343 "WebViewInteractiveTest.WebViewButtonWasNotFocused", false); 1386 "WebViewInteractiveTest.WebViewButtonWasNotFocused", false);
1344 webview_button_not_focused_listener.set_failure_message( 1387 webview_button_not_focused_listener.set_failure_message(
1345 "WebViewInteractiveTest.WebViewButtonWasFocused"); 1388 "WebViewInteractiveTest.WebViewButtonWasFocused");
1346 SendMessageToEmbedder("verify"); 1389 SendMessageToEmbedder("verify");
1347 EXPECT_TRUE(webview_button_not_focused_listener.WaitUntilSatisfied()); 1390 EXPECT_TRUE(webview_button_not_focused_listener.WaitUntilSatisfied());
1348 } 1391 }
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 }
OLDNEW
« no previous file with comments | « no previous file | chrome/test/data/extensions/platform_apps/web_view/text_input_state/background.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698