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 1002 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1013 EXPECT_TRUE(ExecuteScript(shell(), "clickLinkSoon()")); | 1013 EXPECT_TRUE(ExecuteScript(shell(), "clickLinkSoon()")); |
1014 WaitForAppModalDialog(shell()); | 1014 WaitForAppModalDialog(shell()); |
1015 | 1015 |
1016 // Have the cross-site navigation commit. The main RenderFrameHost should | 1016 // Have the cross-site navigation commit. The main RenderFrameHost should |
1017 // still be loading after that. | 1017 // still be loading after that. |
1018 cross_site_delayer.WaitForNavigationFinished(); | 1018 cross_site_delayer.WaitForNavigationFinished(); |
1019 EXPECT_TRUE(shell()->web_contents()->IsLoading()); | 1019 EXPECT_TRUE(shell()->web_contents()->IsLoading()); |
1020 } | 1020 } |
1021 | 1021 |
1022 namespace { | 1022 namespace { |
| 1023 void NavigateToDataURLAndExpectBeforeUnload(Shell* shell, |
| 1024 const std::string& html, |
| 1025 bool expect_onbeforeunload) { |
| 1026 NavigateToURL(shell, GURL("data:text/html," + html)); |
| 1027 RenderFrameHostImpl* rfh = |
| 1028 static_cast<RenderFrameHostImpl*>(shell->web_contents()->GetMainFrame()); |
| 1029 EXPECT_EQ(expect_onbeforeunload, rfh->ShouldDispatchBeforeUnload()); |
| 1030 } |
| 1031 } // namespace |
| 1032 |
| 1033 IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest, NoOnBeforeUnload) { |
| 1034 const std::string NO_BEFORE_UNLOAD_HTML = "<html><body>foo</body></html>"; |
| 1035 NavigateToDataURLAndExpectBeforeUnload(shell(), NO_BEFORE_UNLOAD_HTML, false); |
| 1036 } |
| 1037 |
| 1038 IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest, OnBeforeUnload) { |
| 1039 const std::string BEFORE_UNLOAD_HTML = |
| 1040 "<html><body><script>window.onbeforeunload=function(e) {}</script>" |
| 1041 "</body></html>"; |
| 1042 NavigateToDataURLAndExpectBeforeUnload(shell(), BEFORE_UNLOAD_HTML, true); |
| 1043 } |
| 1044 |
| 1045 namespace { |
1023 | 1046 |
1024 class TestJavaScriptDialogManager : public JavaScriptDialogManager, | 1047 class TestJavaScriptDialogManager : public JavaScriptDialogManager, |
1025 public WebContentsDelegate { | 1048 public WebContentsDelegate { |
1026 public: | 1049 public: |
1027 TestJavaScriptDialogManager() : message_loop_runner_(new MessageLoopRunner) {} | 1050 TestJavaScriptDialogManager() : message_loop_runner_(new MessageLoopRunner) {} |
1028 ~TestJavaScriptDialogManager() override {} | 1051 ~TestJavaScriptDialogManager() override {} |
1029 | 1052 |
1030 void Wait() { | 1053 void Wait() { |
1031 message_loop_runner_->Run(); | 1054 message_loop_runner_->Run(); |
1032 message_loop_runner_ = new MessageLoopRunner; | 1055 message_loop_runner_ = new MessageLoopRunner; |
(...skipping 440 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1473 ASSERT_TRUE(saw_override); | 1496 ASSERT_TRUE(saw_override); |
1474 | 1497 |
1475 BrowserThread::PostTask( | 1498 BrowserThread::PostTask( |
1476 BrowserThread::IO, FROM_HERE, | 1499 BrowserThread::IO, FROM_HERE, |
1477 base::Bind(&ResourceDispatcherHost::SetDelegate, | 1500 base::Bind(&ResourceDispatcherHost::SetDelegate, |
1478 base::Unretained(ResourceDispatcherHostImpl::Get()), | 1501 base::Unretained(ResourceDispatcherHostImpl::Get()), |
1479 old_delegate)); | 1502 old_delegate)); |
1480 } | 1503 } |
1481 | 1504 |
1482 } // namespace content | 1505 } // namespace content |
OLD | NEW |