tfarina@chromium.org | 1ffebd3b | 2014-04-09 12:23:00 | [diff] [blame] | 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. |
| 4 | |
sammc@chromium.org | 582f6e9 | 2014-07-16 23:39:15 | [diff] [blame] | 5 | #include "base/base_paths.h" |
tfarina@chromium.org | 1ffebd3b | 2014-04-09 12:23:00 | [diff] [blame] | 6 | #include "base/bind.h" |
| 7 | #include "base/macros.h" |
sammc@chromium.org | 582f6e9 | 2014-07-16 23:39:15 | [diff] [blame] | 8 | #include "base/path_service.h" |
tfarina@chromium.org | 1ffebd3b | 2014-04-09 12:23:00 | [diff] [blame] | 9 | #include "base/test/launcher/unit_test_launcher.h" |
jamescook@chromium.org | 39ca2051 | 2014-07-24 12:35:52 | [diff] [blame] | 10 | #include "content/public/common/content_client.h" |
| 11 | #include "content/public/test/content_test_suite_base.h" |
sammc@chromium.org | 582f6e9 | 2014-07-16 23:39:15 | [diff] [blame] | 12 | #include "content/public/test/unittest_test_suite.h" |
jamescook@chromium.org | 39ca2051 | 2014-07-24 12:35:52 | [diff] [blame] | 13 | #include "extensions/common/constants.h" |
sammc@chromium.org | 582f6e9 | 2014-07-16 23:39:15 | [diff] [blame] | 14 | #include "extensions/common/extension_paths.h" |
tfarina@chromium.org | dc909f1 | 2014-04-14 00:50:37 | [diff] [blame] | 15 | #include "extensions/test/test_extensions_client.h" |
blundell | 471b74f | 2015-01-23 16:27:14 | [diff] [blame] | 16 | #include "third_party/mojo/src/mojo/edk/embedder/test_embedder.h" |
sammc@chromium.org | 582f6e9 | 2014-07-16 23:39:15 | [diff] [blame] | 17 | #include "ui/base/resource/resource_bundle.h" |
sadrul | ba162cd | 2015-07-20 22:34:26 | [diff] [blame^] | 18 | #include "ui/gl/test/gl_surface_test_support.h" |
tfarina@chromium.org | 1ffebd3b | 2014-04-09 12:23:00 | [diff] [blame] | 19 | |
| 20 | namespace { |
| 21 | |
jamescook@chromium.org | 39ca2051 | 2014-07-24 12:35:52 | [diff] [blame] | 22 | // Content client that exists only to register chrome-extension:// scheme with |
| 23 | // the url module. |
| 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 { |
| 27 | public: |
| 28 | ExtensionsContentClient() {} |
dcheng | 9168b2f | 2014-10-21 12:38:24 | [diff] [blame] | 29 | ~ExtensionsContentClient() override {} |
jamescook@chromium.org | 39ca2051 | 2014-07-24 12:35:52 | [diff] [blame] | 30 | |
| 31 | // content::ContentClient overrides: |
dcheng | 9168b2f | 2014-10-21 12:38:24 | [diff] [blame] | 32 | void AddAdditionalSchemes( |
jamescook@chromium.org | 39ca2051 | 2014-07-24 12:35:52 | [diff] [blame] | 33 | std::vector<std::string>* standard_schemes, |
mostynb | 0eac4e1 | 2014-10-03 16:32:19 | [diff] [blame] | 34 | std::vector<std::string>* savable_schemes) override { |
jamescook@chromium.org | 39ca2051 | 2014-07-24 12:35:52 | [diff] [blame] | 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); |
| 39 | } |
| 40 | |
| 41 | private: |
| 42 | DISALLOW_COPY_AND_ASSIGN(ExtensionsContentClient); |
| 43 | }; |
| 44 | |
| 45 | // The test suite for extensions_unittests. |
| 46 | class ExtensionsTestSuite : public content::ContentTestSuiteBase { |
tfarina@chromium.org | 1ffebd3b | 2014-04-09 12:23:00 | [diff] [blame] | 47 | public: |
| 48 | ExtensionsTestSuite(int argc, char** argv); |
dcheng | 9168b2f | 2014-10-21 12:38:24 | [diff] [blame] | 49 | ~ExtensionsTestSuite() override; |
tfarina@chromium.org | 1ffebd3b | 2014-04-09 12:23:00 | [diff] [blame] | 50 | |
tfarina@chromium.org | dc909f1 | 2014-04-14 00:50:37 | [diff] [blame] | 51 | private: |
tfarina@chromium.org | 1ffebd3b | 2014-04-09 12:23:00 | [diff] [blame] | 52 | // base::TestSuite: |
dcheng | 9168b2f | 2014-10-21 12:38:24 | [diff] [blame] | 53 | void Initialize() override; |
| 54 | void Shutdown() override; |
tfarina@chromium.org | 1ffebd3b | 2014-04-09 12:23:00 | [diff] [blame] | 55 | |
tfarina@chromium.org | dc909f1 | 2014-04-14 00:50:37 | [diff] [blame] | 56 | scoped_ptr<extensions::TestExtensionsClient> client_; |
| 57 | |
tfarina@chromium.org | 1ffebd3b | 2014-04-09 12:23:00 | [diff] [blame] | 58 | DISALLOW_COPY_AND_ASSIGN(ExtensionsTestSuite); |
| 59 | }; |
| 60 | |
| 61 | ExtensionsTestSuite::ExtensionsTestSuite(int argc, char** argv) |
jamescook@chromium.org | 39ca2051 | 2014-07-24 12:35:52 | [diff] [blame] | 62 | : content::ContentTestSuiteBase(argc, argv) {} |
| 63 | |
| 64 | ExtensionsTestSuite::~ExtensionsTestSuite() {} |
tfarina@chromium.org | 1ffebd3b | 2014-04-09 12:23:00 | [diff] [blame] | 65 | |
| 66 | void ExtensionsTestSuite::Initialize() { |
jamescook@chromium.org | 39ca2051 | 2014-07-24 12:35:52 | [diff] [blame] | 67 | content::ContentTestSuiteBase::Initialize(); |
sadrul | ba162cd | 2015-07-20 22:34:26 | [diff] [blame^] | 68 | gfx::GLSurfaceTestSupport::InitializeOneOff(); |
jamescook@chromium.org | 39ca2051 | 2014-07-24 12:35:52 | [diff] [blame] | 69 | |
| 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(). |
| 73 | { |
| 74 | ExtensionsContentClient content_client; |
| 75 | RegisterContentSchemes(&content_client); |
| 76 | } |
asargent | 275faaa | 2015-01-27 23:43:29 | [diff] [blame] | 77 | RegisterInProcessThreads(); |
tfarina@chromium.org | dc909f1 | 2014-04-14 00:50:37 | [diff] [blame] | 78 | |
sammc@chromium.org | 582f6e9 | 2014-07-16 23:39:15 | [diff] [blame] | 79 | extensions::RegisterPathProvider(); |
| 80 | |
tfarina@chromium.org | 02b2c90 | 2014-07-30 16:34:40 | [diff] [blame] | 81 | base::FilePath extensions_shell_and_test_pak_path; |
| 82 | PathService::Get(base::DIR_MODULE, &extensions_shell_and_test_pak_path); |
tfarina@chromium.org | b49ced6 | 2014-07-25 16:47:03 | [diff] [blame] | 83 | ui::ResourceBundle::InitSharedInstanceWithPakPath( |
tfarina@chromium.org | 02b2c90 | 2014-07-30 16:34:40 | [diff] [blame] | 84 | extensions_shell_and_test_pak_path.AppendASCII( |
| 85 | "extensions_shell_and_test.pak")); |
sammc@chromium.org | 582f6e9 | 2014-07-16 23:39:15 | [diff] [blame] | 86 | |
tfarina@chromium.org | dc909f1 | 2014-04-14 00:50:37 | [diff] [blame] | 87 | client_.reset(new extensions::TestExtensionsClient()); |
| 88 | extensions::ExtensionsClient::Set(client_.get()); |
tfarina@chromium.org | 1ffebd3b | 2014-04-09 12:23:00 | [diff] [blame] | 89 | } |
| 90 | |
| 91 | void ExtensionsTestSuite::Shutdown() { |
jamescook@chromium.org | 39ca2051 | 2014-07-24 12:35:52 | [diff] [blame] | 92 | extensions::ExtensionsClient::Set(NULL); |
| 93 | client_.reset(); |
| 94 | |
tfarina@chromium.org | b49ced6 | 2014-07-25 16:47:03 | [diff] [blame] | 95 | ui::ResourceBundle::CleanupSharedInstance(); |
jamescook@chromium.org | 39ca2051 | 2014-07-24 12:35:52 | [diff] [blame] | 96 | content::ContentTestSuiteBase::Shutdown(); |
tfarina@chromium.org | 1ffebd3b | 2014-04-09 12:23:00 | [diff] [blame] | 97 | } |
| 98 | |
| 99 | } // namespace |
| 100 | |
| 101 | int main(int argc, char** argv) { |
sammc@chromium.org | 582f6e9 | 2014-07-16 23:39:15 | [diff] [blame] | 102 | content::UnitTestTestSuite test_suite(new ExtensionsTestSuite(argc, argv)); |
tfarina@chromium.org | 1ffebd3b | 2014-04-09 12:23:00 | [diff] [blame] | 103 | |
viettrungluu@chromium.org | cf74402 | 2014-08-20 17:09:37 | [diff] [blame] | 104 | mojo::embedder::test::InitWithSimplePlatformSupport(); |
tfarina@chromium.org | 1ffebd3b | 2014-04-09 12:23:00 | [diff] [blame] | 105 | return base::LaunchUnitTests(argc, |
| 106 | argv, |
sammc@chromium.org | 582f6e9 | 2014-07-16 23:39:15 | [diff] [blame] | 107 | base::Bind(&content::UnitTestTestSuite::Run, |
tfarina@chromium.org | 1ffebd3b | 2014-04-09 12:23:00 | [diff] [blame] | 108 | base::Unretained(&test_suite))); |
| 109 | } |