Chromium Code Reviews| Index: headless/test/headless_test_launcher.cc |
| diff --git a/headless/test/headless_test_launcher.cc b/headless/test/headless_test_launcher.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..1ced1978319a3a294f430868d18cc9f82761d50f |
| --- /dev/null |
| +++ b/headless/test/headless_test_launcher.cc |
| @@ -0,0 +1,66 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "base/bind.h" |
| +#include "base/macros.h" |
| +#include "base/sys_info.h" |
| +#include "content/public/test/content_test_suite_base.h" |
| +#include "content/public/test/test_launcher.h" |
| +#include "headless/lib/browser/headless_browser_impl.h" |
| +#include "headless/lib/headless_content_main_delegate.h" |
| +#include "testing/gtest/include/gtest/gtest.h" |
| + |
| +namespace headless { |
| +namespace { |
| + |
| +class HeadlessBrowserImplForTest : public HeadlessBrowserImpl { |
| + public: |
| + explicit HeadlessBrowserImplForTest(const HeadlessBrowser::Options& options) |
| + : HeadlessBrowserImpl(base::Bind(&HeadlessBrowserImplForTest::OnStart, |
| + base::Unretained(this)), |
| + options) {} |
| + |
| + void OnStart(HeadlessBrowser* browser) { DCHECK(browser == this); } |
|
Ryan Sleevi
2016/02/25 22:04:37
You should never DCHECK in tests.
Sami
2016/02/26 18:49:16
Changed into EXPECT_EQ.
|
| + |
| + private: |
| + DISALLOW_COPY_AND_ASSIGN(HeadlessBrowserImplForTest); |
| +}; |
| + |
| +class HeadlessTestLauncherDelegate : public content::TestLauncherDelegate { |
| + public: |
| + HeadlessTestLauncherDelegate() {} |
| + ~HeadlessTestLauncherDelegate() override {} |
| + |
| + // content::TestLauncherDelegate implementation: |
| + int RunTestSuite(int argc, char** argv) override { |
| + return base::TestSuite(argc, argv).Run(); |
| + } |
| + |
| + bool AdjustChildProcessCommandLine( |
| + base::CommandLine* command_line, |
| + const base::FilePath& temp_data_dir) override { |
| + return true; |
| + } |
| + |
| + protected: |
| + content::ContentMainDelegate* CreateContentMainDelegate() override { |
| + // TODO(skyostil): Add a way to test custom options. |
| + HeadlessBrowser::Options::Builder options_builder(0, nullptr); |
| + scoped_ptr<HeadlessBrowserImpl> browser( |
| + new HeadlessBrowserImplForTest(options_builder.Build())); |
| + return new HeadlessContentMainDelegate(std::move(browser)); |
| + } |
| + |
| + private: |
| + DISALLOW_COPY_AND_ASSIGN(HeadlessTestLauncherDelegate); |
| +}; |
| + |
| +} // namespace |
| +} // namespace headless |
| + |
| +int main(int argc, char** argv) { |
| + int default_jobs = std::max(1, base::SysInfo::NumberOfProcessors() / 2); |
| + headless::HeadlessTestLauncherDelegate launcher_delegate; |
| + return LaunchTests(&launcher_delegate, default_jobs, argc, argv); |
| +} |