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

Side by Side Diff: chrome/browser/unload_browsertest.cc

Issue 10065041: Fix flakiness in unload browser test, take two. I was able to repro this on my Linux box (~10% of t… (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 years, 8 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #if defined(OS_POSIX) 5 #if defined(OS_POSIX)
6 #include <signal.h> 6 #include <signal.h>
7 #endif 7 #endif
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/process_util.h" 11 #include "base/process_util.h"
12 #include "base/utf_string_conversions.h" 12 #include "base/utf_string_conversions.h"
13 #include "chrome/browser/net/url_request_mock_util.h" 13 #include "chrome/browser/net/url_request_mock_util.h"
14 #include "chrome/browser/ui/app_modal_dialogs/js_modal_dialog.h" 14 #include "chrome/browser/ui/app_modal_dialogs/js_modal_dialog.h"
15 #include "chrome/browser/ui/app_modal_dialogs/native_app_modal_dialog.h" 15 #include "chrome/browser/ui/app_modal_dialogs/native_app_modal_dialog.h"
16 #include "chrome/browser/ui/browser.h" 16 #include "chrome/browser/ui/browser.h"
17 #include "chrome/browser/ui/browser_list.h" 17 #include "chrome/browser/ui/browser_list.h"
18 #include "chrome/common/chrome_notification_types.h" 18 #include "chrome/common/chrome_notification_types.h"
19 #include "chrome/common/chrome_switches.h" 19 #include "chrome/common/chrome_switches.h"
20 #include "chrome/test/base/in_process_browser_test.h" 20 #include "chrome/test/base/in_process_browser_test.h"
21 #include "chrome/test/base/ui_test_utils.h" 21 #include "chrome/test/base/ui_test_utils.h"
22 #include "content/public/browser/browser_thread.h" 22 #include "content/public/browser/browser_thread.h"
23 #include "content/public/browser/notification_service.h" 23 #include "content/public/browser/notification_service.h"
24 #include "content/public/browser/render_process_host.h"
25 #include "content/public/browser/web_contents.h" 24 #include "content/public/browser/web_contents.h"
26 #include "content/test/net/url_request_mock_http_job.h" 25 #include "content/test/net/url_request_mock_http_job.h"
27 #include "net/url_request/url_request_test_util.h" 26 #include "net/url_request/url_request_test_util.h"
28 27
29 using base::TimeDelta; 28 using base::TimeDelta;
30 using content::BrowserThread; 29 using content::BrowserThread;
31 30
32 const std::string NOLISTENERS_HTML = 31 const std::string NOLISTENERS_HTML =
33 "<html><head><title>nolisteners</title></head><body></body></html>"; 32 "<html><head><title>nolisteners</title></head><body></body></html>";
34 33
35 const std::string UNLOAD_HTML = 34 const std::string UNLOAD_HTML =
36 "<html><head><title>unload</title></head><body>" 35 "<html><head><title>unload</title></head><body>"
37 "<script>window.onunload=function(e){}</script></body></html>"; 36 "<script>window.onunload=function(e){}</script></body></html>";
38 37
39 const std::string BEFORE_UNLOAD_HTML = 38 const std::string BEFORE_UNLOAD_HTML =
40 "<html><head><title>beforeunload</title></head><body>" 39 "<html><head><title>beforeunload</title></head><body>"
41 "<script>window.onbeforeunload=function(e){return 'foo'}</script>" 40 "<script>window.onbeforeunload=function(e){"
41 "setTimeout('document.title=\"cancelled\"', 0);return 'foo'}</script>"
42 "</body></html>"; 42 "</body></html>";
43 43
44 const std::string INNER_FRAME_WITH_FOCUS_HTML = 44 const std::string INNER_FRAME_WITH_FOCUS_HTML =
45 "<html><head><title>innerframewithfocus</title></head><body>" 45 "<html><head><title>innerframewithfocus</title></head><body>"
46 "<script>window.onbeforeunload=function(e){return 'foo'}</script>" 46 "<script>window.onbeforeunload=function(e){return 'foo'}</script>"
47 "<iframe src=\"data:text/html,<html><head><script>window.onload=" 47 "<iframe src=\"data:text/html,<html><head><script>window.onload="
48 "function(){document.getElementById('box').focus()}</script>" 48 "function(){document.getElementById('box').focus()}</script>"
49 "<body><input id='box'></input></body></html>\"></iframe>" 49 "<body><input id='box'></input></body></html>\"></iframe>"
50 "</body></html>"; 50 "</body></html>";
51 51
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 127
128 void CheckTitle(const char* expected_title) { 128 void CheckTitle(const char* expected_title) {
129 string16 expected = ASCIIToUTF16(expected_title); 129 string16 expected = ASCIIToUTF16(expected_title);
130 EXPECT_EQ(expected, browser()->GetSelectedWebContents()->GetTitle()); 130 EXPECT_EQ(expected, browser()->GetSelectedWebContents()->GetTitle());
131 } 131 }
132 132
133 void NavigateToDataURL(const std::string& html_content, 133 void NavigateToDataURL(const std::string& html_content,
134 const char* expected_title) { 134 const char* expected_title) {
135 ui_test_utils::NavigateToURL(browser(), 135 ui_test_utils::NavigateToURL(browser(),
136 GURL("data:text/html," + html_content)); 136 GURL("data:text/html," + html_content));
137 content::RenderProcessHost* process =
138 browser()->GetSelectedWebContents()->GetRenderProcessHost();
139 if (html_content.find("unload=") != std::string::npos &&
140 process->SuddenTerminationAllowed()) {
141 LOG(INFO) << "Explicitly unsetting sudden termination because IPC didn't "
142 "arrive yet";
143 process->SetSuddenTerminationAllowed(false);
144 }
145 CheckTitle(expected_title); 137 CheckTitle(expected_title);
146 } 138 }
147 139
148 void NavigateToNolistenersFileTwice() { 140 void NavigateToNolistenersFileTwice() {
149 GURL url(URLRequestMockHTTPJob::GetMockUrl( 141 GURL url(URLRequestMockHTTPJob::GetMockUrl(
150 FilePath(FILE_PATH_LITERAL("title2.html")))); 142 FilePath(FILE_PATH_LITERAL("title2.html"))));
151 ui_test_utils::NavigateToURL(browser(), url); 143 ui_test_utils::NavigateToURL(browser(), url);
152 CheckTitle("Title Of Awesomeness"); 144 CheckTitle("Title Of Awesomeness");
153 ui_test_utils::NavigateToURL(browser(), url); 145 ui_test_utils::NavigateToURL(browser(), url);
154 CheckTitle("Title Of Awesomeness"); 146 CheckTitle("Title Of Awesomeness");
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
264 ui_test_utils::WindowedNotificationObserver window_observer( 256 ui_test_utils::WindowedNotificationObserver window_observer(
265 chrome::NOTIFICATION_BROWSER_CLOSED, 257 chrome::NOTIFICATION_BROWSER_CLOSED,
266 content::NotificationService::AllSources()); 258 content::NotificationService::AllSources());
267 browser()->CloseWindow(); 259 browser()->CloseWindow();
268 ClickModalDialogButton(true); 260 ClickModalDialogButton(true);
269 window_observer.Wait(); 261 window_observer.Wait();
270 } 262 }
271 263
272 // Tests closing the browser with a beforeunload handler and clicking 264 // Tests closing the browser with a beforeunload handler and clicking
273 // CANCEL in the beforeunload confirm dialog. 265 // CANCEL in the beforeunload confirm dialog.
274 // Test has been flakily timing-out: http://crbug.com/123110 266 // If this test flakes, reopen http://crbug.com/123110
275 IN_PROC_BROWSER_TEST_F(UnloadTest, DISABLED_BrowserCloseBeforeUnloadCancel) { 267 IN_PROC_BROWSER_TEST_F(UnloadTest, BrowserCloseBeforeUnloadCancel) {
276 NavigateToDataURL(BEFORE_UNLOAD_HTML, "beforeunload"); 268 NavigateToDataURL(BEFORE_UNLOAD_HTML, "beforeunload");
277 browser()->CloseWindow(); 269 browser()->CloseWindow();
270
271 // We wait for the title to change after cancelling the popup to ensure that
272 // in-flight IPCs from the renderer reach the browser. Otherwise the browser
273 // won't put up the beforeunload dialog because it's waiting for an ack from
274 // the renderer.
275 string16 expected_title = ASCIIToUTF16("cancelled");
276 ui_test_utils::TitleWatcher title_watcher(
277 browser()->GetSelectedWebContents(), expected_title);
278 ClickModalDialogButton(false); 278 ClickModalDialogButton(false);
279 279 ASSERT_EQ(expected_title, title_watcher.WaitAndGetTitle());
280 // There's no real graceful way to wait for something _not_ to happen.
281 ui_test_utils::RunAllPendingInMessageLoop();
282 280
283 ui_test_utils::WindowedNotificationObserver window_observer( 281 ui_test_utils::WindowedNotificationObserver window_observer(
284 chrome::NOTIFICATION_BROWSER_CLOSED, 282 chrome::NOTIFICATION_BROWSER_CLOSED,
285 content::NotificationService::AllSources()); 283 content::NotificationService::AllSources());
286 browser()->CloseWindow(); 284 browser()->CloseWindow();
287 ClickModalDialogButton(true); 285 ClickModalDialogButton(true);
288 window_observer.Wait(); 286 window_observer.Wait();
289 } 287 }
290 288
291 // Tests terminating the browser with a beforeunload handler. 289 // Tests terminating the browser with a beforeunload handler.
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
401 content::NOTIFICATION_TAB_CLOSED, 399 content::NOTIFICATION_TAB_CLOSED,
402 content::NotificationService::AllSources()); 400 content::NotificationService::AllSources());
403 browser()->CloseTab(); 401 browser()->CloseTab();
404 tab_close_observer.Wait(); 402 tab_close_observer.Wait();
405 403
406 CheckTitle("only_one_unload"); 404 CheckTitle("only_one_unload");
407 } 405 }
408 406
409 // TODO(ojan): Add tests for unload/beforeunload that have multiple tabs 407 // TODO(ojan): Add tests for unload/beforeunload that have multiple tabs
410 // and multiple windows. 408 // and multiple windows.
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698