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