blob: 1723e870ced7a9f67d2ac97389a2616862cf019c [file] [log] [blame]
[email protected]8c958aa42013-04-04 09:12:491// 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]8c958aa42013-04-04 09:12:496#include "base/files/file_path.h"
thestig18dfb7a52014-08-26 10:44:047#include "base/files/file_util.h"
[email protected]8c958aa42013-04-04 09:12:498#include "base/files/scoped_temp_dir.h"
[email protected]8c958aa42013-04-04 09:12:499#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 Charettec7108742019-08-23 03:31:4013#include "content/public/test/browser_task_environment.h"
[email protected]8c958aa42013-04-04 09:12:4914#include "testing/gtest/include/gtest/gtest.h"
15
16namespace extensions {
17
18// Tests the environment for packing extensions from the command line
[email protected]c21b5b612013-07-31 07:49:1619// when using the --pack-extension switch.
[email protected]8c958aa42013-04-04 09:12:4920class PackExtensionTest : public testing::Test {
21 public:
fdoray2ce6dc222017-04-27 14:39:3922 PackExtensionTest() {
Avi Drissman9098f9002018-05-04 00:11:5223 base::PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir_);
[email protected]8c958aa42013-04-04 09:12:4924 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());
vabr9142fe22016-09-08 13:19:2231 EXPECT_TRUE(base::CopyDirectory(path, temp_dir.GetPath(), true));
avi3ef9ec9e2014-12-22 22:50:1732 base::CommandLine command_line(base::CommandLine::NO_PROGRAM);
[email protected]8c958aa42013-04-04 09:12:4933 command_line.AppendSwitchPath(switches::kPackExtension,
vabr9142fe22016-09-08 13:19:2234 temp_dir.GetPath().Append(path.BaseName()));
[email protected]8c958aa42013-04-04 09:12:4935 return startup_helper_.PackExtension(command_line);
36 }
37
Gabriel Charette798fde72019-08-20 22:24:0438 content::BrowserTaskEnvironment task_environment_;
[email protected]8c958aa42013-04-04 09:12:4939
40 base::FilePath test_data_dir_;
41 StartupHelper startup_helper_;
42};
43
44TEST_F(PackExtensionTest, Extension) {
45 ASSERT_TRUE(TestPackExtension(test_data_dir_.AppendASCII("api_test")
46 .AppendASCII("tabs")
47 .AppendASCII("basics")));
48}
49
Alexander Hendrich26c375c2019-11-20 14:49:0150TEST_F(PackExtensionTest, ExtensionWithManagedStorage) {
51 ASSERT_TRUE(TestPackExtension(test_data_dir_.AppendASCII("api_test")
52 .AppendASCII("settings")
53 .AppendASCII("managed_storage")));
54}
55
[email protected]8c958aa42013-04-04 09:12:4956TEST_F(PackExtensionTest, PackagedApp) {
57 ASSERT_TRUE(TestPackExtension(test_data_dir_.AppendASCII("packaged_app")));
58}
59
60TEST_F(PackExtensionTest, PlatformApp) {
61 ASSERT_TRUE(TestPackExtension(test_data_dir_.AppendASCII("platform_apps")
62 .AppendASCII("minimal")));
63}
64
65} // namespace extensions