blob: 8b72ef8891243bb6a340425002f947205c8cc2ac [file] [log] [blame]
[email protected]1ffebd3b2014-04-09 12:23:001// 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.
4
dcheng4a7e93b2016-04-23 00:27:165#include <memory>
6
[email protected]582f6e92014-07-16 23:39:157#include "base/base_paths.h"
[email protected]1ffebd3b2014-04-09 12:23:008#include "base/bind.h"
9#include "base/macros.h"
[email protected]582f6e92014-07-16 23:39:1510#include "base/path_service.h"
[email protected]1ffebd3b2014-04-09 12:23:0011#include "base/test/launcher/unit_test_launcher.h"
amistry780142d2016-04-01 02:18:3512#include "base/test/test_io_thread.h"
[email protected]39ca20512014-07-24 12:35:5213#include "content/public/common/content_client.h"
14#include "content/public/test/content_test_suite_base.h"
[email protected]582f6e92014-07-16 23:39:1515#include "content/public/test/unittest_test_suite.h"
[email protected]39ca20512014-07-24 12:35:5216#include "extensions/common/constants.h"
[email protected]582f6e92014-07-16 23:39:1517#include "extensions/common/extension_paths.h"
[email protected]dc909f12014-04-14 00:50:3718#include "extensions/test/test_extensions_client.h"
[email protected]582f6e92014-07-16 23:39:1519#include "ui/base/resource/resource_bundle.h"
sadrulba162cd2015-07-20 22:34:2620#include "ui/gl/test/gl_surface_test_support.h"
tyoshino11a7c9fe2015-08-19 08:51:4621#include "url/url_util.h"
[email protected]1ffebd3b2014-04-09 12:23:0022
23namespace {
24
[email protected]39ca20512014-07-24 12:35:5225// Content client that exists only to register chrome-extension:// scheme with
26// the url module.
27// TODO(jamescook): Should this be merged with ShellContentClient? Should this
28// be a persistent object available to tests?
29class ExtensionsContentClient : public content::ContentClient {
30 public:
31 ExtensionsContentClient() {}
dcheng9168b2f2014-10-21 12:38:2432 ~ExtensionsContentClient() override {}
[email protected]39ca20512014-07-24 12:35:5233
34 // content::ContentClient overrides:
jame0dcd982017-01-11 03:13:4535 void AddAdditionalSchemes(Schemes* schemes) override {
36 schemes->standard_schemes.push_back(extensions::kExtensionScheme);
37 schemes->savable_schemes.push_back(extensions::kExtensionScheme);
[email protected]39ca20512014-07-24 12:35:5238 }
39
40 private:
41 DISALLOW_COPY_AND_ASSIGN(ExtensionsContentClient);
42};
43
44// The test suite for extensions_unittests.
45class ExtensionsTestSuite : public content::ContentTestSuiteBase {
[email protected]1ffebd3b2014-04-09 12:23:0046 public:
47 ExtensionsTestSuite(int argc, char** argv);
dcheng9168b2f2014-10-21 12:38:2448 ~ExtensionsTestSuite() override;
[email protected]1ffebd3b2014-04-09 12:23:0049
[email protected]dc909f12014-04-14 00:50:3750 private:
[email protected]1ffebd3b2014-04-09 12:23:0051 // base::TestSuite:
dcheng9168b2f2014-10-21 12:38:2452 void Initialize() override;
53 void Shutdown() override;
[email protected]1ffebd3b2014-04-09 12:23:0054
dcheng4a7e93b2016-04-23 00:27:1655 std::unique_ptr<extensions::TestExtensionsClient> client_;
[email protected]dc909f12014-04-14 00:50:3756
[email protected]1ffebd3b2014-04-09 12:23:0057 DISALLOW_COPY_AND_ASSIGN(ExtensionsTestSuite);
58};
59
60ExtensionsTestSuite::ExtensionsTestSuite(int argc, char** argv)
[email protected]39ca20512014-07-24 12:35:5261 : content::ContentTestSuiteBase(argc, argv) {}
62
63ExtensionsTestSuite::~ExtensionsTestSuite() {}
[email protected]1ffebd3b2014-04-09 12:23:0064
65void ExtensionsTestSuite::Initialize() {
[email protected]39ca20512014-07-24 12:35:5266 content::ContentTestSuiteBase::Initialize();
kylechar7a463842016-05-26 14:46:1267 gl::GLSurfaceTestSupport::InitializeOneOff();
[email protected]39ca20512014-07-24 12:35:5268
69 // Register the chrome-extension:// scheme via this circuitous path. Note
70 // that this does not persistently set up a ContentClient; individual tests
71 // must use content::SetContentClient().
72 {
73 ExtensionsContentClient content_client;
74 RegisterContentSchemes(&content_client);
75 }
asargent275faaa2015-01-27 23:43:2976 RegisterInProcessThreads();
[email protected]dc909f12014-04-14 00:50:3777
[email protected]582f6e92014-07-16 23:39:1578 extensions::RegisterPathProvider();
79
[email protected]02b2c902014-07-30 16:34:4080 base::FilePath extensions_shell_and_test_pak_path;
81 PathService::Get(base::DIR_MODULE, &extensions_shell_and_test_pak_path);
[email protected]b49ced62014-07-25 16:47:0382 ui::ResourceBundle::InitSharedInstanceWithPakPath(
[email protected]02b2c902014-07-30 16:34:4083 extensions_shell_and_test_pak_path.AppendASCII(
84 "extensions_shell_and_test.pak"));
[email protected]582f6e92014-07-16 23:39:1585
[email protected]dc909f12014-04-14 00:50:3786 client_.reset(new extensions::TestExtensionsClient());
87 extensions::ExtensionsClient::Set(client_.get());
[email protected]1ffebd3b2014-04-09 12:23:0088}
89
90void ExtensionsTestSuite::Shutdown() {
[email protected]39ca20512014-07-24 12:35:5291 extensions::ExtensionsClient::Set(NULL);
92 client_.reset();
93
[email protected]b49ced62014-07-25 16:47:0394 ui::ResourceBundle::CleanupSharedInstance();
[email protected]39ca20512014-07-24 12:35:5295 content::ContentTestSuiteBase::Shutdown();
[email protected]1ffebd3b2014-04-09 12:23:0096}
97
98} // namespace
99
100int main(int argc, char** argv) {
[email protected]582f6e92014-07-16 23:39:15101 content::UnitTestTestSuite test_suite(new ExtensionsTestSuite(argc, argv));
[email protected]1ffebd3b2014-04-09 12:23:00102 return base::LaunchUnitTests(argc,
103 argv,
[email protected]582f6e92014-07-16 23:39:15104 base::Bind(&content::UnitTestTestSuite::Run,
[email protected]1ffebd3b2014-04-09 12:23:00105 base::Unretained(&test_suite)));
106}