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 "ui/base/resource/resource_bundle.h"
20 // Content client that exists only to register chrome-extension:// scheme with
22 // TODO(jamescook): Should this be merged with ShellContentClient? Should this
23 // be a persistent object available to tests?
24 class ExtensionsContentClient
: public content::ContentClient
{
26 ExtensionsContentClient() {}
27 virtual ~ExtensionsContentClient() {}
29 // content::ContentClient overrides:
30 virtual void AddAdditionalSchemes(
31 std::vector
<std::string
>* standard_schemes
,
32 std::vector
<std::string
>* savable_schemes
) OVERRIDE
{
33 standard_schemes
->push_back(extensions::kExtensionScheme
);
34 savable_schemes
->push_back(extensions::kExtensionScheme
);
35 standard_schemes
->push_back(extensions::kExtensionResourceScheme
);
36 savable_schemes
->push_back(extensions::kExtensionResourceScheme
);
40 DISALLOW_COPY_AND_ASSIGN(ExtensionsContentClient
);
43 // The test suite for extensions_unittests.
44 class ExtensionsTestSuite
: public content::ContentTestSuiteBase
{
46 ExtensionsTestSuite(int argc
, char** argv
);
47 virtual ~ExtensionsTestSuite();
51 virtual void Initialize() OVERRIDE
;
52 virtual void Shutdown() OVERRIDE
;
54 scoped_ptr
<extensions::TestExtensionsClient
> client_
;
56 DISALLOW_COPY_AND_ASSIGN(ExtensionsTestSuite
);
59 ExtensionsTestSuite::ExtensionsTestSuite(int argc
, char** argv
)
60 : content::ContentTestSuiteBase(argc
, argv
) {}
62 ExtensionsTestSuite::~ExtensionsTestSuite() {}
64 void ExtensionsTestSuite::Initialize() {
65 content::ContentTestSuiteBase::Initialize();
67 // Register the chrome-extension:// scheme via this circuitous path. Note
68 // that this does not persistently set up a ContentClient; individual tests
69 // must use content::SetContentClient().
71 ExtensionsContentClient content_client
;
72 RegisterContentSchemes(&content_client
);
75 extensions::RegisterPathProvider();
77 base::FilePath resources_pack_path
;
78 PathService::Get(base::DIR_MODULE
, &resources_pack_path
);
79 ResourceBundle::InitSharedInstanceWithPakPath(
80 resources_pack_path
.AppendASCII("extensions_unittests_resources.pak"));
82 client_
.reset(new extensions::TestExtensionsClient());
83 extensions::ExtensionsClient::Set(client_
.get());
86 void ExtensionsTestSuite::Shutdown() {
87 extensions::ExtensionsClient::Set(NULL
);
90 ResourceBundle::CleanupSharedInstance();
91 content::ContentTestSuiteBase::Shutdown();
96 int main(int argc
, char** argv
) {
97 content::UnitTestTestSuite
test_suite(new ExtensionsTestSuite(argc
, argv
));
99 return base::LaunchUnitTests(argc
,
101 base::Bind(&content::UnitTestTestSuite::Run
,
102 base::Unretained(&test_suite
)));