OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/extensions/test_extension_dir.h" | 5 #include "chrome/browser/extensions/test_extension_dir.h" |
6 | 6 |
7 #include "base/files/file_util.h" | 7 #include "base/files/file_util.h" |
8 #include "base/json/json_writer.h" | 8 #include "base/json/json_writer.h" |
9 #include "base/numerics/safe_conversions.h" | 9 #include "base/numerics/safe_conversions.h" |
10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
(...skipping 17 matching lines...) Expand all Loading... |
28 | 28 |
29 void TestExtensionDir::WriteManifestWithSingleQuotes( | 29 void TestExtensionDir::WriteManifestWithSingleQuotes( |
30 base::StringPiece manifest) { | 30 base::StringPiece manifest) { |
31 std::string double_quotes; | 31 std::string double_quotes; |
32 base::ReplaceChars(manifest.data(), "'", "\"", &double_quotes); | 32 base::ReplaceChars(manifest.data(), "'", "\"", &double_quotes); |
33 WriteManifest(double_quotes); | 33 WriteManifest(double_quotes); |
34 } | 34 } |
35 | 35 |
36 void TestExtensionDir::WriteFile(const base::FilePath::StringType& filename, | 36 void TestExtensionDir::WriteFile(const base::FilePath::StringType& filename, |
37 base::StringPiece contents) { | 37 base::StringPiece contents) { |
38 EXPECT_EQ( | 38 EXPECT_EQ(base::checked_cast<int>(contents.size()), |
39 base::checked_cast<int>(contents.size()), | 39 base::WriteFile(dir_.GetPath().Append(filename), contents.data(), |
40 base::WriteFile( | 40 contents.size())); |
41 dir_.path().Append(filename), contents.data(), contents.size())); | |
42 } | 41 } |
43 | 42 |
44 // This function packs the extension into a .crx, and returns the path to that | 43 // This function packs the extension into a .crx, and returns the path to that |
45 // .crx. Multiple calls to Pack() will produce extensions with the same ID. | 44 // .crx. Multiple calls to Pack() will produce extensions with the same ID. |
46 base::FilePath TestExtensionDir::Pack() { | 45 base::FilePath TestExtensionDir::Pack() { |
47 ExtensionCreator creator; | 46 ExtensionCreator creator; |
48 base::FilePath crx_path = | 47 base::FilePath crx_path = |
49 crx_dir_.path().Append(FILE_PATH_LITERAL("ext.crx")); | 48 crx_dir_.GetPath().Append(FILE_PATH_LITERAL("ext.crx")); |
50 base::FilePath pem_path = | 49 base::FilePath pem_path = |
51 crx_dir_.path().Append(FILE_PATH_LITERAL("ext.pem")); | 50 crx_dir_.GetPath().Append(FILE_PATH_LITERAL("ext.pem")); |
52 base::FilePath pem_in_path, pem_out_path; | 51 base::FilePath pem_in_path, pem_out_path; |
53 if (base::PathExists(pem_path)) | 52 if (base::PathExists(pem_path)) |
54 pem_in_path = pem_path; | 53 pem_in_path = pem_path; |
55 else | 54 else |
56 pem_out_path = pem_path; | 55 pem_out_path = pem_path; |
57 if (!creator.Run(dir_.path(), | 56 if (!creator.Run(dir_.GetPath(), crx_path, pem_in_path, pem_out_path, |
58 crx_path, | |
59 pem_in_path, | |
60 pem_out_path, | |
61 ExtensionCreator::kOverwriteCRX)) { | 57 ExtensionCreator::kOverwriteCRX)) { |
62 ADD_FAILURE() | 58 ADD_FAILURE() |
63 << "ExtensionCreator::Run() failed: " << creator.error_message(); | 59 << "ExtensionCreator::Run() failed: " << creator.error_message(); |
64 return base::FilePath(); | 60 return base::FilePath(); |
65 } | 61 } |
66 if (!base::PathExists(crx_path)) { | 62 if (!base::PathExists(crx_path)) { |
67 ADD_FAILURE() << crx_path.value() << " was not created."; | 63 ADD_FAILURE() << crx_path.value() << " was not created."; |
68 return base::FilePath(); | 64 return base::FilePath(); |
69 } | 65 } |
70 return crx_path; | 66 return crx_path; |
71 } | 67 } |
72 | 68 |
| 69 base::FilePath TestExtensionDir::UnpackedPath() { |
| 70 return dir_.GetPath(); |
| 71 } |
| 72 |
73 } // namespace extensions | 73 } // namespace extensions |
OLD | NEW |