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"
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"
22 // Content client that exists only to register chrome-extension:// scheme with
24 // TODO(jamescook): Should this be merged with ShellContentClient? Should this
25 // be a persistent object available to tests?
26 class ExtensionsContentClient
: public content::ContentClient
{
28 ExtensionsContentClient() {}
29 ~ExtensionsContentClient() override
{}
31 // content::ContentClient overrides:
32 void AddAdditionalSchemes(
33 std::vector
<std::string
>* standard_schemes
,
34 std::vector
<std::string
>* savable_schemes
) override
{
35 standard_schemes
->push_back(extensions::kExtensionScheme
);
36 savable_schemes
->push_back(extensions::kExtensionScheme
);
37 standard_schemes
->push_back(extensions::kExtensionResourceScheme
);
38 savable_schemes
->push_back(extensions::kExtensionResourceScheme
);
42 DISALLOW_COPY_AND_ASSIGN(ExtensionsContentClient
);
45 // The test suite for extensions_unittests.
46 class ExtensionsTestSuite
: public content::ContentTestSuiteBase
{
48 ExtensionsTestSuite(int argc
, char** argv
);
49 ~ExtensionsTestSuite() override
;
53 void Initialize() override
;
54 void Shutdown() override
;
56 scoped_ptr
<extensions::TestExtensionsClient
> client_
;
58 DISALLOW_COPY_AND_ASSIGN(ExtensionsTestSuite
);
61 ExtensionsTestSuite::ExtensionsTestSuite(int argc
, char** argv
)
62 : content::ContentTestSuiteBase(argc
, argv
) {}
64 ExtensionsTestSuite::~ExtensionsTestSuite() {}
66 void ExtensionsTestSuite::Initialize() {
67 content::ContentTestSuiteBase::Initialize();
68 gfx::GLSurfaceTestSupport::InitializeOneOff();
70 // Register the chrome-extension:// scheme via this circuitous path. Note
71 // that this does not persistently set up a ContentClient; individual tests
72 // must use content::SetContentClient().
74 ExtensionsContentClient content_client
;
75 RegisterContentSchemes(&content_client
);
77 RegisterInProcessThreads();
79 extensions::RegisterPathProvider();
81 base::FilePath extensions_shell_and_test_pak_path
;
82 PathService::Get(base::DIR_MODULE
, &extensions_shell_and_test_pak_path
);
83 ui::ResourceBundle::InitSharedInstanceWithPakPath(
84 extensions_shell_and_test_pak_path
.AppendASCII(
85 "extensions_shell_and_test.pak"));
87 client_
.reset(new extensions::TestExtensionsClient());
88 extensions::ExtensionsClient::Set(client_
.get());
91 void ExtensionsTestSuite::Shutdown() {
92 extensions::ExtensionsClient::Set(NULL
);
95 ui::ResourceBundle::CleanupSharedInstance();
96 content::ContentTestSuiteBase::Shutdown();
101 int main(int argc
, char** argv
) {
102 content::UnitTestTestSuite
test_suite(new ExtensionsTestSuite(argc
, argv
));
104 mojo::embedder::test::InitWithSimplePlatformSupport();
105 return base::LaunchUnitTests(argc
,
107 base::Bind(&content::UnitTestTestSuite::Run
,
108 base::Unretained(&test_suite
)));