Index: content/browser/web_contents/web_contents_impl_browsertest.cc |
diff --git a/content/browser/web_contents/web_contents_impl_browsertest.cc b/content/browser/web_contents/web_contents_impl_browsertest.cc |
index 2f161b0134423a18edfa73ad2a9d3d710586340e..fea1eb689970be47a719c141df99207907b1f4c4 100644 |
--- a/content/browser/web_contents/web_contents_impl_browsertest.cc |
+++ b/content/browser/web_contents/web_contents_impl_browsertest.cc |
@@ -1467,4 +1467,78 @@ IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest, |
wc->SetJavaScriptDialogManagerForTesting(nullptr); |
} |
+class FormBubbleDelegate : public WebContentsDelegate { |
+ public: |
+ FormBubbleDelegate() = default; |
+ |
+ void WaitUntilShown() { |
+ while (!is_visible_) { |
+ message_loop_runner_ = new MessageLoopRunner; |
+ message_loop_runner_->Run(); |
+ } |
+ } |
+ |
+ void WaitUntilHidden() { |
+ while (is_visible_) { |
+ message_loop_runner_ = new MessageLoopRunner; |
+ message_loop_runner_->Run(); |
+ } |
+ } |
+ |
+ private: |
+ void ShowValidationMessage(WebContents* web_contents, |
+ const gfx::Rect& anchor_in_root_view, |
+ const base::string16& main_text, |
+ const base::string16& sub_text) override { |
+ is_visible_ = true; |
+ if (message_loop_runner_) |
+ message_loop_runner_->Quit(); |
+ } |
+ |
+ void HideValidationMessage(WebContents* web_contents) override { |
+ is_visible_ = false; |
+ if (message_loop_runner_) |
+ message_loop_runner_->Quit(); |
+ } |
+ |
+ bool is_visible_ = false; |
+ scoped_refptr<MessageLoopRunner> message_loop_runner_; |
+}; |
+ |
+IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest, |
+ NavigationHidesFormValidationBubble) { |
+ ASSERT_TRUE(embedded_test_server()->Start()); |
+ EXPECT_TRUE(NavigateToURL( |
+ shell(), embedded_test_server()->GetURL("a.com", "/title1.html"))); |
+ |
+ // Start listening for requests to show or hide the form validation bubble. |
+ WebContentsImpl* web_contents = |
+ static_cast<WebContentsImpl*>(shell()->web_contents()); |
+ FormBubbleDelegate bubble_delegate; |
+ web_contents->SetDelegate(&bubble_delegate); |
+ |
+ // Trigger a form validation bubble and verify that the bubble is shown. |
+ std::string script = R"( |
+ var input_field = document.createElement('input'); |
+ input_field.required = true; |
+ var form = document.createElement('form'); |
+ form.appendChild(input_field); |
+ document.body.appendChild(form); |
+ |
+ setTimeout(function() { |
+ input_field.setCustomValidity('Custom validity message'); |
+ input_field.reportValidity(); |
+ }, |
+ 0); |
+ )"; |
+ ASSERT_TRUE(ExecuteScript(web_contents, script)); |
+ bubble_delegate.WaitUntilShown(); |
+ |
+ // Navigate to another page and verify that the form validation bubble is |
+ // hidden. |
+ EXPECT_TRUE(NavigateToURL( |
+ shell(), embedded_test_server()->GetURL("b.com", "/title2.html"))); |
+ bubble_delegate.WaitUntilHidden(); |
+} |
+ |
} // namespace content |