[email protected] | 8c958aa4 | 2013-04-04 09:12:49 | [diff] [blame] | 1 | // Copyright (c) 2013 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 | |||||
5 | #include "base/command_line.h" | ||||
[email protected] | 8c958aa4 | 2013-04-04 09:12:49 | [diff] [blame] | 6 | #include "base/files/file_path.h" |
thestig | 18dfb7a5 | 2014-08-26 10:44:04 | [diff] [blame] | 7 | #include "base/files/file_util.h" |
[email protected] | 8c958aa4 | 2013-04-04 09:12:49 | [diff] [blame] | 8 | #include "base/files/scoped_temp_dir.h" |
[email protected] | 8c958aa4 | 2013-04-04 09:12:49 | [diff] [blame] | 9 | #include "base/path_service.h" |
10 | #include "chrome/browser/extensions/startup_helper.h" | ||||
11 | #include "chrome/common/chrome_paths.h" | ||||
12 | #include "chrome/common/chrome_switches.h" | ||||
Gabriel Charette | c710874 | 2019-08-23 03:31:40 | [diff] [blame] | 13 | #include "content/public/test/browser_task_environment.h" |
[email protected] | 8c958aa4 | 2013-04-04 09:12:49 | [diff] [blame] | 14 | #include "testing/gtest/include/gtest/gtest.h" |
15 | |||||
16 | namespace extensions { | ||||
17 | |||||
18 | // Tests the environment for packing extensions from the command line | ||||
[email protected] | c21b5b61 | 2013-07-31 07:49:16 | [diff] [blame] | 19 | // when using the --pack-extension switch. |
[email protected] | 8c958aa4 | 2013-04-04 09:12:49 | [diff] [blame] | 20 | class PackExtensionTest : public testing::Test { |
21 | public: | ||||
fdoray | 2ce6dc22 | 2017-04-27 14:39:39 | [diff] [blame] | 22 | PackExtensionTest() { |
Avi Drissman | 9098f900 | 2018-05-04 00:11:52 | [diff] [blame] | 23 | base::PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir_); |
[email protected] | 8c958aa4 | 2013-04-04 09:12:49 | [diff] [blame] | 24 | test_data_dir_ = test_data_dir_.AppendASCII("extensions"); |
25 | } | ||||
26 | |||||
27 | protected: | ||||
28 | bool TestPackExtension(const base::FilePath& path) { | ||||
29 | base::ScopedTempDir temp_dir; | ||||
30 | EXPECT_TRUE(temp_dir.CreateUniqueTempDir()); | ||||
vabr | 9142fe2 | 2016-09-08 13:19:22 | [diff] [blame] | 31 | EXPECT_TRUE(base::CopyDirectory(path, temp_dir.GetPath(), true)); |
avi | 3ef9ec9e | 2014-12-22 22:50:17 | [diff] [blame] | 32 | base::CommandLine command_line(base::CommandLine::NO_PROGRAM); |
[email protected] | 8c958aa4 | 2013-04-04 09:12:49 | [diff] [blame] | 33 | command_line.AppendSwitchPath(switches::kPackExtension, |
vabr | 9142fe2 | 2016-09-08 13:19:22 | [diff] [blame] | 34 | temp_dir.GetPath().Append(path.BaseName())); |
[email protected] | 8c958aa4 | 2013-04-04 09:12:49 | [diff] [blame] | 35 | return startup_helper_.PackExtension(command_line); |
36 | } | ||||
37 | |||||
Gabriel Charette | 798fde7 | 2019-08-20 22:24:04 | [diff] [blame] | 38 | content::BrowserTaskEnvironment task_environment_; |
[email protected] | 8c958aa4 | 2013-04-04 09:12:49 | [diff] [blame] | 39 | |
40 | base::FilePath test_data_dir_; | ||||
41 | StartupHelper startup_helper_; | ||||
42 | }; | ||||
43 | |||||
44 | TEST_F(PackExtensionTest, Extension) { | ||||
45 | ASSERT_TRUE(TestPackExtension(test_data_dir_.AppendASCII("api_test") | ||||
46 | .AppendASCII("tabs") | ||||
47 | .AppendASCII("basics"))); | ||||
48 | } | ||||
49 | |||||
Alexander Hendrich | 26c375c | 2019-11-20 14:49:01 | [diff] [blame] | 50 | TEST_F(PackExtensionTest, ExtensionWithManagedStorage) { |
51 | ASSERT_TRUE(TestPackExtension(test_data_dir_.AppendASCII("api_test") | ||||
52 | .AppendASCII("settings") | ||||
53 | .AppendASCII("managed_storage"))); | ||||
54 | } | ||||
55 | |||||
[email protected] | 8c958aa4 | 2013-04-04 09:12:49 | [diff] [blame] | 56 | TEST_F(PackExtensionTest, PackagedApp) { |
57 | ASSERT_TRUE(TestPackExtension(test_data_dir_.AppendASCII("packaged_app"))); | ||||
58 | } | ||||
59 | |||||
60 | TEST_F(PackExtensionTest, PlatformApp) { | ||||
61 | ASSERT_TRUE(TestPackExtension(test_data_dir_.AppendASCII("platform_apps") | ||||
62 | .AppendASCII("minimal"))); | ||||
63 | } | ||||
64 | |||||
65 | } // namespace extensions |