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

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

Issue 816403003: Make callers of CommandLine use it via the base:: namespace. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix Created 5 years, 12 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
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 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 106
107 const std::string CLOSE_TAB_WHEN_OTHER_TAB_HAS_LISTENER = 107 const std::string CLOSE_TAB_WHEN_OTHER_TAB_HAS_LISTENER =
108 "<html><head><title>only_one_unload</title></head>" 108 "<html><head><title>only_one_unload</title></head>"
109 "<body onclick=\"window.open('data:text/html," 109 "<body onclick=\"window.open('data:text/html,"
110 "<html><head><title>popup</title></head></body>')\" " 110 "<html><head><title>popup</title></head></body>')\" "
111 "onbeforeunload='return;'>" 111 "onbeforeunload='return;'>"
112 "</body></html>"; 112 "</body></html>";
113 113
114 class UnloadTest : public InProcessBrowserTest { 114 class UnloadTest : public InProcessBrowserTest {
115 public: 115 public:
116 void SetUpCommandLine(CommandLine* command_line) override { 116 void SetUpCommandLine(base::CommandLine* command_line) override {
117 const testing::TestInfo* const test_info = 117 const testing::TestInfo* const test_info =
118 testing::UnitTest::GetInstance()->current_test_info(); 118 testing::UnitTest::GetInstance()->current_test_info();
119 if (strcmp(test_info->name(), 119 if (strcmp(test_info->name(),
120 "BrowserCloseTabWhenOtherTabHasListener") == 0) { 120 "BrowserCloseTabWhenOtherTabHasListener") == 0) {
121 command_line->AppendSwitch(switches::kDisablePopupBlocking); 121 command_line->AppendSwitch(switches::kDisablePopupBlocking);
122 } else if (strcmp(test_info->name(), "BrowserTerminateBeforeUnload") == 0) { 122 } else if (strcmp(test_info->name(), "BrowserTerminateBeforeUnload") == 0) {
123 #if defined(OS_POSIX) 123 #if defined(OS_POSIX)
124 DisableSIGTERMHandling(); 124 DisableSIGTERMHandling();
125 #endif 125 #endif
126 } 126 }
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 } 189 }
190 }; 190 };
191 191
192 // Navigate to a page with an infinite unload handler. 192 // Navigate to a page with an infinite unload handler.
193 // Then two async crosssite requests to ensure 193 // Then two async crosssite requests to ensure
194 // we don't get confused and think we're closing the tab. 194 // we don't get confused and think we're closing the tab.
195 // 195 //
196 // This test is flaky on the valgrind UI bots. http://crbug.com/39057 196 // This test is flaky on the valgrind UI bots. http://crbug.com/39057
197 IN_PROC_BROWSER_TEST_F(UnloadTest, CrossSiteInfiniteUnloadAsync) { 197 IN_PROC_BROWSER_TEST_F(UnloadTest, CrossSiteInfiniteUnloadAsync) {
198 // Tests makes no sense in single-process mode since the renderer is hung. 198 // Tests makes no sense in single-process mode since the renderer is hung.
199 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kSingleProcess)) 199 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
200 switches::kSingleProcess))
200 return; 201 return;
201 202
202 NavigateToDataURL(INFINITE_UNLOAD_HTML, "infiniteunload"); 203 NavigateToDataURL(INFINITE_UNLOAD_HTML, "infiniteunload");
203 // Must navigate to a non-data URL to trigger cross-site codepath. 204 // Must navigate to a non-data URL to trigger cross-site codepath.
204 NavigateToNolistenersFileTwiceAsync(); 205 NavigateToNolistenersFileTwiceAsync();
205 } 206 }
206 207
207 // Navigate to a page with an infinite unload handler. 208 // Navigate to a page with an infinite unload handler.
208 // Then two sync crosssite requests to ensure 209 // Then two sync crosssite requests to ensure
209 // we correctly nav to each one. 210 // we correctly nav to each one.
210 IN_PROC_BROWSER_TEST_F(UnloadTest, CrossSiteInfiniteUnloadSync) { 211 IN_PROC_BROWSER_TEST_F(UnloadTest, CrossSiteInfiniteUnloadSync) {
211 // Tests makes no sense in single-process mode since the renderer is hung. 212 // Tests makes no sense in single-process mode since the renderer is hung.
212 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kSingleProcess)) 213 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
214 switches::kSingleProcess))
213 return; 215 return;
214 216
215 NavigateToDataURL(INFINITE_UNLOAD_HTML, "infiniteunload"); 217 NavigateToDataURL(INFINITE_UNLOAD_HTML, "infiniteunload");
216 // Must navigate to a non-data URL to trigger cross-site codepath. 218 // Must navigate to a non-data URL to trigger cross-site codepath.
217 NavigateToNolistenersFileTwice(); 219 NavigateToNolistenersFileTwice();
218 } 220 }
219 221
220 // Navigate to a page with an infinite beforeunload handler. 222 // Navigate to a page with an infinite beforeunload handler.
221 // Then two two async crosssite requests to ensure 223 // Then two two async crosssite requests to ensure
222 // we don't get confused and think we're closing the tab. 224 // we don't get confused and think we're closing the tab.
223 // This test is flaky on the valgrind UI bots. http://crbug.com/39057 and 225 // This test is flaky on the valgrind UI bots. http://crbug.com/39057 and
224 // http://crbug.com/86469 226 // http://crbug.com/86469
225 IN_PROC_BROWSER_TEST_F(UnloadTest, CrossSiteInfiniteBeforeUnloadAsync) { 227 IN_PROC_BROWSER_TEST_F(UnloadTest, CrossSiteInfiniteBeforeUnloadAsync) {
226 // Tests makes no sense in single-process mode since the renderer is hung. 228 // Tests makes no sense in single-process mode since the renderer is hung.
227 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kSingleProcess)) 229 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
230 switches::kSingleProcess))
228 return; 231 return;
229 232
230 NavigateToDataURL(INFINITE_BEFORE_UNLOAD_HTML, "infinitebeforeunload"); 233 NavigateToDataURL(INFINITE_BEFORE_UNLOAD_HTML, "infinitebeforeunload");
231 // Must navigate to a non-data URL to trigger cross-site codepath. 234 // Must navigate to a non-data URL to trigger cross-site codepath.
232 NavigateToNolistenersFileTwiceAsync(); 235 NavigateToNolistenersFileTwiceAsync();
233 } 236 }
234 237
235 // Navigate to a page with an infinite beforeunload handler. 238 // Navigate to a page with an infinite beforeunload handler.
236 // Then two two sync crosssite requests to ensure 239 // Then two two sync crosssite requests to ensure
237 // we correctly nav to each one. 240 // we correctly nav to each one.
238 // If this flakes, see bug http://crbug.com/86469. 241 // If this flakes, see bug http://crbug.com/86469.
239 IN_PROC_BROWSER_TEST_F(UnloadTest, CrossSiteInfiniteBeforeUnloadSync) { 242 IN_PROC_BROWSER_TEST_F(UnloadTest, CrossSiteInfiniteBeforeUnloadSync) {
240 // Tests makes no sense in single-process mode since the renderer is hung. 243 // Tests makes no sense in single-process mode since the renderer is hung.
241 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kSingleProcess)) 244 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
245 switches::kSingleProcess))
242 return; 246 return;
243 247
244 NavigateToDataURL(INFINITE_BEFORE_UNLOAD_HTML, "infinitebeforeunload"); 248 NavigateToDataURL(INFINITE_BEFORE_UNLOAD_HTML, "infinitebeforeunload");
245 // Must navigate to a non-data URL to trigger cross-site codepath. 249 // Must navigate to a non-data URL to trigger cross-site codepath.
246 NavigateToNolistenersFileTwice(); 250 NavigateToNolistenersFileTwice();
247 } 251 }
248 252
249 // Tests closing the browser on a page with no unload listeners registered. 253 // Tests closing the browser on a page with no unload listeners registered.
250 IN_PROC_BROWSER_TEST_F(UnloadTest, BrowserCloseNoUnloadListeners) { 254 IN_PROC_BROWSER_TEST_F(UnloadTest, BrowserCloseNoUnloadListeners) {
251 LoadUrlAndQuitBrowser(NOLISTENERS_HTML, "nolisteners"); 255 LoadUrlAndQuitBrowser(NOLISTENERS_HTML, "nolisteners");
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
322 // two seconds to run. 326 // two seconds to run.
323 IN_PROC_BROWSER_TEST_F(UnloadTest, BrowserCloseTwoSecondBeforeUnload) { 327 IN_PROC_BROWSER_TEST_F(UnloadTest, BrowserCloseTwoSecondBeforeUnload) {
324 LoadUrlAndQuitBrowser(TWO_SECOND_BEFORE_UNLOAD_HTML, 328 LoadUrlAndQuitBrowser(TWO_SECOND_BEFORE_UNLOAD_HTML,
325 "twosecondbeforeunload"); 329 "twosecondbeforeunload");
326 } 330 }
327 331
328 // Tests closing the browser on a page with an unload listener registered where 332 // Tests closing the browser on a page with an unload listener registered where
329 // the unload handler has an infinite loop. 333 // the unload handler has an infinite loop.
330 IN_PROC_BROWSER_TEST_F(UnloadTest, BrowserCloseInfiniteUnload) { 334 IN_PROC_BROWSER_TEST_F(UnloadTest, BrowserCloseInfiniteUnload) {
331 // Tests makes no sense in single-process mode since the renderer is hung. 335 // Tests makes no sense in single-process mode since the renderer is hung.
332 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kSingleProcess)) 336 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
337 switches::kSingleProcess))
333 return; 338 return;
334 339
335 LoadUrlAndQuitBrowser(INFINITE_UNLOAD_HTML, "infiniteunload"); 340 LoadUrlAndQuitBrowser(INFINITE_UNLOAD_HTML, "infiniteunload");
336 } 341 }
337 342
338 // Tests closing the browser with a beforeunload handler that hangs. 343 // Tests closing the browser with a beforeunload handler that hangs.
339 // If this flakes, use http://crbug.com/78803 and http://crbug.com/86469 344 // If this flakes, use http://crbug.com/78803 and http://crbug.com/86469
340 IN_PROC_BROWSER_TEST_F(UnloadTest, DISABLED_BrowserCloseInfiniteBeforeUnload) { 345 IN_PROC_BROWSER_TEST_F(UnloadTest, DISABLED_BrowserCloseInfiniteBeforeUnload) {
341 // Tests makes no sense in single-process mode since the renderer is hung. 346 // Tests makes no sense in single-process mode since the renderer is hung.
342 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kSingleProcess)) 347 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
348 switches::kSingleProcess))
343 return; 349 return;
344 350
345 LoadUrlAndQuitBrowser(INFINITE_BEFORE_UNLOAD_HTML, "infinitebeforeunload"); 351 LoadUrlAndQuitBrowser(INFINITE_BEFORE_UNLOAD_HTML, "infinitebeforeunload");
346 } 352 }
347 353
348 // Tests closing the browser on a page with an unload listener registered where 354 // Tests closing the browser on a page with an unload listener registered where
349 // the unload handler has an infinite loop followed by an alert. 355 // the unload handler has an infinite loop followed by an alert.
350 // If this flakes, use http://crbug.com/86469 356 // If this flakes, use http://crbug.com/86469
351 IN_PROC_BROWSER_TEST_F(UnloadTest, BrowserCloseInfiniteUnloadAlert) { 357 IN_PROC_BROWSER_TEST_F(UnloadTest, BrowserCloseInfiniteUnloadAlert) {
352 // Tests makes no sense in single-process mode since the renderer is hung. 358 // Tests makes no sense in single-process mode since the renderer is hung.
353 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kSingleProcess)) 359 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
360 switches::kSingleProcess))
354 return; 361 return;
355 362
356 LoadUrlAndQuitBrowser(INFINITE_UNLOAD_ALERT_HTML, "infiniteunloadalert"); 363 LoadUrlAndQuitBrowser(INFINITE_UNLOAD_ALERT_HTML, "infiniteunloadalert");
357 } 364 }
358 365
359 // Tests closing the browser with a beforeunload handler that hangs then 366 // Tests closing the browser with a beforeunload handler that hangs then
360 // pops up an alert. 367 // pops up an alert.
361 // If this flakes, use http://crbug.com/78803 and http://crbug.com/86469. 368 // If this flakes, use http://crbug.com/78803 and http://crbug.com/86469.
362 IN_PROC_BROWSER_TEST_F(UnloadTest, 369 IN_PROC_BROWSER_TEST_F(UnloadTest,
363 DISABLED_BrowserCloseInfiniteBeforeUnloadAlert) { 370 DISABLED_BrowserCloseInfiniteBeforeUnloadAlert) {
364 // Tests makes no sense in single-process mode since the renderer is hung. 371 // Tests makes no sense in single-process mode since the renderer is hung.
365 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kSingleProcess)) 372 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
373 switches::kSingleProcess))
366 return; 374 return;
367 375
368 LoadUrlAndQuitBrowser(INFINITE_BEFORE_UNLOAD_ALERT_HTML, 376 LoadUrlAndQuitBrowser(INFINITE_BEFORE_UNLOAD_ALERT_HTML,
369 "infinitebeforeunloadalert"); 377 "infinitebeforeunloadalert");
370 } 378 }
371 379
372 // Tests closing the browser on a page with an unload listener registered where 380 // Tests closing the browser on a page with an unload listener registered where
373 // the unload handler has an 2 second long loop followed by an alert. 381 // the unload handler has an 2 second long loop followed by an alert.
374 IN_PROC_BROWSER_TEST_F(UnloadTest, BrowserCloseTwoSecondUnloadAlert) { 382 IN_PROC_BROWSER_TEST_F(UnloadTest, BrowserCloseTwoSecondUnloadAlert) {
375 LoadUrlAndQuitBrowser(TWO_SECOND_UNLOAD_ALERT_HTML, "twosecondunloadalert"); 383 LoadUrlAndQuitBrowser(TWO_SECOND_UNLOAD_ALERT_HTML, "twosecondunloadalert");
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
409 content::WebContentsDestroyedWatcher destroyed_watcher( 417 content::WebContentsDestroyedWatcher destroyed_watcher(
410 browser()->tab_strip_model()->GetActiveWebContents()); 418 browser()->tab_strip_model()->GetActiveWebContents());
411 chrome::CloseTab(browser()); 419 chrome::CloseTab(browser());
412 destroyed_watcher.Wait(); 420 destroyed_watcher.Wait();
413 421
414 CheckTitle("only_one_unload"); 422 CheckTitle("only_one_unload");
415 } 423 }
416 424
417 class FastUnloadTest : public UnloadTest { 425 class FastUnloadTest : public UnloadTest {
418 public: 426 public:
419 void SetUpCommandLine(CommandLine* command_line) override { 427 void SetUpCommandLine(base::CommandLine* command_line) override {
420 UnloadTest::SetUpCommandLine(command_line); 428 UnloadTest::SetUpCommandLine(command_line);
421 command_line->AppendSwitch(switches::kEnableFastUnload); 429 command_line->AppendSwitch(switches::kEnableFastUnload);
422 } 430 }
423 431
424 void SetUpInProcessBrowserTestFixture() override { 432 void SetUpInProcessBrowserTestFixture() override {
425 ASSERT_TRUE(test_server()->Start()); 433 ASSERT_TRUE(test_server()->Start());
426 } 434 }
427 435
428 void TearDownInProcessBrowserTestFixture() override { test_server()->Stop(); } 436 void TearDownInProcessBrowserTestFixture() override { test_server()->Stop(); }
429 437
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
613 #if defined(OS_WIN) || defined(OS_LINUX) 621 #if defined(OS_WIN) || defined(OS_LINUX)
614 #define MAYBE_WindowCloseAfterBeforeUnloadCrash \ 622 #define MAYBE_WindowCloseAfterBeforeUnloadCrash \
615 DISABLED_WindowCloseAfterBeforeUnloadCrash 623 DISABLED_WindowCloseAfterBeforeUnloadCrash
616 #else 624 #else
617 #define MAYBE_WindowCloseAfterBeforeUnloadCrash \ 625 #define MAYBE_WindowCloseAfterBeforeUnloadCrash \
618 WindowCloseAfterBeforeUnloadCrash 626 WindowCloseAfterBeforeUnloadCrash
619 #endif 627 #endif
620 IN_PROC_BROWSER_TEST_F(FastUnloadTest, 628 IN_PROC_BROWSER_TEST_F(FastUnloadTest,
621 MAYBE_WindowCloseAfterBeforeUnloadCrash) { 629 MAYBE_WindowCloseAfterBeforeUnloadCrash) {
622 // Tests makes no sense in single-process mode since the renderer is hung. 630 // Tests makes no sense in single-process mode since the renderer is hung.
623 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kSingleProcess)) 631 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
632 switches::kSingleProcess))
624 return; 633 return;
625 634
626 NavigateToDataURL(BEFORE_UNLOAD_HTML, "beforeunload"); 635 NavigateToDataURL(BEFORE_UNLOAD_HTML, "beforeunload");
627 content::WebContents* beforeunload_contents = 636 content::WebContents* beforeunload_contents =
628 browser()->tab_strip_model()->GetActiveWebContents(); 637 browser()->tab_strip_model()->GetActiveWebContents();
629 638
630 content::WindowedNotificationObserver window_observer( 639 content::WindowedNotificationObserver window_observer(
631 chrome::NOTIFICATION_BROWSER_CLOSED, 640 chrome::NOTIFICATION_BROWSER_CLOSED,
632 content::NotificationService::AllSources()); 641 content::NotificationService::AllSources());
633 chrome::CloseWindow(browser()); 642 chrome::CloseWindow(browser());
634 CrashTab(beforeunload_contents); 643 CrashTab(beforeunload_contents);
635 window_observer.Wait(); 644 window_observer.Wait();
636 } 645 }
637 646
638 // TODO(ojan): Add tests for unload/beforeunload that have multiple tabs 647 // TODO(ojan): Add tests for unload/beforeunload that have multiple tabs
639 // and multiple windows. 648 // and multiple windows.
OLDNEW
« no previous file with comments | « chrome/browser/ui/window_sizer/window_sizer_ash_unittest.cc ('k') | chrome/browser/upgrade_detector.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698