OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "content/test/content_browser_test.h" |
| 6 |
| 7 #include "base/mac/scoped_nsautorelease_pool.h" |
| 8 #include "base/message_loop.h" |
| 9 #include "content/test/test_content_client.h" |
| 10 |
| 11 void ContentBrowserTest::SetUp() { |
| 12 DCHECK(!content::GetContentClient()); |
| 13 content_client_.reset(new TestContentClient); |
| 14 content::SetContentClient(content_client_.get()); |
| 15 |
| 16 content_browser_client_.reset(new content::MockContentBrowserClient()); |
| 17 content_client_->set_browser(content_browser_client_.get()); |
| 18 |
| 19 BrowserTestBase::SetUp(); |
| 20 } |
| 21 |
| 22 void ContentBrowserTest::TearDown() { |
| 23 BrowserTestBase::TearDown(); |
| 24 |
| 25 DCHECK_EQ(content_client_.get(), content::GetContentClient()); |
| 26 content::SetContentClient(NULL); |
| 27 content_client_.reset(); |
| 28 |
| 29 content_browser_client_.reset(); |
| 30 } |
| 31 |
| 32 #if defined(OS_POSIX) |
| 33 // On SIGTERM (sent by the runner on timeouts), dump a stack trace (to make |
| 34 // debugging easier) and also exit with a known error code (so that the test |
| 35 // framework considers this a failure -- http://crbug.com/57578). |
| 36 static void DumpStackTraceSignalHandler(int signal) { |
| 37 base::debug::StackTrace().PrintBacktrace(); |
| 38 _exit(128 + signal); |
| 39 } |
| 40 #endif // defined(OS_POSIX) |
| 41 |
| 42 void ContentBrowserTest::RunTestOnMainThreadLoop() { |
| 43 #if defined(OS_POSIX) |
| 44 signal(SIGTERM, DumpStackTraceSignalHandler); |
| 45 #endif // defined(OS_POSIX) |
| 46 |
| 47 // On Mac, without the following autorelease pool, code which is directly |
| 48 // executed (as opposed to executed inside a message loop) would autorelease |
| 49 // objects into a higher-level pool. This pool is not recycled in-sync with |
| 50 // the message loops' pools and causes problems with code relying on |
| 51 // deallocation via an autorelease pool (such as browser window closure and |
| 52 // browser shutdown). To avoid this, the following pool is recycled after each |
| 53 // time code is directly executed. |
| 54 base::mac::ScopedNSAutoreleasePool pool; |
| 55 |
| 56 // Pump startup related events. |
| 57 MessageLoopForUI::current()->RunAllPending(); |
| 58 pool.Recycle(); |
| 59 |
| 60 RunTestOnMainThread(); |
| 61 pool.Recycle(); |
| 62 |
| 63 MessageLoopForUI::current()->Quit(); |
| 64 pool.Recycle(); |
| 65 } |
OLD | NEW |