Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(95)

Side by Side Diff: content/test/content_browser_test.cc

Issue 10803026: Get content_browsertest working. I've added a simple test for now, and will convert the tests in sr… (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: get it working on mac + linux, fix unittests crash, and fix unittest link error and add missing dep… Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « content/test/content_browser_test.h ('k') | content/test/content_browser_test_test.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/debug/stack_trace.h" 8 #include "base/debug/stack_trace.h"
9 #include "base/file_path.h"
10 #include "base/logging.h"
8 #include "base/message_loop.h" 11 #include "base/message_loop.h"
12 #include "base/path_service.h"
13 #include "content/public/common/content_switches.h"
9 #include "content/shell/shell.h" 14 #include "content/shell/shell.h"
10 #include "content/shell/shell_main_delegate.h" 15 #include "content/shell/shell_main_delegate.h"
11 #include "content/test/test_content_client.h" 16 #include "content/test/test_content_client.h"
12 17
13 #if defined(OS_MACOSX) 18 #if defined(OS_MACOSX)
14 #include "base/mac/scoped_nsautorelease_pool.h" 19 #include "base/mac/scoped_nsautorelease_pool.h"
15 #endif 20 #endif
16 21
17 ContentBrowserTest::ContentBrowserTest() { 22 ContentBrowserTest::ContentBrowserTest() {
23 #if defined(OS_MACOSX)
24 // See comment in InProcessBrowserTest::InProcessBrowserTest().
25 FilePath content_shell_path;
26 CHECK(PathService::Get(base::FILE_EXE, &content_shell_path));
27 content_shell_path = content_shell_path.DirName();
28 content_shell_path = content_shell_path.Append(
29 FILE_PATH_LITERAL("Content Shell.app/Contents/MacOS/Content Shell"));
30 CHECK(PathService::Override(base::FILE_EXE, content_shell_path));
31 #endif
18 } 32 }
19 33
20 ContentBrowserTest::~ContentBrowserTest() { 34 ContentBrowserTest::~ContentBrowserTest() {
21 } 35 }
22 36
23 void ContentBrowserTest::SetUp() { 37 void ContentBrowserTest::SetUp() {
24 DCHECK(!content::GetContentClient());
25 shell_main_delegate_.reset(new ShellMainDelegate); 38 shell_main_delegate_.reset(new ShellMainDelegate);
26 shell_main_delegate_->PreSandboxStartup(); 39 shell_main_delegate_->PreSandboxStartup();
27 40
41 #if defined(OS_MACOSX)
42 // See InProcessBrowserTest::PrepareTestCommandLine().
43 CommandLine* command_line = CommandLine::ForCurrentProcess();
44 FilePath subprocess_path;
45 PathService::Get(base::FILE_EXE, &subprocess_path);
46 subprocess_path = subprocess_path.DirName().DirName();
47 DCHECK_EQ(subprocess_path.BaseName().value(), "Contents");
48 subprocess_path = subprocess_path.Append(
49 "Frameworks/Content Shell Helper.app/Contents/MacOS/Content Shell Helper") ;
50 command_line->AppendSwitchPath(switches::kBrowserSubprocessPath,
51 subprocess_path);
52 #endif
53
28 BrowserTestBase::SetUp(); 54 BrowserTestBase::SetUp();
29 } 55 }
30 56
31 void ContentBrowserTest::TearDown() { 57 void ContentBrowserTest::TearDown() {
32 BrowserTestBase::TearDown(); 58 BrowserTestBase::TearDown();
33 59
34 shell_main_delegate_.reset(); 60 shell_main_delegate_.reset();
35 } 61 }
36 62
37 #if defined(OS_POSIX) 63 #if defined(OS_POSIX)
38 // On SIGTERM (sent by the runner on timeouts), dump a stack trace (to make 64 // 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 65 // debugging easier) and also exit with a known error code (so that the test
40 // framework considers this a failure -- http://crbug.com/57578). 66 // framework considers this a failure -- http://crbug.com/57578).
41 static void DumpStackTraceSignalHandler(int signal) { 67 static void DumpStackTraceSignalHandler(int signal) {
42 base::debug::StackTrace().PrintBacktrace(); 68 base::debug::StackTrace().PrintBacktrace();
43 _exit(128 + signal); 69 _exit(128 + signal);
44 } 70 }
45 #endif // defined(OS_POSIX) 71 #endif // defined(OS_POSIX)
46 72
47 void ContentBrowserTest::RunTestOnMainThreadLoop() { 73 void ContentBrowserTest::RunTestOnMainThreadLoop() {
74 CHECK_EQ(content::Shell::windows().size(), 1u);
75 shell_ = content::Shell::windows()[0];
76
48 #if defined(OS_POSIX) 77 #if defined(OS_POSIX)
49 signal(SIGTERM, DumpStackTraceSignalHandler); 78 signal(SIGTERM, DumpStackTraceSignalHandler);
50 #endif // defined(OS_POSIX) 79 #endif // defined(OS_POSIX)
51 80
52 #if defined(OS_MACOSX) 81 #if defined(OS_MACOSX)
53 // On Mac, without the following autorelease pool, code which is directly 82 // On Mac, without the following autorelease pool, code which is directly
54 // executed (as opposed to executed inside a message loop) would autorelease 83 // 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 84 // 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 85 // the message loops' pools and causes problems with code relying on
57 // deallocation via an autorelease pool (such as browser window closure and 86 // deallocation via an autorelease pool (such as browser window closure and
58 // browser shutdown). To avoid this, the following pool is recycled after each 87 // browser shutdown). To avoid this, the following pool is recycled after each
59 // time code is directly executed. 88 // time code is directly executed.
60 base::mac::ScopedNSAutoreleasePool pool; 89 base::mac::ScopedNSAutoreleasePool pool;
61 #endif 90 #endif
62 91
63 // Pump startup related events. 92 // Pump startup related events.
64 MessageLoopForUI::current()->RunAllPending(); 93 MessageLoopForUI::current()->RunAllPending();
65 94
66 #if defined(OS_MACOSX) 95 #if defined(OS_MACOSX)
67 pool.Recycle(); 96 pool.Recycle();
68 #endif 97 #endif
69 98
70 RunTestOnMainThread(); 99 RunTestOnMainThread();
71 #if defined(OS_MACOSX) 100 #if defined(OS_MACOSX)
72 pool.Recycle(); 101 pool.Recycle();
73 #endif 102 #endif
74
75 MessageLoopForUI::current()->Quit();
76 #if defined(OS_MACOSX)
77 pool.Recycle();
78 #endif
79 } 103 }
OLDNEW
« no previous file with comments | « content/test/content_browser_test.h ('k') | content/test/content_browser_test_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698