summaryrefslogtreecommitdiffstats
path: root/chrome/browser/unload_browsertest.cc
diff options
context:
space:
mode:
authorjam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-04-13 18:33:37 +0000
committerjam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-04-13 18:33:37 +0000
commitc7287fa1cab3c83da135fcc795b4219bb3cfacdb (patch)
tree6ace101738f97b5697b437e9ecd184396727dda4 /chrome/browser/unload_browsertest.cc
parentae6b74f65f1969b5a2420532665eb65d9cee07fe (diff)
downloadchromium_src-c7287fa1cab3c83da135fcc795b4219bb3cfacdb.zip
chromium_src-c7287fa1cab3c83da135fcc795b4219bb3cfacdb.tar.gz
chromium_src-c7287fa1cab3c83da135fcc795b4219bb3cfacdb.tar.bz2
Fix flakiness in unload browser test, take two. I was able to repro this on my Linux box (~10% of the time). The issue turned out to be that the beforeunload ack from the renderer would sometimes come after the second time that we try to close the tab. The browser wouldn't put up the beforeunload prompt because it was waiting for the previous ack. The old ui test had a 10 second sleep here which masked this.
BUG=123110 Review URL: https://chromiumcodereview.appspot.com/10065041 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@132217 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/unload_browsertest.cc')
-rw-r--r--chrome/browser/unload_browsertest.cc28
1 files changed, 13 insertions, 15 deletions
diff --git a/chrome/browser/unload_browsertest.cc b/chrome/browser/unload_browsertest.cc
index 5a3e453..f60f01a 100644
--- a/chrome/browser/unload_browsertest.cc
+++ b/chrome/browser/unload_browsertest.cc
@@ -21,7 +21,6 @@
#include "chrome/test/base/ui_test_utils.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/notification_service.h"
-#include "content/public/browser/render_process_host.h"
#include "content/public/browser/web_contents.h"
#include "content/test/net/url_request_mock_http_job.h"
#include "net/url_request/url_request_test_util.h"
@@ -38,7 +37,8 @@ const std::string UNLOAD_HTML =
const std::string BEFORE_UNLOAD_HTML =
"<html><head><title>beforeunload</title></head><body>"
- "<script>window.onbeforeunload=function(e){return 'foo'}</script>"
+ "<script>window.onbeforeunload=function(e){"
+ "setTimeout('document.title=\"cancelled\"', 0);return 'foo'}</script>"
"</body></html>";
const std::string INNER_FRAME_WITH_FOCUS_HTML =
@@ -134,14 +134,6 @@ class UnloadTest : public InProcessBrowserTest {
const char* expected_title) {
ui_test_utils::NavigateToURL(browser(),
GURL("data:text/html," + html_content));
- content::RenderProcessHost* process =
- browser()->GetSelectedWebContents()->GetRenderProcessHost();
- if (html_content.find("unload=") != std::string::npos &&
- process->SuddenTerminationAllowed()) {
- LOG(INFO) << "Explicitly unsetting sudden termination because IPC didn't "
- "arrive yet";
- process->SetSuddenTerminationAllowed(false);
- }
CheckTitle(expected_title);
}
@@ -271,14 +263,20 @@ IN_PROC_BROWSER_TEST_F(UnloadTest, BrowserCloseBeforeUnloadOK) {
// Tests closing the browser with a beforeunload handler and clicking
// CANCEL in the beforeunload confirm dialog.
-// Test has been flakily timing-out: http://crbug.com/123110
-IN_PROC_BROWSER_TEST_F(UnloadTest, DISABLED_BrowserCloseBeforeUnloadCancel) {
+// If this test flakes, reopen http://crbug.com/123110
+IN_PROC_BROWSER_TEST_F(UnloadTest, BrowserCloseBeforeUnloadCancel) {
NavigateToDataURL(BEFORE_UNLOAD_HTML, "beforeunload");
browser()->CloseWindow();
- ClickModalDialogButton(false);
- // There's no real graceful way to wait for something _not_ to happen.
- ui_test_utils::RunAllPendingInMessageLoop();
+ // We wait for the title to change after cancelling the popup to ensure that
+ // in-flight IPCs from the renderer reach the browser. Otherwise the browser
+ // won't put up the beforeunload dialog because it's waiting for an ack from
+ // the renderer.
+ string16 expected_title = ASCIIToUTF16("cancelled");
+ ui_test_utils::TitleWatcher title_watcher(
+ browser()->GetSelectedWebContents(), expected_title);
+ ClickModalDialogButton(false);
+ ASSERT_EQ(expected_title, title_watcher.WaitAndGetTitle());
ui_test_utils::WindowedNotificationObserver window_observer(
chrome::NOTIFICATION_BROWSER_CLOSED,