Chromium Code Reviews| 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 924 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 935 // still be loading after that. | 935 // still be loading after that. |
| 936 cross_site_delayer.WaitForNavigationFinished(); | 936 cross_site_delayer.WaitForNavigationFinished(); |
| 937 EXPECT_TRUE(shell()->web_contents()->IsLoading()); | 937 EXPECT_TRUE(shell()->web_contents()->IsLoading()); |
| 938 } | 938 } |
| 939 | 939 |
| 940 namespace { | 940 namespace { |
| 941 | 941 |
| 942 class TestJavaScriptDialogManager : public JavaScriptDialogManager, | 942 class TestJavaScriptDialogManager : public JavaScriptDialogManager, |
| 943 public WebContentsDelegate { | 943 public WebContentsDelegate { |
| 944 public: | 944 public: |
| 945 TestJavaScriptDialogManager() : message_loop_runner_(new MessageLoopRunner) {} | 945 TestJavaScriptDialogManager() |
| 946 : is_fullscreen_(false), message_loop_runner_(new MessageLoopRunner) {} | |
| 946 ~TestJavaScriptDialogManager() override {} | 947 ~TestJavaScriptDialogManager() override {} |
| 947 | 948 |
| 948 void Wait() { | 949 void Wait() { |
| 949 message_loop_runner_->Run(); | 950 message_loop_runner_->Run(); |
| 950 message_loop_runner_ = new MessageLoopRunner; | 951 message_loop_runner_ = new MessageLoopRunner; |
| 951 } | 952 } |
| 952 | 953 |
| 953 std::string last_message() { return last_message_; } | 954 std::string last_message() { return last_message_; } |
| 954 | 955 |
| 955 // WebContentsDelegate | 956 // WebContentsDelegate |
| 956 | 957 |
| 957 JavaScriptDialogManager* GetJavaScriptDialogManager( | 958 JavaScriptDialogManager* GetJavaScriptDialogManager( |
| 958 WebContents* source) override { | 959 WebContents* source) override { |
| 959 return this; | 960 return this; |
| 960 } | 961 } |
| 961 | 962 |
| 963 void EnterFullscreenModeForTab(WebContents* web_contents, | |
| 964 const GURL& origin) override { | |
| 965 is_fullscreen_ = true; | |
| 966 } | |
| 967 | |
| 968 void ExitFullscreenModeForTab(WebContents*) override { | |
| 969 is_fullscreen_ = false; | |
| 970 } | |
| 971 | |
| 972 bool IsFullscreenForTabOrPending( | |
| 973 const WebContents* web_contents) const override { | |
| 974 return is_fullscreen_; | |
| 975 } | |
| 976 | |
| 962 // JavaScriptDialogManager | 977 // JavaScriptDialogManager |
| 963 | 978 |
| 964 void RunJavaScriptDialog(WebContents* web_contents, | 979 void RunJavaScriptDialog(WebContents* web_contents, |
| 965 const GURL& origin_url, | 980 const GURL& origin_url, |
| 966 JavaScriptDialogType dialog_type, | 981 JavaScriptDialogType dialog_type, |
| 967 const base::string16& message_text, | 982 const base::string16& message_text, |
| 968 const base::string16& default_prompt_text, | 983 const base::string16& default_prompt_text, |
| 969 const DialogClosedCallback& callback, | 984 const DialogClosedCallback& callback, |
| 970 bool* did_suppress_message) override { | 985 bool* did_suppress_message) override { |
| 971 last_message_ = base::UTF16ToUTF8(message_text); | 986 last_message_ = base::UTF16ToUTF8(message_text); |
| 972 *did_suppress_message = true; | 987 *did_suppress_message = true; |
| 973 | 988 |
| 974 message_loop_runner_->Quit(); | 989 message_loop_runner_->Quit(); |
| 975 }; | 990 }; |
| 976 | 991 |
| 977 void RunBeforeUnloadDialog(WebContents* web_contents, | 992 void RunBeforeUnloadDialog(WebContents* web_contents, |
| 978 bool is_reload, | 993 bool is_reload, |
| 979 const DialogClosedCallback& callback) override {} | 994 const DialogClosedCallback& callback) override { |
| 995 callback.Run(true, base::string16()); | |
| 996 message_loop_runner_->Quit(); | |
| 997 } | |
| 980 | 998 |
| 981 bool HandleJavaScriptDialog(WebContents* web_contents, | 999 bool HandleJavaScriptDialog(WebContents* web_contents, |
| 982 bool accept, | 1000 bool accept, |
| 983 const base::string16* prompt_override) override { | 1001 const base::string16* prompt_override) override { |
| 984 return true; | 1002 return true; |
| 985 } | 1003 } |
| 986 | 1004 |
| 987 void CancelDialogs(WebContents* web_contents, | 1005 void CancelDialogs(WebContents* web_contents, |
| 988 bool reset_state) override {} | 1006 bool reset_state) override {} |
| 989 | 1007 |
| 990 private: | 1008 private: |
| 991 std::string last_message_; | 1009 std::string last_message_; |
| 992 | 1010 |
| 1011 bool is_fullscreen_; | |
| 1012 | |
| 993 // The MessageLoopRunner used to spin the message loop. | 1013 // The MessageLoopRunner used to spin the message loop. |
| 994 scoped_refptr<MessageLoopRunner> message_loop_runner_; | 1014 scoped_refptr<MessageLoopRunner> message_loop_runner_; |
| 995 | 1015 |
| 996 DISALLOW_COPY_AND_ASSIGN(TestJavaScriptDialogManager); | 1016 DISALLOW_COPY_AND_ASSIGN(TestJavaScriptDialogManager); |
| 997 }; | 1017 }; |
| 998 | 1018 |
| 999 } // namespace | 1019 } // namespace |
| 1000 | 1020 |
| 1001 IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest, | 1021 IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest, |
| 1002 JavaScriptDialogsInMainAndSubframes) { | 1022 JavaScriptDialogsInMainAndSubframes) { |
| (...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1388 tab_observer.Wait(); | 1408 tab_observer.Wait(); |
| 1389 ASSERT_TRUE(saw_override); | 1409 ASSERT_TRUE(saw_override); |
| 1390 | 1410 |
| 1391 BrowserThread::PostTask( | 1411 BrowserThread::PostTask( |
| 1392 BrowserThread::IO, FROM_HERE, | 1412 BrowserThread::IO, FROM_HERE, |
| 1393 base::Bind(&ResourceDispatcherHost::SetDelegate, | 1413 base::Bind(&ResourceDispatcherHost::SetDelegate, |
| 1394 base::Unretained(ResourceDispatcherHostImpl::Get()), | 1414 base::Unretained(ResourceDispatcherHostImpl::Get()), |
| 1395 old_delegate)); | 1415 old_delegate)); |
| 1396 } | 1416 } |
| 1397 | 1417 |
| 1418 IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest, | |
|
Matt Giuca
2017/06/09 06:16:37
Excellent tests, thanks.
Avi (use Gerrit)
2017/06/09 14:36:23
Acknowledged.
| |
| 1419 DialogsFromJavaScriptEndFullscreen) { | |
| 1420 WebContentsImpl* wc = static_cast<WebContentsImpl*>(shell()->web_contents()); | |
| 1421 TestJavaScriptDialogManager dialog_manager; | |
| 1422 wc->SetDelegate(&dialog_manager); | |
| 1423 | |
| 1424 GURL url("about:blank"); | |
| 1425 EXPECT_TRUE(NavigateToURL(shell(), url)); | |
| 1426 | |
| 1427 // alert | |
| 1428 wc->EnterFullscreenMode(url); | |
| 1429 EXPECT_TRUE(wc->IsFullscreenForCurrentTab()); | |
| 1430 std::string script = "alert('hi')"; | |
| 1431 EXPECT_TRUE(content::ExecuteScript(wc, script)); | |
| 1432 dialog_manager.Wait(); | |
| 1433 EXPECT_FALSE(wc->IsFullscreenForCurrentTab()); | |
| 1434 | |
| 1435 // confirm | |
| 1436 wc->EnterFullscreenMode(url); | |
| 1437 EXPECT_TRUE(wc->IsFullscreenForCurrentTab()); | |
| 1438 script = "confirm('hi')"; | |
| 1439 EXPECT_TRUE(content::ExecuteScript(wc, script)); | |
| 1440 dialog_manager.Wait(); | |
| 1441 EXPECT_FALSE(wc->IsFullscreenForCurrentTab()); | |
| 1442 | |
| 1443 // prompt | |
| 1444 wc->EnterFullscreenMode(url); | |
| 1445 EXPECT_TRUE(wc->IsFullscreenForCurrentTab()); | |
| 1446 script = "prompt('hi')"; | |
| 1447 EXPECT_TRUE(content::ExecuteScript(wc, script)); | |
| 1448 dialog_manager.Wait(); | |
| 1449 EXPECT_FALSE(wc->IsFullscreenForCurrentTab()); | |
| 1450 | |
| 1451 // beforeunload | |
| 1452 wc->EnterFullscreenMode(url); | |
| 1453 EXPECT_TRUE(wc->IsFullscreenForCurrentTab()); | |
| 1454 // Disable the hang monitor, otherwise there will be a race between the | |
|
Matt Giuca
2017/06/09 06:16:37
Nit: Replace the commas with parens: "(otherwise .
Avi (use Gerrit)
2017/06/09 14:36:23
Done.
| |
| 1455 // beforeunload dialog and the beforeunload hang timer, and give the page a | |
| 1456 // gesture to allow dialogs. | |
| 1457 wc->GetMainFrame()->DisableBeforeUnloadHangMonitorForTesting(); | |
| 1458 wc->GetMainFrame()->ExecuteJavaScriptWithUserGestureForTests( | |
| 1459 base::string16()); | |
| 1460 script = "window.onbeforeunload=function(e){return 'x'};"; | |
|
Matt Giuca
2017/06/09 06:16:37
nit: Insert spaces in the JavaScript for readabili
Avi (use Gerrit)
2017/06/09 14:36:23
Done.
Matt Giuca
2017/06/13 01:53:38
I meant also around the equals sign. And may as we
| |
| 1461 EXPECT_TRUE(content::ExecuteScript(wc, script)); | |
| 1462 EXPECT_TRUE(NavigateToURL(shell(), url)); | |
| 1463 dialog_manager.Wait(); | |
| 1464 EXPECT_FALSE(wc->IsFullscreenForCurrentTab()); | |
| 1465 | |
| 1466 wc->SetDelegate(nullptr); | |
| 1467 wc->SetJavaScriptDialogManagerForTesting(nullptr); | |
| 1468 } | |
| 1469 | |
| 1398 } // namespace content | 1470 } // namespace content |
| OLD | NEW |