| 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/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/debug/stack_trace.h" | 8 #include "base/debug/stack_trace.h" |
| 9 #include "base/file_path.h" | 9 #include "base/file_path.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/message_loop.h" | 11 #include "base/message_loop.h" |
| 12 #include "base/path_service.h" | 12 #include "base/path_service.h" |
| 13 #include "content/public/common/content_switches.h" | 13 #include "content/public/common/content_switches.h" |
| 14 #include "content/shell/shell.h" | 14 #include "content/shell/shell.h" |
| 15 #include "content/shell/shell_main_delegate.h" | 15 #include "content/shell/shell_main_delegate.h" |
| 16 #include "content/test/test_content_client.h" | 16 #include "content/test/test_content_client.h" |
| 17 | 17 |
| 18 #if defined(OS_MACOSX) | 18 #if defined(OS_MACOSX) |
| 19 #include "base/mac/scoped_nsautorelease_pool.h" | 19 #include "base/mac/scoped_nsautorelease_pool.h" |
| 20 #endif | 20 #endif |
| 21 | 21 |
| 22 namespace content { |
| 23 |
| 22 ContentBrowserTest::ContentBrowserTest() { | 24 ContentBrowserTest::ContentBrowserTest() { |
| 23 #if defined(OS_MACOSX) | 25 #if defined(OS_MACOSX) |
| 24 // See comment in InProcessBrowserTest::InProcessBrowserTest(). | 26 // See comment in InProcessBrowserTest::InProcessBrowserTest(). |
| 25 FilePath content_shell_path; | 27 FilePath content_shell_path; |
| 26 CHECK(PathService::Get(base::FILE_EXE, &content_shell_path)); | 28 CHECK(PathService::Get(base::FILE_EXE, &content_shell_path)); |
| 27 content_shell_path = content_shell_path.DirName(); | 29 content_shell_path = content_shell_path.DirName(); |
| 28 content_shell_path = content_shell_path.Append( | 30 content_shell_path = content_shell_path.Append( |
| 29 FILE_PATH_LITERAL("Content Shell.app/Contents/MacOS/Content Shell")); | 31 FILE_PATH_LITERAL("Content Shell.app/Contents/MacOS/Content Shell")); |
| 30 CHECK(PathService::Override(base::FILE_EXE, content_shell_path)); | 32 CHECK(PathService::Override(base::FILE_EXE, content_shell_path)); |
| 31 #endif | 33 #endif |
| 32 } | 34 } |
| 33 | 35 |
| 34 ContentBrowserTest::~ContentBrowserTest() { | 36 ContentBrowserTest::~ContentBrowserTest() { |
| 35 } | 37 } |
| 36 | 38 |
| 37 void ContentBrowserTest::SetUp() { | 39 void ContentBrowserTest::SetUp() { |
| 38 shell_main_delegate_.reset(new ShellMainDelegate); | 40 shell_main_delegate_.reset(new content::ShellMainDelegate); |
| 39 shell_main_delegate_->PreSandboxStartup(); | 41 shell_main_delegate_->PreSandboxStartup(); |
| 40 | 42 |
| 41 #if defined(OS_MACOSX) | 43 #if defined(OS_MACOSX) |
| 42 // See InProcessBrowserTest::PrepareTestCommandLine(). | 44 // See InProcessBrowserTest::PrepareTestCommandLine(). |
| 43 CommandLine* command_line = CommandLine::ForCurrentProcess(); | 45 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
| 44 FilePath subprocess_path; | 46 FilePath subprocess_path; |
| 45 PathService::Get(base::FILE_EXE, &subprocess_path); | 47 PathService::Get(base::FILE_EXE, &subprocess_path); |
| 46 subprocess_path = subprocess_path.DirName().DirName(); | 48 subprocess_path = subprocess_path.DirName().DirName(); |
| 47 DCHECK_EQ(subprocess_path.BaseName().value(), "Contents"); | 49 DCHECK_EQ(subprocess_path.BaseName().value(), "Contents"); |
| 48 subprocess_path = subprocess_path.Append( | 50 subprocess_path = subprocess_path.Append( |
| (...skipping 15 matching lines...) Expand all Loading... |
| 64 // On SIGTERM (sent by the runner on timeouts), dump a stack trace (to make | 66 // On SIGTERM (sent by the runner on timeouts), dump a stack trace (to make |
| 65 // debugging easier) and also exit with a known error code (so that the test | 67 // debugging easier) and also exit with a known error code (so that the test |
| 66 // framework considers this a failure -- http://crbug.com/57578). | 68 // framework considers this a failure -- http://crbug.com/57578). |
| 67 static void DumpStackTraceSignalHandler(int signal) { | 69 static void DumpStackTraceSignalHandler(int signal) { |
| 68 base::debug::StackTrace().PrintBacktrace(); | 70 base::debug::StackTrace().PrintBacktrace(); |
| 69 _exit(128 + signal); | 71 _exit(128 + signal); |
| 70 } | 72 } |
| 71 #endif // defined(OS_POSIX) | 73 #endif // defined(OS_POSIX) |
| 72 | 74 |
| 73 void ContentBrowserTest::RunTestOnMainThreadLoop() { | 75 void ContentBrowserTest::RunTestOnMainThreadLoop() { |
| 74 CHECK_EQ(content::Shell::windows().size(), 1u); | 76 CHECK_EQ(Shell::windows().size(), 1u); |
| 75 shell_ = content::Shell::windows()[0]; | 77 shell_ = Shell::windows()[0]; |
| 76 | 78 |
| 77 #if defined(OS_POSIX) | 79 #if defined(OS_POSIX) |
| 78 signal(SIGTERM, DumpStackTraceSignalHandler); | 80 signal(SIGTERM, DumpStackTraceSignalHandler); |
| 79 #endif // defined(OS_POSIX) | 81 #endif // defined(OS_POSIX) |
| 80 | 82 |
| 81 #if defined(OS_MACOSX) | 83 #if defined(OS_MACOSX) |
| 82 // On Mac, without the following autorelease pool, code which is directly | 84 // On Mac, without the following autorelease pool, code which is directly |
| 83 // executed (as opposed to executed inside a message loop) would autorelease | 85 // executed (as opposed to executed inside a message loop) would autorelease |
| 84 // objects into a higher-level pool. This pool is not recycled in-sync with | 86 // objects into a higher-level pool. This pool is not recycled in-sync with |
| 85 // the message loops' pools and causes problems with code relying on | 87 // the message loops' pools and causes problems with code relying on |
| 86 // deallocation via an autorelease pool (such as browser window closure and | 88 // deallocation via an autorelease pool (such as browser window closure and |
| 87 // browser shutdown). To avoid this, the following pool is recycled after each | 89 // browser shutdown). To avoid this, the following pool is recycled after each |
| 88 // time code is directly executed. | 90 // time code is directly executed. |
| 89 base::mac::ScopedNSAutoreleasePool pool; | 91 base::mac::ScopedNSAutoreleasePool pool; |
| 90 #endif | 92 #endif |
| 91 | 93 |
| 92 // Pump startup related events. | 94 // Pump startup related events. |
| 93 MessageLoopForUI::current()->RunAllPending(); | 95 MessageLoopForUI::current()->RunAllPending(); |
| 94 | 96 |
| 95 #if defined(OS_MACOSX) | 97 #if defined(OS_MACOSX) |
| 96 pool.Recycle(); | 98 pool.Recycle(); |
| 97 #endif | 99 #endif |
| 98 | 100 |
| 99 RunTestOnMainThread(); | 101 RunTestOnMainThread(); |
| 100 #if defined(OS_MACOSX) | 102 #if defined(OS_MACOSX) |
| 101 pool.Recycle(); | 103 pool.Recycle(); |
| 102 #endif | 104 #endif |
| 103 } | 105 } |
| 106 |
| 107 } // namespace content |
| OLD | NEW |