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. 4 5 #ifndef CHROME_BROWSER_EXTENSIONS_TEST_EXTENSION_DIR_H_ 6 #define CHROME_BROWSER_EXTENSIONS_TEST_EXTENSION_DIR_H_ 7 8 #include "base/files/file_path.h" 9 #include "base/files/scoped_temp_dir.h" 10 #include "base/strings/string_piece.h" 11 12 namespace extensions { 13 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 { 17 public: 18 TestExtensionDir(); 19 20 ~TestExtensionDir(); 21 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); 25 26 // Writes |contents| to |filename| within the unpacked dir, overwriting 27 // anything that was already there. 28 void WriteFile(const base::FilePath::StringType& filename, 29 base::StringPiece contents); 30 31 // Packs the extension into a .crx, and returns the path to that 32 // .crx. Multiple calls to Pack() will produce extensions with the same ID. 33 base::FilePath Pack(); 34 35 // Returns the path to the unpacked directory. 36 base::FilePath unpacked_path() { 37 return dir_.path(); 38 } 39 40 private: 41 // Stores files that make up the extension. 42 base::ScopedTempDir dir_; 43 44 // Stores the generated .crx and .pem. 45 base::ScopedTempDir crx_dir_; 46 }; 47 48 } // namespace extensions 49 50 #endif // CHROME_BROWSER_EXTENSIONS_TEST_EXTENSION_DIR_H_ 51