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 "base/macros.h" | 5 #include "base/macros.h" |
6 #include "base/run_loop.h" | 6 #include "base/run_loop.h" |
7 #include "base/strings/pattern.h" | 7 #include "base/strings/pattern.h" |
8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
9 #include "base/values.h" | 9 #include "base/values.h" |
10 #include "build/build_config.h" | 10 #include "build/build_config.h" |
(...skipping 1449 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1460 script = "window.onbeforeunload=function(e){ return 'x' };"; | 1460 script = "window.onbeforeunload=function(e){ return 'x' };"; |
1461 EXPECT_TRUE(content::ExecuteScript(wc, script)); | 1461 EXPECT_TRUE(content::ExecuteScript(wc, script)); |
1462 EXPECT_TRUE(NavigateToURL(shell(), url)); | 1462 EXPECT_TRUE(NavigateToURL(shell(), url)); |
1463 dialog_manager.Wait(); | 1463 dialog_manager.Wait(); |
1464 EXPECT_FALSE(wc->IsFullscreenForCurrentTab()); | 1464 EXPECT_FALSE(wc->IsFullscreenForCurrentTab()); |
1465 | 1465 |
1466 wc->SetDelegate(nullptr); | 1466 wc->SetDelegate(nullptr); |
1467 wc->SetJavaScriptDialogManagerForTesting(nullptr); | 1467 wc->SetJavaScriptDialogManagerForTesting(nullptr); |
1468 } | 1468 } |
1469 | 1469 |
1470 class FormBubbleDelegate : public WebContentsDelegate { | |
1471 public: | |
1472 FormBubbleDelegate() = default; | |
1473 | |
1474 void WaitUntilShown() { | |
1475 while (!is_visible_) { | |
1476 message_loop_runner_ = new MessageLoopRunner; | |
1477 message_loop_runner_->Run(); | |
1478 } | |
1479 } | |
1480 | |
1481 void WaitUntilHidden() { | |
1482 while (is_visible_) { | |
1483 message_loop_runner_ = new MessageLoopRunner; | |
1484 message_loop_runner_->Run(); | |
1485 } | |
1486 } | |
1487 | |
1488 private: | |
1489 void ShowValidationMessage(WebContents* web_contents, | |
1490 const gfx::Rect& anchor_in_root_view, | |
1491 const base::string16& main_text, | |
1492 const base::string16& sub_text) override { | |
1493 is_visible_ = true; | |
1494 if (message_loop_runner_) | |
1495 message_loop_runner_->Quit(); | |
1496 } | |
1497 | |
1498 void HideValidationMessage(WebContents* web_contents) override { | |
1499 is_visible_ = false; | |
1500 if (message_loop_runner_) | |
1501 message_loop_runner_->Quit(); | |
1502 } | |
1503 | |
1504 bool is_visible_ = false; | |
1505 scoped_refptr<MessageLoopRunner> message_loop_runner_; | |
1506 }; | |
1507 | |
1508 IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest, | |
1509 NavigationHidesFormValidationBubble) { | |
1510 ASSERT_TRUE(embedded_test_server()->Start()); | |
1511 EXPECT_TRUE(NavigateToURL( | |
1512 shell(), embedded_test_server()->GetURL("a.com", "/title1.html"))); | |
1513 | |
1514 // Start listening for requests to show or hide the form validation bubble. | |
1515 WebContentsImpl* web_contents = | |
1516 static_cast<WebContentsImpl*>(shell()->web_contents()); | |
1517 FormBubbleDelegate bubble_delegate; | |
1518 web_contents->SetDelegate(&bubble_delegate); | |
1519 | |
1520 // Trigger a form validation bubble and verify that the bubble is shown. | |
1521 std::string script = R"( | |
1522 var input_field = document.createElement('input'); | |
1523 input_field.required = true; | |
1524 var form = document.createElement('form'); | |
1525 form.appendChild(input_field); | |
1526 document.body.appendChild(form); | |
1527 | |
1528 setTimeout(function() { | |
1529 input_field.setCustomValidity('Custom validity message'); | |
1530 input_field.reportValidity(); | |
1531 }, | |
1532 0); | |
1533 )"; | |
1534 ASSERT_TRUE(ExecuteScript(web_contents, script)); | |
1535 bubble_delegate.WaitUntilShown(); | |
1536 | |
1537 // Navigate to another page and verify that the form validation bubble is | |
1538 // hidden. | |
1539 EXPECT_TRUE(NavigateToURL( | |
1540 shell(), embedded_test_server()->GetURL("b.com", "/title2.html"))); | |
1541 bubble_delegate.WaitUntilHidden(); | |
1542 } | |
1543 | |
1544 } // namespace content | 1470 } // namespace content |
OLD | NEW |