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