test_extension_dir.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. #ifndef EXTENSIONS_TEST_TEST_EXTENSION_DIR_H_
  5. #define EXTENSIONS_TEST_TEST_EXTENSION_DIR_H_
  6. #include "base/files/file_path.h"
  7. #include "base/files/scoped_temp_dir.h"
  8. #include "base/strings/string_piece.h"
  9. namespace extensions {
  10. // Provides a temporary directory to build an extension into. This lets all of
  11. // an extension's code live inside the test instead of in a separate directory.
  12. class TestExtensionDir {
  13. public:
  14. TestExtensionDir();
  15. ~TestExtensionDir();
  16. // Writes |manifest| to manifest.json within the unpacked dir. No validation
  17. // is performed. If desired this should be done on extension installation.
  18. void WriteManifest(base::StringPiece manifest);
  19. // Writes |contents| to |filename| within the unpacked dir, overwriting
  20. // anything that was already there.
  21. void WriteFile(const base::FilePath::StringType& filename,
  22. base::StringPiece contents);
  23. // Copies the file at |from_path| into |local_filename| under the temp
  24. // directory, overwriting anything that was already there.
  25. void CopyFileTo(const base::FilePath& from_path,
  26. const base::FilePath::StringType& local_filename);
  27. // Packs the extension into a .crx, and returns the path to that
  28. // .crx. Multiple calls to Pack() will produce extensions with the same ID.
  29. base::FilePath Pack();
  30. // Returns the path to the unpacked directory.
  31. base::FilePath UnpackedPath() const;
  32. private:
  33. // Stores files that make up the extension.
  34. base::ScopedTempDir dir_;
  35. // Stores the generated .crx and .pem.
  36. base::ScopedTempDir crx_dir_;
  37. };
  38. } // namespace extensions
  39. #endif // EXTENSIONS_TEST_TEST_EXTENSION_DIR_H_