Chromium Code Reviews| Index: chrome/browser/apps/guest_view/web_view_browsertest.cc |
| diff --git a/chrome/browser/apps/guest_view/web_view_browsertest.cc b/chrome/browser/apps/guest_view/web_view_browsertest.cc |
| index 3def5c52abf3b19cee0ccee6af4dcb5eb5dba753..5a5c41f247af0b232c761c2e126c3b31ab9f2ab7 100644 |
| --- a/chrome/browser/apps/guest_view/web_view_browsertest.cc |
| +++ b/chrome/browser/apps/guest_view/web_view_browsertest.cc |
| @@ -355,6 +355,38 @@ class MockDownloadWebContentsDelegate : public content::WebContentsDelegate { |
| DISALLOW_COPY_AND_ASSIGN(MockDownloadWebContentsDelegate); |
| }; |
| +class TextInputStateHelper { |
| + public: |
| + using Predicate = |
| + base::Callback<bool(const content::TextInputStateTestExport&)>; |
| + |
| + static void WaitForDesiredState(content::WebContents* web_contents, |
| + const Predicate& predicate) { |
| + content::TextInputStateTestExport state = |
| + content::TextInputStateTestExport::FromWebContents(web_contents); |
| + while (!predicate.Run(state)) { |
| + scoped_refptr<content::MessageLoopRunner> loop = |
| + new content::MessageLoopRunner(); |
| + content::BrowserThread::PostDelayedTask( |
| + content::BrowserThread::UI, FROM_HERE, loop->QuitClosure(), |
| + base::TimeDelta::FromMilliseconds(1LL)); |
| + loop->Run(); |
| + state = content::TextInputStateTestExport::FromWebContents(web_contents); |
| + } |
| + } |
| + |
| + static bool IsStateOfGivenType( |
| + ui::TextInputType type, |
| + const content::TextInputStateTestExport& state) { |
| + return type == state.type(); |
| + } |
| + |
| + static bool HasGivenValue(const std::string& value, |
| + const content::TextInputStateTestExport& state) { |
| + return value == state.value(); |
| + } |
| +}; |
| + |
| // TODO(wjmaclean): Fix this test class at some point so it can be re-enabled on |
| // the site isolation bots, and then look at re-enabling WebViewFocusTest when |
| // that happens. |
| @@ -781,6 +813,12 @@ class WebViewWithZoomForDSFTest : public WebViewTest { |
| static float scale() { return 2.0f; } |
| }; |
| +// TODO(ekaramad): Enable this test for OOPIF. |
| +class WebViewTextInputStateTest : public WebViewTest {}; |
| +INSTANTIATE_TEST_CASE_P(WebViewTests, |
| + WebViewTextInputStateTest, |
| + testing::Bool()); |
| + |
| class WebContentsAudioMutedObserver : public content::WebContentsObserver { |
| public: |
| explicit WebContentsAudioMutedObserver(content::WebContents* web_contents) |
| @@ -3116,3 +3154,79 @@ IN_PROC_BROWSER_TEST_P(WebViewTest, TaskManagementPostExistingWebViews) { |
| } |
| #endif // defined(ENABLE_TASK_MANAGER) |
| + |
| +// TODO(ekaramad): Activate this test for OOPIF when input event routing for |
| +// OOPIF-<webview> is fixed. |
| +IN_PROC_BROWSER_TEST_P(WebViewTextInputStateTest, |
| + TopLevelWebContentsTracksCorrectly) { |
| + if (content::BrowserPluginGuestMode::UseCrossProcessFramesForGuests()) |
| + return; |
| + |
| + ASSERT_TRUE(StartEmbeddedTestServer()); |
| + |
| + EXPECT_TRUE(!!LoadGuest( |
| + "/extensions/platform_apps/web_view/text_input_state/guest.html", |
| + "web_view/text_input_state")); |
| + |
| + auto press_tab = [](content::WebContents* web_contents) { |
| + content::SimulateKeyPress(web_contents, ui::VKEY_TAB, false, false, false, |
| + false); |
| + }; |
| + |
| + auto get_type_checker = [](ui::TextInputType target) { |
| + return base::Bind(&TextInputStateHelper::IsStateOfGivenType, target); |
| + }; |
| + |
| + content::WebContents* embedder_webcontents = GetEmbedderWebContents(); |
| + |
| + // Press the tab key. The <input> in the embedder should get focused. |
| + // Top level state type should be number. |
| + press_tab(embedder_webcontents); |
| + TextInputStateHelper::WaitForDesiredState( |
|
lazyboy
2016/04/04 19:17:59
Generally, queuing tasks to wait for a change is d
EhsanK
2016/04/06 00:37:58
(As discussed offline) I now listen to 'onfocus()'
|
| + GetEmbedderWebContents(), get_type_checker(ui::TEXT_INPUT_TYPE_NUMBER)); |
| + |
| + // Press the tab key again and the <input> inside <webview> gets focused. The |
| + // input type should text now. |
| + press_tab(embedder_webcontents); |
| + TextInputStateHelper::WaitForDesiredState( |
| + GetEmbedderWebContents(), get_type_checker(ui::TEXT_INPUT_TYPE_TEXT)); |
| + |
| + // Press the tab key one more time to get back to embedder's second <input>. |
| + // The value should be "last one". |
| + press_tab(embedder_webcontents); |
| + TextInputStateHelper::WaitForDesiredState( |
| + GetEmbedderWebContents(), |
| + base::Bind(&TextInputStateHelper::HasGivenValue, "last one")); |
| +} |
| + |
| +// TODO(ekaramad): Activate this test for OOPIF when input event routing for |
| +// OOPIF-<webview> is fixed. |
| +IN_PROC_BROWSER_TEST_P(WebViewTextInputStateTest, CrashingWebViewResetsState) { |
| + if (content::BrowserPluginGuestMode::UseCrossProcessFramesForGuests()) |
| + return; |
| + |
| + ASSERT_TRUE(StartEmbeddedTestServer()); |
| + |
| + content::WebContents* guest_contents = LoadGuest( |
| + "/extensions/platform_apps/web_view/text_input_state/guest.html", |
| + "web_view/text_input_state"); |
| + |
| + // Press tab key twice to end up in the <input> of the <webview>, |
| + for (size_t i = 0; i < 2; ++i) { |
| + content::SimulateKeyPress(GetEmbedderWebContents(), ui::VKEY_TAB, false, |
| + false, false, false); |
| + }; |
| + |
| + TextInputStateHelper::WaitForDesiredState( |
| + GetEmbedderWebContents(), |
| + base::Bind(&TextInputStateHelper::HasGivenValue, "guest")); |
| + |
| + // Now crash the <webview>. |
| + guest_contents->GetRenderProcessHost()->Shutdown(false, 0); |
| + |
| + // State should reset to none. |
| + TextInputStateHelper::WaitForDesiredState( |
| + GetEmbedderWebContents(), |
| + base::Bind(&TextInputStateHelper::IsStateOfGivenType, |
| + ui::TEXT_INPUT_TYPE_NONE)); |
| +} |