OLD | NEW |
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 #include "chrome/test/base/in_process_browser_test.h" | 5 #include "chrome/test/base/in_process_browser_test.h" |
6 | 6 |
7 #include "base/auto_reset.h" | 7 #include "base/auto_reset.h" |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/debug/stack_trace.h" | 10 #include "base/debug/stack_trace.h" |
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
326 } | 326 } |
327 #endif // defined(OS_POSIX) | 327 #endif // defined(OS_POSIX) |
328 | 328 |
329 void InProcessBrowserTest::RunTestOnMainThreadLoop() { | 329 void InProcessBrowserTest::RunTestOnMainThreadLoop() { |
330 #if defined(OS_POSIX) | 330 #if defined(OS_POSIX) |
331 if (handle_sigterm_) | 331 if (handle_sigterm_) |
332 signal(SIGTERM, DumpStackTraceSignalHandler); | 332 signal(SIGTERM, DumpStackTraceSignalHandler); |
333 #endif // defined(OS_POSIX) | 333 #endif // defined(OS_POSIX) |
334 | 334 |
335 // Pump startup related events. | 335 // Pump startup related events. |
336 ui_test_utils::RunAllPendingInMessageLoop(); | 336 content::RunAllPendingInMessageLoop(); |
337 | 337 |
338 #if defined(OS_MACOSX) | 338 #if defined(OS_MACOSX) |
339 autorelease_pool_->Recycle(); | 339 autorelease_pool_->Recycle(); |
340 #endif | 340 #endif |
341 | 341 |
342 if (!BrowserList::empty()) { | 342 if (!BrowserList::empty()) { |
343 browser_ = *BrowserList::begin(); | 343 browser_ = *BrowserList::begin(); |
344 content::WaitForLoadStop(chrome::GetActiveWebContents(browser_)); | 344 content::WaitForLoadStop(chrome::GetActiveWebContents(browser_)); |
345 } | 345 } |
346 | 346 |
347 // Pump any pending events that were created as a result of creating a | 347 // Pump any pending events that were created as a result of creating a |
348 // browser. | 348 // browser. |
349 ui_test_utils::RunAllPendingInMessageLoop(); | 349 content::RunAllPendingInMessageLoop(); |
350 | 350 |
351 SetUpOnMainThread(); | 351 SetUpOnMainThread(); |
352 #if defined(OS_MACOSX) | 352 #if defined(OS_MACOSX) |
353 autorelease_pool_->Recycle(); | 353 autorelease_pool_->Recycle(); |
354 #endif | 354 #endif |
355 | 355 |
356 if (!HasFatalFailure()) | 356 if (!HasFatalFailure()) |
357 RunTestOnMainThread(); | 357 RunTestOnMainThread(); |
358 #if defined(OS_MACOSX) | 358 #if defined(OS_MACOSX) |
359 autorelease_pool_->Recycle(); | 359 autorelease_pool_->Recycle(); |
360 #endif | 360 #endif |
361 | 361 |
362 // Invoke cleanup and quit even if there are failures. This is similar to | 362 // Invoke cleanup and quit even if there are failures. This is similar to |
363 // gtest in that it invokes TearDown even if Setup fails. | 363 // gtest in that it invokes TearDown even if Setup fails. |
364 CleanUpOnMainThread(); | 364 CleanUpOnMainThread(); |
365 #if defined(OS_MACOSX) | 365 #if defined(OS_MACOSX) |
366 autorelease_pool_->Recycle(); | 366 autorelease_pool_->Recycle(); |
367 #endif | 367 #endif |
368 | 368 |
369 // Sometimes tests leave Quit tasks in the MessageLoop (for shame), so let's | 369 // Sometimes tests leave Quit tasks in the MessageLoop (for shame), so let's |
370 // run all pending messages here to avoid preempting the QuitBrowsers tasks. | 370 // run all pending messages here to avoid preempting the QuitBrowsers tasks. |
371 // TODO(jbates) Once crbug.com/134753 is fixed, this can be removed because it | 371 // TODO(jbates) Once crbug.com/134753 is fixed, this can be removed because it |
372 // will not be possible to post Quit tasks. | 372 // will not be possible to post Quit tasks. |
373 ui_test_utils::RunAllPendingInMessageLoop(); | 373 content::RunAllPendingInMessageLoop(); |
374 | 374 |
375 QuitBrowsers(); | 375 QuitBrowsers(); |
376 CHECK(BrowserList::empty()); | 376 CHECK(BrowserList::empty()); |
377 } | 377 } |
378 | 378 |
379 void InProcessBrowserTest::QuitBrowsers() { | 379 void InProcessBrowserTest::QuitBrowsers() { |
380 if (BrowserList::empty()) | 380 if (BrowserList::empty()) |
381 return; | 381 return; |
382 | 382 |
383 // Invoke AttemptExit on a running message loop. | 383 // Invoke AttemptExit on a running message loop. |
384 // AttemptExit exits the message loop after everything has been | 384 // AttemptExit exits the message loop after everything has been |
385 // shut down properly. | 385 // shut down properly. |
386 MessageLoopForUI::current()->PostTask(FROM_HERE, | 386 MessageLoopForUI::current()->PostTask(FROM_HERE, |
387 base::Bind(&browser::AttemptExit)); | 387 base::Bind(&browser::AttemptExit)); |
388 content::RunMessageLoop(); | 388 content::RunMessageLoop(); |
389 | 389 |
390 #if defined(OS_MACOSX) | 390 #if defined(OS_MACOSX) |
391 // browser::AttemptExit() will attempt to close all browsers by deleting | 391 // browser::AttemptExit() will attempt to close all browsers by deleting |
392 // their tab contents. The last tab contents being removed triggers closing of | 392 // their tab contents. The last tab contents being removed triggers closing of |
393 // the browser window. | 393 // the browser window. |
394 // | 394 // |
395 // On the Mac, this eventually reaches | 395 // On the Mac, this eventually reaches |
396 // -[BrowserWindowController windowWillClose:], which will post a deferred | 396 // -[BrowserWindowController windowWillClose:], which will post a deferred |
397 // -autorelease on itself to ultimately destroy the Browser object. The line | 397 // -autorelease on itself to ultimately destroy the Browser object. The line |
398 // below is necessary to pump these pending messages to ensure all Browsers | 398 // below is necessary to pump these pending messages to ensure all Browsers |
399 // get deleted. | 399 // get deleted. |
400 ui_test_utils::RunAllPendingInMessageLoop(); | 400 content::RunAllPendingInMessageLoop(); |
401 delete autorelease_pool_; | 401 delete autorelease_pool_; |
402 autorelease_pool_ = NULL; | 402 autorelease_pool_ = NULL; |
403 #endif | 403 #endif |
404 } | 404 } |
OLD | NEW |