Index: chrome/browser/apps/guest_view/web_view_interactive_browsertest.cc |
diff --git a/chrome/browser/apps/guest_view/web_view_interactive_browsertest.cc b/chrome/browser/apps/guest_view/web_view_interactive_browsertest.cc |
index 53bfdc5a9e4050af08e180f4cdaa8f2ca2935035..e524dc60c6694100a07876f61aab6bf7a968cd64 100644 |
--- a/chrome/browser/apps/guest_view/web_view_interactive_browsertest.cc |
+++ b/chrome/browser/apps/guest_view/web_view_interactive_browsertest.cc |
@@ -504,6 +504,7 @@ class WebViewInteractiveTest : public WebViewInteractiveTestBase, |
}; |
class WebViewNewWindowInteractiveTest : public WebViewInteractiveTest {}; |
+class WebViewTextInputStateInteractiveTest : public WebViewInteractiveTest {}; |
// The following class of tests do not work for OOPIF <webview>. |
// TODO(ekaramad): Make this tests work with OOPIF and replace the test classes |
@@ -522,6 +523,10 @@ INSTANTIATE_TEST_CASE_P(WebViewInteractiveTests, |
WebViewNewWindowInteractiveTest, |
testing::Bool()); |
+INSTANTIATE_TEST_CASE_P(WebViewInteractiveTests, |
+ WebViewTextInputStateInteractiveTest, |
+ 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.
|
+ |
// ui_test_utils::SendMouseMoveSync doesn't seem to work on OS_MACOSX, and |
// likely won't work on many other platforms as well, so for now this test |
// is for Windows and Linux only. As of Sept 17th, 2013 this test is disabled |
@@ -1346,3 +1351,109 @@ IN_PROC_BROWSER_TEST_F(WebViewFocusInteractiveTest, FocusAndVisibility) { |
SendMessageToEmbedder("verify"); |
EXPECT_TRUE(webview_button_not_focused_listener.WaitUntilSatisfied()); |
} |
+ |
+// A helper class which polls the text input state of the given WebContents. |
+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.
|
+ 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)); |
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.
|
+ 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(ekaramad): Activate this test for OOPIF when input event routing for |
+// OOPIF-<webview> is fixed. |
+IN_PROC_BROWSER_TEST_P(WebViewTextInputStateInteractiveTest, |
+ TopLevelWebContentsTracksCorrectly) { |
+ if (content::BrowserPluginGuestMode::UseCrossProcessFramesForGuests()) |
+ return; |
+ |
+ SetupTest("web_view/text_input_state", |
+ "/extensions/platform_apps/web_view/text_input_state/guest.html"); |
+ |
+ auto press_tab_to_focus = [](WebViewTextInputStateInteractiveTest* test, |
+ const std::string& message) { |
+ ExtensionTestMessageListener listener(message, false); |
+ test->SendKeyPressToPlatformApp(ui::VKEY_TAB); |
+ listener.WaitUntilSatisfied(); |
+ }; |
+ |
+ auto get_type_checker = [](ui::TextInputType target) { |
+ return base::Bind(&TextInputStateHelper::IsStateOfGivenType, target); |
+ }; |
+ |
+ // Press the tab key. The <input> in the embedder should get focused. |
+ // Top level state type should be number. |
+ press_tab_to_focus(this, "EMBEDDER-FOCUSED-1"); |
+ TextInputStateHelper::WaitForDesiredState( |
+ embedder_web_contents(), 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_to_focus(this, "GUEST-FOCUSED"); |
+ TextInputStateHelper::WaitForDesiredState( |
+ embedder_web_contents(), 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_to_focus(this, "EMBEDDER-FOCUSED-2"); |
+ TextInputStateHelper::WaitForDesiredState( |
+ embedder_web_contents(), |
+ 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(WebViewTextInputStateInteractiveTest, |
+ CrashingWebViewResetsState) { |
+ if (content::BrowserPluginGuestMode::UseCrossProcessFramesForGuests()) |
+ return; |
+ |
+ SetupTest("web_view/text_input_state", |
+ "/extensions/platform_apps/web_view/text_input_state/guest.html"); |
+ |
+ // Press tab key twice to end up in the <input> of the <webview>, |
+ ExtensionTestMessageListener listener("GUEST-FOCUSED", false); |
+ for (size_t i = 0; i < 2; ++i) |
+ SendKeyPressToPlatformApp(ui::VKEY_TAB); |
+ |
+ listener.WaitUntilSatisfied(); |
+ |
+ // Now wait for a text input state change. |
+ TextInputStateHelper::WaitForDesiredState( |
+ embedder_web_contents(), |
+ base::Bind(&TextInputStateHelper::HasGivenValue, "guest")); |
+ |
+ // Now crash the <webview>. |
+ guest_web_contents()->GetRenderProcessHost()->Shutdown(false, 0); |
+ |
+ // State should reset to none. |
+ TextInputStateHelper::WaitForDesiredState( |
+ embedder_web_contents(), |
+ base::Bind(&TextInputStateHelper::IsStateOfGivenType, |
+ ui::TEXT_INPUT_TYPE_NONE)); |
+} |