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 1001 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1012 SetShouldProceedOnBeforeUnload(shell(), false); | 1012 SetShouldProceedOnBeforeUnload(shell(), false); |
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 { |
| 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 |
1022 IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest, NoOnBeforeUnload) { | 1033 IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest, NoOnBeforeUnload) { |
1023 ASSERT_TRUE(embedded_test_server()->Start()); | 1034 const std::string NO_BEFORE_UNLOAD_HTML = "<html><body>foo</body></html>"; |
1024 GURL url = embedded_test_server()->GetURL("/simple_page.html"); | 1035 NavigateToDataURLAndExpectBeforeUnload(shell(), NO_BEFORE_UNLOAD_HTML, false); |
1025 NavigateToURL(shell(), url); | |
1026 RenderFrameHostImpl* rfh = static_cast<RenderFrameHostImpl*>( | |
1027 shell()->web_contents()->GetMainFrame()); | |
1028 EXPECT_FALSE(rfh->ShouldDispatchBeforeUnload()); | |
1029 } | 1036 } |
1030 | 1037 |
1031 IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest, OnBeforeUnload) { | 1038 IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest, OnBeforeUnload) { |
1032 ASSERT_TRUE(embedded_test_server()->Start()); | 1039 const std::string BEFORE_UNLOAD_HTML = |
1033 GURL url = | 1040 "<html><body><script>window.onbeforeunload=function(e) {}</script>" |
1034 embedded_test_server()->GetURL("/page_with_empty_beforeunload.html"); | 1041 "</body></html>"; |
1035 NavigateToURL(shell(), url); | 1042 NavigateToDataURLAndExpectBeforeUnload(shell(), BEFORE_UNLOAD_HTML, true); |
1036 RenderFrameHostImpl* rfh = static_cast<RenderFrameHostImpl*>( | |
1037 shell()->web_contents()->GetMainFrame()); | |
1038 EXPECT_TRUE(rfh->ShouldDispatchBeforeUnload()); | |
1039 } | 1043 } |
1040 | 1044 |
1041 namespace { | 1045 namespace { |
1042 | 1046 |
1043 class TestJavaScriptDialogManager : public JavaScriptDialogManager, | 1047 class TestJavaScriptDialogManager : public JavaScriptDialogManager, |
1044 public WebContentsDelegate { | 1048 public WebContentsDelegate { |
1045 public: | 1049 public: |
1046 TestJavaScriptDialogManager() : message_loop_runner_(new MessageLoopRunner) {} | 1050 TestJavaScriptDialogManager() : message_loop_runner_(new MessageLoopRunner) {} |
1047 ~TestJavaScriptDialogManager() override {} | 1051 ~TestJavaScriptDialogManager() override {} |
1048 | 1052 |
(...skipping 443 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1492 ASSERT_TRUE(saw_override); | 1496 ASSERT_TRUE(saw_override); |
1493 | 1497 |
1494 BrowserThread::PostTask( | 1498 BrowserThread::PostTask( |
1495 BrowserThread::IO, FROM_HERE, | 1499 BrowserThread::IO, FROM_HERE, |
1496 base::Bind(&ResourceDispatcherHost::SetDelegate, | 1500 base::Bind(&ResourceDispatcherHost::SetDelegate, |
1497 base::Unretained(ResourceDispatcherHostImpl::Get()), | 1501 base::Unretained(ResourceDispatcherHostImpl::Get()), |
1498 old_delegate)); | 1502 old_delegate)); |
1499 } | 1503 } |
1500 | 1504 |
1501 } // namespace content | 1505 } // namespace content |
OLD | NEW |