1 // Copyright 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.
5 #ifndef CHROME_BROWSER_EXTENSIONS_TEST_EXTENSION_DIR_H_
6 #define CHROME_BROWSER_EXTENSIONS_TEST_EXTENSION_DIR_H_
8 #include "base/files/file_path.h"
9 #include "base/files/scoped_temp_dir.h"
10 #include "base/strings/string_piece.h"
12 namespace extensions
{
14 // Provides a temporary directory to build an extension into. This lets all of
15 // an extension's code live inside the test instead of in a separate directory.
16 class TestExtensionDir
{
22 // Writes |manifest| to manifest.json within the unpacked dir. No validation
23 // is performed. If desired this should be done on extension installation.
24 void WriteManifest(base::StringPiece manifest
);
26 // Like WriteManifest, but where the |manifest| is given in single-quotes
27 // rather than double-quotes. This is for convenience to avoid escaping.
29 // E.g. |manifest| can be {'name': 'me'} rather than {\"name\": \"me\"}.
30 void WriteManifestWithSingleQuotes(base::StringPiece manifest
);
32 // Writes |contents| to |filename| within the unpacked dir, overwriting
33 // anything that was already there.
34 void WriteFile(const base::FilePath::StringType
& filename
,
35 base::StringPiece contents
);
37 // Packs the extension into a .crx, and returns the path to that
38 // .crx. Multiple calls to Pack() will produce extensions with the same ID.
39 base::FilePath
Pack();
41 // Returns the path to the unpacked directory.
42 base::FilePath
unpacked_path() {
47 // Stores files that make up the extension.
48 base::ScopedTempDir dir_
;
50 // Stores the generated .crx and .pem.
51 base::ScopedTempDir crx_dir_
;
54 } // namespace extensions
56 #endif // CHROME_BROWSER_EXTENSIONS_TEST_EXTENSION_DIR_H_