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