Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(287)

Side by Side Diff: chrome/browser/ui/browser_browsertest.cc

Issue 25434002: Don't leave renderer process frozen when canceling JavaScript dialogs. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove WebContentsObserver Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 <string> 5 #include <string>
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/compiler_specific.h" 9 #include "base/compiler_specific.h"
10 #include "base/files/file_path.h" 10 #include "base/files/file_path.h"
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 public: 224 public:
225 TestInterstitialPage(WebContents* tab, bool new_navigation, const GURL& url) { 225 TestInterstitialPage(WebContents* tab, bool new_navigation, const GURL& url) {
226 interstitial_page_ = InterstitialPage::Create( 226 interstitial_page_ = InterstitialPage::Create(
227 tab, new_navigation, url , this); 227 tab, new_navigation, url , this);
228 interstitial_page_->Show(); 228 interstitial_page_->Show();
229 } 229 }
230 virtual ~TestInterstitialPage() { } 230 virtual ~TestInterstitialPage() { }
231 void Proceed() { 231 void Proceed() {
232 interstitial_page_->Proceed(); 232 interstitial_page_->Proceed();
233 } 233 }
234 void DontProceed() {
235 interstitial_page_->DontProceed();
236 }
234 237
235 virtual std::string GetHTMLContents() OVERRIDE { 238 virtual std::string GetHTMLContents() OVERRIDE {
236 return "<h1>INTERSTITIAL</h1>"; 239 return "<h1>INTERSTITIAL</h1>";
237 } 240 }
238 241
239 private: 242 private:
240 InterstitialPage* interstitial_page_; // Owns us. 243 InterstitialPage* interstitial_page_; // Owns us.
241 }; 244 };
242 245
243 class RenderViewSizeObserver : public content::WebContentsObserver { 246 class RenderViewSizeObserver : public content::WebContentsObserver {
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
453 #else 456 #else
454 25; 457 25;
455 #endif 458 #endif
456 if (base::SysInfo::AmountOfPhysicalMemoryMB() >= 2048) { 459 if (base::SysInfo::AmountOfPhysicalMemoryMB() >= 2048) {
457 EXPECT_GE(CountRenderProcessHosts(), kExpectedProcessCount); 460 EXPECT_GE(CountRenderProcessHosts(), kExpectedProcessCount);
458 } else { 461 } else {
459 EXPECT_LT(CountRenderProcessHosts(), kExpectedProcessCount); 462 EXPECT_LT(CountRenderProcessHosts(), kExpectedProcessCount);
460 } 463 }
461 } 464 }
462 465
466 // Test for crbug.com/297289. Ensure that modal dialogs are closed when a
467 // cross-process navigation is ready to commit.
468 IN_PROC_BROWSER_TEST_F(BrowserTest, CrossProcessNavCancelsDialogs) {
469 ASSERT_TRUE(test_server()->Start());
470 host_resolver()->AddRule("www.example.com", "127.0.0.1");
471 GURL url(test_server()->GetURL("empty.html"));
472 ui_test_utils::NavigateToURL(browser(), url);
473
474 WebContents* contents = browser()->tab_strip_model()->GetActiveWebContents();
475 contents->GetRenderViewHost()->ExecuteJavascriptInWebFrame(
476 string16(),
477 ASCIIToUTF16("alert('Dialog showing!');"));
478 AppModalDialog* alert = ui_test_utils::WaitForAppModalDialog();
479 EXPECT_TRUE(alert->IsValid());
480 AppModalDialogQueue* dialog_queue = AppModalDialogQueue::GetInstance();
481 EXPECT_TRUE(dialog_queue->HasActiveDialog());
482
483 // A cross-site navigation should force the dialog to close.
484 GURL url2("http://www.example.com/empty.html");
485 ui_test_utils::NavigateToURL(browser(), url2);
486 EXPECT_FALSE(dialog_queue->HasActiveDialog());
487
488 // Make sure input events still work in the renderer process.
489 EXPECT_FALSE(contents->GetRenderProcessHost()->IgnoreInputEvents());
490 }
491
463 // Test for crbug.com/22004. Reloading a page with a before unload handler and 492 // Test for crbug.com/22004. Reloading a page with a before unload handler and
464 // then canceling the dialog should not leave the throbber spinning. 493 // then canceling the dialog should not leave the throbber spinning.
465 IN_PROC_BROWSER_TEST_F(BrowserTest, ReloadThenCancelBeforeUnload) { 494 IN_PROC_BROWSER_TEST_F(BrowserTest, ReloadThenCancelBeforeUnload) {
466 GURL url(std::string("data:text/html,") + kBeforeUnloadHTML); 495 GURL url(std::string("data:text/html,") + kBeforeUnloadHTML);
467 ui_test_utils::NavigateToURL(browser(), url); 496 ui_test_utils::NavigateToURL(browser(), url);
468 497
469 // Navigate to another page, but click cancel in the dialog. Make sure that 498 // Navigate to another page, but click cancel in the dialog. Make sure that
470 // the throbber stops spinning. 499 // the throbber stops spinning.
471 chrome::Reload(browser(), CURRENT_TAB); 500 chrome::Reload(browser(), CURRENT_TAB);
472 AppModalDialog* alert = ui_test_utils::WaitForAppModalDialog(); 501 AppModalDialog* alert = ui_test_utils::WaitForAppModalDialog();
(...skipping 1247 matching lines...) Expand 10 before | Expand all | Expand 10 after
1720 EXPECT_TRUE(contents->ShowingInterstitialPage()); 1749 EXPECT_TRUE(contents->ShowingInterstitialPage());
1721 EXPECT_FALSE(dialog_queue->HasActiveDialog()); 1750 EXPECT_FALSE(dialog_queue->HasActiveDialog());
1722 1751
1723 { 1752 {
1724 scoped_refptr<content::MessageLoopRunner> loop_runner( 1753 scoped_refptr<content::MessageLoopRunner> loop_runner(
1725 new content::MessageLoopRunner); 1754 new content::MessageLoopRunner);
1726 1755
1727 InterstitialObserver observer(contents, 1756 InterstitialObserver observer(contents,
1728 base::Closure(), 1757 base::Closure(),
1729 loop_runner->QuitClosure()); 1758 loop_runner->QuitClosure());
1730 interstitial->Proceed(); 1759 interstitial->DontProceed();
1731 loop_runner->Run(); 1760 loop_runner->Run();
1732 // interstitial is deleted now. 1761 // interstitial is deleted now.
1733 } 1762 }
1763
1764 // Make sure input events still work in the renderer process.
1765 EXPECT_FALSE(contents->GetRenderProcessHost()->IgnoreInputEvents());
1734 } 1766 }
1735 1767
1736 1768
1737 IN_PROC_BROWSER_TEST_F(BrowserTest, InterstitialCloseTab) { 1769 IN_PROC_BROWSER_TEST_F(BrowserTest, InterstitialCloseTab) {
1738 WebContents* contents = browser()->tab_strip_model()->GetActiveWebContents(); 1770 WebContents* contents = browser()->tab_strip_model()->GetActiveWebContents();
1739 1771
1740 { 1772 {
1741 scoped_refptr<content::MessageLoopRunner> loop_runner( 1773 scoped_refptr<content::MessageLoopRunner> loop_runner(
1742 new content::MessageLoopRunner); 1774 new content::MessageLoopRunner);
1743 1775
(...skipping 729 matching lines...) Expand 10 before | Expand all | Expand 10 after
2473 exp_commit_size.Enlarge(wcv_resize_insets.width(), 2505 exp_commit_size.Enlarge(wcv_resize_insets.width(),
2474 wcv_resize_insets.height() + height_inset); 2506 wcv_resize_insets.height() + height_inset);
2475 EXPECT_EQ(exp_commit_size, rwhv_commit_size2); 2507 EXPECT_EQ(exp_commit_size, rwhv_commit_size2);
2476 EXPECT_EQ(exp_commit_size, wcv_commit_size2); 2508 EXPECT_EQ(exp_commit_size, wcv_commit_size2);
2477 // Sizes of RenderWidgetHostView and WebContentsView before and after 2509 // Sizes of RenderWidgetHostView and WebContentsView before and after
2478 // WebContentsDelegate::DidNavigateMainFramePostCommit should be the same. 2510 // WebContentsDelegate::DidNavigateMainFramePostCommit should be the same.
2479 EXPECT_EQ(rwhv_commit_size2, 2511 EXPECT_EQ(rwhv_commit_size2,
2480 web_contents->GetRenderWidgetHostView()->GetViewBounds().size()); 2512 web_contents->GetRenderWidgetHostView()->GetViewBounds().size());
2481 EXPECT_EQ(wcv_commit_size2, web_contents->GetView()->GetContainerSize()); 2513 EXPECT_EQ(wcv_commit_size2, web_contents->GetView()->GetContainerSize());
2482 } 2514 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698