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

Side by Side Diff: content/test/content_test_launcher.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_utils.cc ('k') | content/test/data/simple_page.html » ('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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/public/test/test_launcher.h" 5 #include "content/public/test/test_launcher.h"
6 6
7 #include "base/base_paths.h" 7 #include "base/base_paths.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/path_service.h" 10 #include "base/path_service.h"
11 #include "base/scoped_temp_dir.h" 11 #include "base/scoped_temp_dir.h"
12 #include "base/test/test_suite.h" 12 #include "base/test/test_suite.h"
13 #include "content/public/app/content_main.h" 13 #include "content/public/app/content_main.h"
14 #include "content/public/common/content_switches.h" 14 #include "content/public/common/content_switches.h"
15 #include "content/public/test/content_test_suite_base.h"
16 #include "content/shell/shell_content_browser_client.h"
17 #include "content/shell/shell_content_client.h"
15 #include "content/shell/shell_main_delegate.h" 18 #include "content/shell/shell_main_delegate.h"
19 #include "testing/gtest/include/gtest/gtest.h"
16 20
17 #if defined(OS_WIN) 21 #if defined(OS_WIN)
18 #include "content/public/app/startup_helper_win.h" 22 #include "content/public/app/startup_helper_win.h"
19 #include "sandbox/src/sandbox_types.h" 23 #include "sandbox/src/sandbox_types.h"
24 #include "ui/base/win/scoped_ole_initializer.h"
20 #endif // defined(OS_WIN) 25 #endif // defined(OS_WIN)
21 26
27 namespace content {
28
29 class ContentShellTestSuiteInitializer
30 : public testing::EmptyTestEventListener {
31 public:
32 ContentShellTestSuiteInitializer() {
33 }
34
35 virtual void OnTestStart(const testing::TestInfo& test_info) OVERRIDE {
36 DCHECK(!GetContentClient());
37 content_client_.reset(new ShellContentClient);
38 browser_content_client_.reset(new ShellContentBrowserClient());
39 content_client_->set_browser_for_testing(browser_content_client_.get());
40 SetContentClient(content_client_.get());
41 }
42
43 virtual void OnTestEnd(const testing::TestInfo& test_info) OVERRIDE {
44 DCHECK_EQ(content_client_.get(), GetContentClient());
45 browser_content_client_.reset();
46 content_client_.reset();
47 SetContentClient(NULL);
48 }
49
50 private:
51 scoped_ptr<ShellContentClient> content_client_;
52 scoped_ptr<ShellContentBrowserClient> browser_content_client_;
53
54 DISALLOW_COPY_AND_ASSIGN(ContentShellTestSuiteInitializer);
55 };
56
57 class ContentBrowserTestSuite : public ContentTestSuiteBase {
58 public:
59 ContentBrowserTestSuite(int argc, char** argv)
60 : ContentTestSuiteBase(argc, argv) {
61 }
62 virtual ~ContentBrowserTestSuite() {
63 }
64
65 protected:
66 virtual void Initialize() OVERRIDE {
67 ContentTestSuiteBase::Initialize();
68
69 testing::TestEventListeners& listeners =
70 testing::UnitTest::GetInstance()->listeners();
71 listeners.Append(new ContentShellTestSuiteInitializer);
72 }
73 virtual void Shutdown() OVERRIDE {
74 base::TestSuite::Shutdown();
75 }
76
77 virtual ContentClient* CreateClientForInitialization() OVERRIDE {
78 return new ShellContentClient();
79 }
80
81 #if defined(OS_WIN)
82 ui::ScopedOleInitializer ole_initializer_;
83 #endif
84
85 DISALLOW_COPY_AND_ASSIGN(ContentBrowserTestSuite);
86 };
87
88 } // namespace content
89
22 class ContentTestLauncherDelegate : public test_launcher::TestLauncherDelegate { 90 class ContentTestLauncherDelegate : public test_launcher::TestLauncherDelegate {
23 public: 91 public:
24 ContentTestLauncherDelegate() { 92 ContentTestLauncherDelegate() {
25 } 93 }
26 94
27 virtual ~ContentTestLauncherDelegate() { 95 virtual ~ContentTestLauncherDelegate() {
28 } 96 }
29 97
30 virtual void EarlyInitialize() OVERRIDE { 98 virtual void EarlyInitialize() OVERRIDE {
31 } 99 }
32 100
33 virtual bool Run(int argc, char** argv, int* return_code) OVERRIDE { 101 virtual bool Run(int argc, char** argv, int* return_code) OVERRIDE {
34 #if defined(OS_WIN) 102 #if defined(OS_WIN) || defined(OS_LINUX)
35 CommandLine* command_line = CommandLine::ForCurrentProcess(); 103 CommandLine* command_line = CommandLine::ForCurrentProcess();
36 if (command_line->HasSwitch(switches::kProcessType)) { 104 if (command_line->HasSwitch(switches::kProcessType)) {
105 ShellMainDelegate delegate;
106 #if defined(OS_WIN)
37 sandbox::SandboxInterfaceInfo sandbox_info = {0}; 107 sandbox::SandboxInterfaceInfo sandbox_info = {0};
38 content::InitializeSandboxInfo(&sandbox_info); 108 content::InitializeSandboxInfo(&sandbox_info);
39 ShellMainDelegate delegate;
40 *return_code = 109 *return_code =
41 content::ContentMain(GetModuleHandle(NULL), &sandbox_info, &delegate); 110 content::ContentMain(GetModuleHandle(NULL), &sandbox_info, &delegate);
111 #elif defined(OS_LINUX)
112 *return_code = content::ContentMain(argc,
113 const_cast<const char**>(argv),
114 &delegate);
115 #endif // defined(OS_WIN)
42 return true; 116 return true;
43 } 117 }
44 #endif // defined(OS_WIN) 118 #endif // defined(OS_WIN) || defined(OS_LINUX)
45 119
46 return false; 120 return false;
47 } 121 }
48 122
49 virtual int RunTestSuite(int argc, char** argv) OVERRIDE { 123 virtual int RunTestSuite(int argc, char** argv) OVERRIDE {
50 return base::TestSuite(argc, argv).Run(); 124 return content::ContentBrowserTestSuite(argc, argv).Run();
51 } 125 }
52 126
53 virtual bool AdjustChildProcessCommandLine( 127 virtual bool AdjustChildProcessCommandLine(
54 CommandLine* command_line) OVERRIDE { 128 CommandLine* command_line) OVERRIDE {
55 FilePath file_exe;
56 if (!PathService::Get(base::FILE_EXE, &file_exe))
57 return false;
58 command_line->AppendSwitchPath(switches::kBrowserSubprocessPath, file_exe);
59 return true; 129 return true;
60 } 130 }
61 131
62 private: 132 private:
63 DISALLOW_COPY_AND_ASSIGN(ContentTestLauncherDelegate); 133 DISALLOW_COPY_AND_ASSIGN(ContentTestLauncherDelegate);
64 }; 134 };
65 135
66 int main(int argc, char** argv) { 136 int main(int argc, char** argv) {
67 ContentTestLauncherDelegate launcher_delegate; 137 ContentTestLauncherDelegate launcher_delegate;
68 return test_launcher::LaunchTests(&launcher_delegate, argc, argv); 138 return test_launcher::LaunchTests(&launcher_delegate, argc, argv);
69 } 139 }
OLDNEW
« no previous file with comments | « content/test/content_browser_test_utils.cc ('k') | content/test/data/simple_page.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698