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

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

Issue 10807047: Create content\public\test\test_utils.h to hold common test classes that are used by unit and brows… (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 years, 5 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 #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"
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 GURL url(URLRequestMockHTTPJob::GetMockUrl( 155 GURL url(URLRequestMockHTTPJob::GetMockUrl(
156 FilePath(FILE_PATH_LITERAL("title2.html")))); 156 FilePath(FILE_PATH_LITERAL("title2.html"))));
157 ui_test_utils::NavigateToURLWithDisposition(browser(), url, CURRENT_TAB, 0); 157 ui_test_utils::NavigateToURLWithDisposition(browser(), url, CURRENT_TAB, 0);
158 ui_test_utils::NavigateToURL(browser(), url); 158 ui_test_utils::NavigateToURL(browser(), url);
159 CheckTitle("Title Of Awesomeness"); 159 CheckTitle("Title Of Awesomeness");
160 } 160 }
161 161
162 void LoadUrlAndQuitBrowser(const std::string& html_content, 162 void LoadUrlAndQuitBrowser(const std::string& html_content,
163 const char* expected_title) { 163 const char* expected_title) {
164 NavigateToDataURL(html_content, expected_title); 164 NavigateToDataURL(html_content, expected_title);
165 ui_test_utils::WindowedNotificationObserver window_observer( 165 content::WindowedNotificationObserver window_observer(
166 chrome::NOTIFICATION_BROWSER_CLOSED, 166 chrome::NOTIFICATION_BROWSER_CLOSED,
167 content::NotificationService::AllSources()); 167 content::NotificationService::AllSources());
168 chrome::CloseWindow(browser()); 168 chrome::CloseWindow(browser());
169 window_observer.Wait(); 169 window_observer.Wait();
170 } 170 }
171 171
172 // If |accept| is true, simulates user clicking OK, otherwise simulates 172 // If |accept| is true, simulates user clicking OK, otherwise simulates
173 // clicking Cancel. 173 // clicking Cancel.
174 void ClickModalDialogButton(bool accept) { 174 void ClickModalDialogButton(bool accept) {
175 AppModalDialog* dialog = ui_test_utils::WaitForAppModalDialog(); 175 AppModalDialog* dialog = ui_test_utils::WaitForAppModalDialog();
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
248 // Test marked as flaky in http://crbug.com/51698 248 // Test marked as flaky in http://crbug.com/51698
249 IN_PROC_BROWSER_TEST_F(UnloadTest, DISABLED_BrowserCloseUnload) { 249 IN_PROC_BROWSER_TEST_F(UnloadTest, DISABLED_BrowserCloseUnload) {
250 LoadUrlAndQuitBrowser(UNLOAD_HTML, "unload"); 250 LoadUrlAndQuitBrowser(UNLOAD_HTML, "unload");
251 } 251 }
252 252
253 // Tests closing the browser with a beforeunload handler and clicking 253 // Tests closing the browser with a beforeunload handler and clicking
254 // OK in the beforeunload confirm dialog. 254 // OK in the beforeunload confirm dialog.
255 IN_PROC_BROWSER_TEST_F(UnloadTest, BrowserCloseBeforeUnloadOK) { 255 IN_PROC_BROWSER_TEST_F(UnloadTest, BrowserCloseBeforeUnloadOK) {
256 NavigateToDataURL(BEFORE_UNLOAD_HTML, "beforeunload"); 256 NavigateToDataURL(BEFORE_UNLOAD_HTML, "beforeunload");
257 257
258 ui_test_utils::WindowedNotificationObserver window_observer( 258 content::WindowedNotificationObserver window_observer(
259 chrome::NOTIFICATION_BROWSER_CLOSED, 259 chrome::NOTIFICATION_BROWSER_CLOSED,
260 content::NotificationService::AllSources()); 260 content::NotificationService::AllSources());
261 chrome::CloseWindow(browser()); 261 chrome::CloseWindow(browser());
262 ClickModalDialogButton(true); 262 ClickModalDialogButton(true);
263 window_observer.Wait(); 263 window_observer.Wait();
264 } 264 }
265 265
266 // Tests closing the browser with a beforeunload handler and clicking 266 // Tests closing the browser with a beforeunload handler and clicking
267 // CANCEL in the beforeunload confirm dialog. 267 // CANCEL in the beforeunload confirm dialog.
268 // If this test flakes, reopen http://crbug.com/123110 268 // If this test flakes, reopen http://crbug.com/123110
269 IN_PROC_BROWSER_TEST_F(UnloadTest, BrowserCloseBeforeUnloadCancel) { 269 IN_PROC_BROWSER_TEST_F(UnloadTest, BrowserCloseBeforeUnloadCancel) {
270 NavigateToDataURL(BEFORE_UNLOAD_HTML, "beforeunload"); 270 NavigateToDataURL(BEFORE_UNLOAD_HTML, "beforeunload");
271 chrome::CloseWindow(browser()); 271 chrome::CloseWindow(browser());
272 272
273 // We wait for the title to change after cancelling the popup to ensure that 273 // We wait for the title to change after cancelling the popup to ensure that
274 // in-flight IPCs from the renderer reach the browser. Otherwise the browser 274 // in-flight IPCs from the renderer reach the browser. Otherwise the browser
275 // won't put up the beforeunload dialog because it's waiting for an ack from 275 // won't put up the beforeunload dialog because it's waiting for an ack from
276 // the renderer. 276 // the renderer.
277 string16 expected_title = ASCIIToUTF16("cancelled"); 277 string16 expected_title = ASCIIToUTF16("cancelled");
278 ui_test_utils::TitleWatcher title_watcher( 278 ui_test_utils::TitleWatcher title_watcher(
279 chrome::GetActiveWebContents(browser()), expected_title); 279 chrome::GetActiveWebContents(browser()), expected_title);
280 ClickModalDialogButton(false); 280 ClickModalDialogButton(false);
281 ASSERT_EQ(expected_title, title_watcher.WaitAndGetTitle()); 281 ASSERT_EQ(expected_title, title_watcher.WaitAndGetTitle());
282 282
283 ui_test_utils::WindowedNotificationObserver window_observer( 283 content::WindowedNotificationObserver window_observer(
284 chrome::NOTIFICATION_BROWSER_CLOSED, 284 chrome::NOTIFICATION_BROWSER_CLOSED,
285 content::NotificationService::AllSources()); 285 content::NotificationService::AllSources());
286 chrome::CloseWindow(browser()); 286 chrome::CloseWindow(browser());
287 ClickModalDialogButton(true); 287 ClickModalDialogButton(true);
288 window_observer.Wait(); 288 window_observer.Wait();
289 } 289 }
290 290
291 // Tests terminating the browser with a beforeunload handler. 291 // Tests terminating the browser with a beforeunload handler.
292 // Currently only ChromeOS shuts down gracefully. 292 // Currently only ChromeOS shuts down gracefully.
293 #if defined(OS_CHROMEOS) 293 #if defined(OS_CHROMEOS)
294 IN_PROC_BROWSER_TEST_F(UnloadTest, BrowserTerminateBeforeUnload) { 294 IN_PROC_BROWSER_TEST_F(UnloadTest, BrowserTerminateBeforeUnload) {
295 NavigateToDataURL(BEFORE_UNLOAD_HTML, "beforeunload"); 295 NavigateToDataURL(BEFORE_UNLOAD_HTML, "beforeunload");
296 EXPECT_EQ(kill(base::GetCurrentProcessHandle(), SIGTERM), 0); 296 EXPECT_EQ(kill(base::GetCurrentProcessHandle(), SIGTERM), 0);
297 } 297 }
298 #endif 298 #endif
299 299
300 // Tests closing the browser and clicking OK in the beforeunload confirm dialog 300 // Tests closing the browser and clicking OK in the beforeunload confirm dialog
301 // if an inner frame has the focus. 301 // if an inner frame has the focus.
302 // If this flakes, use http://crbug.com/32615 and http://crbug.com/45675 302 // If this flakes, use http://crbug.com/32615 and http://crbug.com/45675
303 IN_PROC_BROWSER_TEST_F(UnloadTest, BrowserCloseWithInnerFocusedFrame) { 303 IN_PROC_BROWSER_TEST_F(UnloadTest, BrowserCloseWithInnerFocusedFrame) {
304 NavigateToDataURL(INNER_FRAME_WITH_FOCUS_HTML, "innerframewithfocus"); 304 NavigateToDataURL(INNER_FRAME_WITH_FOCUS_HTML, "innerframewithfocus");
305 305
306 ui_test_utils::WindowedNotificationObserver window_observer( 306 content::WindowedNotificationObserver window_observer(
307 chrome::NOTIFICATION_BROWSER_CLOSED, 307 chrome::NOTIFICATION_BROWSER_CLOSED,
308 content::NotificationService::AllSources()); 308 content::NotificationService::AllSources());
309 chrome::CloseWindow(browser()); 309 chrome::CloseWindow(browser());
310 ClickModalDialogButton(true); 310 ClickModalDialogButton(true);
311 window_observer.Wait(); 311 window_observer.Wait();
312 } 312 }
313 313
314 // Tests closing the browser with a beforeunload handler that takes 314 // Tests closing the browser with a beforeunload handler that takes
315 // two seconds to run. 315 // two seconds to run.
316 IN_PROC_BROWSER_TEST_F(UnloadTest, BrowserCloseTwoSecondBeforeUnload) { 316 IN_PROC_BROWSER_TEST_F(UnloadTest, BrowserCloseTwoSecondBeforeUnload) {
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
378 // unload handler, and the other doesn't, the tab that doesn't have an unload 378 // unload handler, and the other doesn't, the tab that doesn't have an unload
379 // handler can be closed. 379 // handler can be closed.
380 // If this flakes, see http://crbug.com/45162, http://crbug.com/45281 and 380 // If this flakes, see http://crbug.com/45162, http://crbug.com/45281 and
381 // http://crbug.com/86769. 381 // http://crbug.com/86769.
382 IN_PROC_BROWSER_TEST_F(UnloadTest, BrowserCloseTabWhenOtherTabHasListener) { 382 IN_PROC_BROWSER_TEST_F(UnloadTest, BrowserCloseTabWhenOtherTabHasListener) {
383 NavigateToDataURL(CLOSE_TAB_WHEN_OTHER_TAB_HAS_LISTENER, "only_one_unload"); 383 NavigateToDataURL(CLOSE_TAB_WHEN_OTHER_TAB_HAS_LISTENER, "only_one_unload");
384 384
385 // Simulate a click to force user_gesture to true; if we don't, the resulting 385 // Simulate a click to force user_gesture to true; if we don't, the resulting
386 // popup will be constrained, which isn't what we want to test. 386 // popup will be constrained, which isn't what we want to test.
387 387
388 ui_test_utils::WindowedNotificationObserver observer( 388 content::WindowedNotificationObserver observer(
389 chrome::NOTIFICATION_TAB_ADDED, 389 chrome::NOTIFICATION_TAB_ADDED,
390 content::NotificationService::AllSources()); 390 content::NotificationService::AllSources());
391 ui_test_utils::WindowedNotificationObserver load_stop_observer( 391 content::WindowedNotificationObserver load_stop_observer(
392 content::NOTIFICATION_LOAD_STOP, 392 content::NOTIFICATION_LOAD_STOP,
393 content::NotificationService::AllSources()); 393 content::NotificationService::AllSources());
394 ui_test_utils::SimulateMouseClick(chrome::GetActiveWebContents(browser())); 394 ui_test_utils::SimulateMouseClick(chrome::GetActiveWebContents(browser()));
395 observer.Wait(); 395 observer.Wait();
396 load_stop_observer.Wait(); 396 load_stop_observer.Wait();
397 CheckTitle("popup"); 397 CheckTitle("popup");
398 398
399 ui_test_utils::WindowedNotificationObserver tab_close_observer( 399 content::WindowedNotificationObserver tab_close_observer(
400 content::NOTIFICATION_WEB_CONTENTS_DESTROYED, 400 content::NOTIFICATION_WEB_CONTENTS_DESTROYED,
401 content::NotificationService::AllSources()); 401 content::NotificationService::AllSources());
402 chrome::CloseTab(browser()); 402 chrome::CloseTab(browser());
403 tab_close_observer.Wait(); 403 tab_close_observer.Wait();
404 404
405 CheckTitle("only_one_unload"); 405 CheckTitle("only_one_unload");
406 } 406 }
407 407
408 // TODO(ojan): Add tests for unload/beforeunload that have multiple tabs 408 // TODO(ojan): Add tests for unload/beforeunload that have multiple tabs
409 // and multiple windows. 409 // and multiple windows.
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/print_preview/print_preview_ui_browsertest.cc ('k') | chrome/test/base/in_process_browser_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698