Remove linux_chromium_gn_dbg from the chromium CQ.
[chromium-blink-merge.git] / extensions / test / extensions_unittests_main.cc
blobf39e40dd92e8a4f698a92531cad51b61404ed2ed
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "base/base_paths.h"
6 #include "base/bind.h"
7 #include "base/macros.h"
8 #include "base/path_service.h"
9 #include "base/test/launcher/unit_test_launcher.h"
10 #include "content/public/common/content_client.h"
11 #include "content/public/test/content_test_suite_base.h"
12 #include "content/public/test/unittest_test_suite.h"
13 #include "extensions/common/constants.h"
14 #include "extensions/common/extension_paths.h"
15 #include "extensions/test/test_extensions_client.h"
16 #include "third_party/mojo/src/mojo/edk/embedder/test_embedder.h"
17 #include "ui/base/resource/resource_bundle.h"
18 #include "ui/gl/test/gl_surface_test_support.h"
19 #include "url/url_util.h"
21 namespace {
23 const int kNumExtensionStandardURLSchemes = 2;
24 const url::SchemeWithType kExtensionStandardURLSchemes[
25 kNumExtensionStandardURLSchemes] = {
26 {extensions::kExtensionScheme, url::SCHEME_WITHOUT_PORT},
27 {extensions::kExtensionResourceScheme, url::SCHEME_WITHOUT_PORT},
30 // Content client that exists only to register chrome-extension:// scheme with
31 // the url module.
32 // TODO(jamescook): Should this be merged with ShellContentClient? Should this
33 // be a persistent object available to tests?
34 class ExtensionsContentClient : public content::ContentClient {
35 public:
36 ExtensionsContentClient() {}
37 ~ExtensionsContentClient() override {}
39 // content::ContentClient overrides:
40 void AddAdditionalSchemes(
41 std::vector<url::SchemeWithType>* standard_schemes,
42 std::vector<std::string>* savable_schemes) override {
43 for (int i = 0; i < kNumExtensionStandardURLSchemes; i++)
44 standard_schemes->push_back(kExtensionStandardURLSchemes[i]);
46 savable_schemes->push_back(extensions::kExtensionScheme);
47 savable_schemes->push_back(extensions::kExtensionResourceScheme);
50 private:
51 DISALLOW_COPY_AND_ASSIGN(ExtensionsContentClient);
54 // The test suite for extensions_unittests.
55 class ExtensionsTestSuite : public content::ContentTestSuiteBase {
56 public:
57 ExtensionsTestSuite(int argc, char** argv);
58 ~ExtensionsTestSuite() override;
60 private:
61 // base::TestSuite:
62 void Initialize() override;
63 void Shutdown() override;
65 scoped_ptr<extensions::TestExtensionsClient> client_;
67 DISALLOW_COPY_AND_ASSIGN(ExtensionsTestSuite);
70 ExtensionsTestSuite::ExtensionsTestSuite(int argc, char** argv)
71 : content::ContentTestSuiteBase(argc, argv) {}
73 ExtensionsTestSuite::~ExtensionsTestSuite() {}
75 void ExtensionsTestSuite::Initialize() {
76 content::ContentTestSuiteBase::Initialize();
77 gfx::GLSurfaceTestSupport::InitializeOneOff();
79 // Register the chrome-extension:// scheme via this circuitous path. Note
80 // that this does not persistently set up a ContentClient; individual tests
81 // must use content::SetContentClient().
83 ExtensionsContentClient content_client;
84 RegisterContentSchemes(&content_client);
86 RegisterInProcessThreads();
88 extensions::RegisterPathProvider();
90 base::FilePath extensions_shell_and_test_pak_path;
91 PathService::Get(base::DIR_MODULE, &extensions_shell_and_test_pak_path);
92 ui::ResourceBundle::InitSharedInstanceWithPakPath(
93 extensions_shell_and_test_pak_path.AppendASCII(
94 "extensions_shell_and_test.pak"));
96 client_.reset(new extensions::TestExtensionsClient());
97 extensions::ExtensionsClient::Set(client_.get());
100 void ExtensionsTestSuite::Shutdown() {
101 extensions::ExtensionsClient::Set(NULL);
102 client_.reset();
104 ui::ResourceBundle::CleanupSharedInstance();
105 content::ContentTestSuiteBase::Shutdown();
108 } // namespace
110 int main(int argc, char** argv) {
111 content::UnitTestTestSuite test_suite(new ExtensionsTestSuite(argc, argv));
113 mojo::embedder::test::InitWithSimplePlatformSupport();
114 return base::LaunchUnitTests(argc,
115 argv,
116 base::Bind(&content::UnitTestTestSuite::Run,
117 base::Unretained(&test_suite)));