| 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 356 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 367 #endif | 367 #endif |
| 368 | 368 |
| 369 // Invoke cleanup and quit even if there are failures. This is similar to | 369 // Invoke cleanup and quit even if there are failures. This is similar to |
| 370 // gtest in that it invokes TearDown even if Setup fails. | 370 // gtest in that it invokes TearDown even if Setup fails. |
| 371 CleanUpOnMainThread(); | 371 CleanUpOnMainThread(); |
| 372 #if defined(OS_MACOSX) | 372 #if defined(OS_MACOSX) |
| 373 autorelease_pool_->Recycle(); | 373 autorelease_pool_->Recycle(); |
| 374 #endif | 374 #endif |
| 375 | 375 |
| 376 QuitBrowsers(); | 376 QuitBrowsers(); |
| 377 CHECK(BrowserList::empty()); |
| 377 } | 378 } |
| 378 | 379 |
| 379 void InProcessBrowserTest::QuitBrowsers() { | 380 void InProcessBrowserTest::QuitBrowsers() { |
| 380 if (BrowserList::empty()) | 381 if (BrowserList::empty()) |
| 381 return; | 382 return; |
| 382 | 383 |
| 383 // Invoke CloseAllBrowsersAndMayExit on a running message loop. | 384 // Invoke AttemptExit on a running message loop. |
| 384 // CloseAllBrowsersAndMayExit exits the message loop after everything has been | 385 // AttemptExit exits the message loop after everything has been |
| 385 // shut down properly. | 386 // shut down properly. |
| 386 MessageLoopForUI::current()->PostTask(FROM_HERE, | 387 MessageLoopForUI::current()->PostTask(FROM_HERE, |
| 387 base::Bind(&browser::AttemptExit)); | 388 base::Bind(&browser::AttemptExit)); |
| 388 ui_test_utils::RunMessageLoop(); | 389 ui_test_utils::RunMessageLoop(); |
| 389 | 390 |
| 390 #if defined(OS_MACOSX) | 391 #if defined(OS_MACOSX) |
| 392 // browser::AttemptExit() will attempt to close all browsers by deleting |
| 393 // their tab contents. The last tab contents being removed triggers closing of |
| 394 // the browser window. |
| 395 // |
| 396 // On the Mac, this eventually reaches |
| 397 // -[BrowserWindowController windowWillClose:], which will post a deferred |
| 398 // -autorelease on itself to ultimately destroy the Browser object. The line |
| 399 // below is necessary to pump these pending messages to ensure all Browsers |
| 400 // get deleted. |
| 401 ui_test_utils::RunAllPendingInMessageLoop(); |
| 391 delete autorelease_pool_; | 402 delete autorelease_pool_; |
| 392 autorelease_pool_ = NULL; | 403 autorelease_pool_ = NULL; |
| 393 #endif | 404 #endif |
| 394 } | 405 } |
| OLD | NEW |