Chromium Code Reviews| Index: chrome/browser/ui/browser_browsertest.cc |
| diff --git a/chrome/browser/ui/browser_browsertest.cc b/chrome/browser/ui/browser_browsertest.cc |
| index 1226efd341b089e4af173fb084508771496ff653..c90e60dfe756161d7bd061625ee199eb2bd65bde 100644 |
| --- a/chrome/browser/ui/browser_browsertest.cc |
| +++ b/chrome/browser/ui/browser_browsertest.cc |
| @@ -83,6 +83,7 @@ |
| #include "content/public/browser/interstitial_page.h" |
| #include "content/public/browser/interstitial_page_delegate.h" |
| #include "content/public/browser/navigation_entry.h" |
| +#include "content/public/browser/navigation_handle.h" |
| #include "content/public/browser/notification_service.h" |
| #include "content/public/browser/reload_type.h" |
| #include "content/public/browser/render_frame_host.h" |
| @@ -94,6 +95,7 @@ |
| #include "content/public/browser/ssl_status.h" |
| #include "content/public/browser/web_contents.h" |
| #include "content/public/browser/web_contents_observer.h" |
| +#include "content/public/common/browser_side_navigation_policy.h" |
| #include "content/public/common/frame_navigate_params.h" |
| #include "content/public/common/renderer_preferences.h" |
| #include "content/public/common/url_constants.h" |
| @@ -332,6 +334,24 @@ class RenderViewSizeObserver : public content::WebContentsObserver { |
| DISALLOW_COPY_AND_ASSIGN(RenderViewSizeObserver); |
| }; |
| +// Waits for a failed commit notification. |
| +class FailedCommitWatcher : public content::WebContentsObserver { |
| +public: |
| + explicit FailedCommitWatcher(content::WebContents* wc) |
| + : content::WebContentsObserver(wc) {} |
| + void Wait() { |
| + run_loop_.Run(); |
| + } |
| + |
| + private: |
| + void DidFinishNavigation( |
| + content::NavigationHandle* navigation_handle) override { |
| + CHECK(!navigation_handle->HasCommitted()); |
| + run_loop_.Quit(); |
| + } |
| + base::RunLoop run_loop_; |
| +}; |
| + |
| } // namespace |
| class BrowserTest : public ExtensionBrowserTest { |
| @@ -672,7 +692,12 @@ IN_PROC_BROWSER_TEST_F(BrowserTest, ReloadThenCancelBeforeUnload) { |
| // the throbber stops spinning. |
| chrome::Reload(browser(), WindowOpenDisposition::CURRENT_TAB); |
| AppModalDialog* alert = ui_test_utils::WaitForAppModalDialog(); |
| + |
| + FailedCommitWatcher watcher( |
| + browser()->tab_strip_model()->GetActiveWebContents()); |
| alert->CloseModalDialog(); |
| + if (content::IsBrowserSideNavigationEnabled()) |
| + watcher.Wait(); |
| EXPECT_FALSE( |
| browser()->tab_strip_model()->GetActiveWebContents()->IsLoading()); |
| @@ -824,7 +849,11 @@ IN_PROC_BROWSER_TEST_F(BrowserTest, CancelBeforeUnloadResetsURL) { |
| // Cancel the dialog. |
| AppModalDialog* alert = ui_test_utils::WaitForAppModalDialog(); |
| + FailedCommitWatcher watcher( |
| + browser()->tab_strip_model()->GetActiveWebContents()); |
| alert->CloseModalDialog(); |
| + if (content::IsBrowserSideNavigationEnabled()) |
| + watcher.Wait(); |
| EXPECT_FALSE( |
| browser()->tab_strip_model()->GetActiveWebContents()->IsLoading()); |
| @@ -893,8 +922,14 @@ IN_PROC_BROWSER_TEST_F(BrowserTest, MAYBE_BeforeUnloadVsBeforeReload) { |
| AppModalDialog* alert = ui_test_utils::WaitForAppModalDialog(); |
| EXPECT_TRUE(static_cast<JavaScriptAppModalDialog*>(alert)->is_reload()); |
| - // Cancel the reload. |
| + // Cancel the reload. Wait for the ack from the renderer because the OpenURL |
| + // call below tries to put up an unload dialog synchronously in the |
|
Charlie Reis
2016/09/30 17:36:10
nit: a beforeunload dialog
Also, I'm curious abou
jam
2016/09/30 22:42:07
I don't actually remember why I wrote it that way.
|
| + // PlzNavigate case. |
| + FailedCommitWatcher watcher( |
| + browser()->tab_strip_model()->GetActiveWebContents()); |
| alert->native_dialog()->CancelAppModalDialog(); |
| + if (content::IsBrowserSideNavigationEnabled()) |
| + watcher.Wait(); |
| // Navigate to another url, and check that we get a "before unload" dialog. |
| GURL url2(url::kAboutBlankURL); |