OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 "base/files/file_path.h" | 5 #include "base/files/file_path.h" |
6 #include "base/files/file_util.h" | 6 #include "base/files/file_util.h" |
7 #include "base/files/scoped_temp_dir.h" | 7 #include "base/files/scoped_temp_dir.h" |
8 #include "base/memory/ptr_util.h" | 8 #include "base/memory/ptr_util.h" |
9 #include "base/path_service.h" | 9 #include "base/path_service.h" |
10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
252 | 252 |
253 { | 253 { |
254 // Make sure non-empty background.js fails content verification. | 254 // Make sure non-empty background.js fails content verification. |
255 std::string modified_contents = "console.log('non empty');"; | 255 std::string modified_contents = "console.log('non empty');"; |
256 EXPECT_EQ(ContentVerifyJob::HASH_MISMATCH, | 256 EXPECT_EQ(ContentVerifyJob::HASH_MISMATCH, |
257 RunContentVerifyJob(*extension.get(), resource_path, | 257 RunContentVerifyJob(*extension.get(), resource_path, |
258 modified_contents)); | 258 modified_contents)); |
259 } | 259 } |
260 } | 260 } |
261 | 261 |
| 262 // Tests that extension resources of different interesting sizes work properly. |
| 263 // Regression test for https://crbug.com/720597, where content verification |
| 264 // always failed for sizes multiple of content hash's block size (4096 bytes). |
| 265 TEST_F(ContentVerifyJobUnittest, DifferentSizedFiles) { |
| 266 base::FilePath test_dir_base = |
| 267 GetTestPath(base::FilePath(FILE_PATH_LITERAL("different_sized_files"))); |
| 268 base::FilePath unzipped_path; |
| 269 scoped_refptr<Extension> extension = UnzipToTempDirAndLoad( |
| 270 test_dir_base.AppendASCII("source.zip"), &unzipped_path); |
| 271 ASSERT_TRUE(extension.get()); |
| 272 // Make sure there is a verified_contents.json file there as this test cannot |
| 273 // fetch it. |
| 274 EXPECT_TRUE( |
| 275 base::PathExists(file_util::GetVerifiedContentsPath(extension->path()))); |
| 276 |
| 277 const struct { |
| 278 const char* name; |
| 279 size_t byte_size; |
| 280 } kFilesToTest[] = { |
| 281 {"1024.js", 1024}, {"4096.js", 4096}, {"8192.js", 8192}, |
| 282 {"8191.js", 8191}, {"8193.js", 8193}, |
| 283 }; |
| 284 for (const auto& file_to_test : kFilesToTest) { |
| 285 base::FilePath resource_path = |
| 286 base::FilePath::FromUTF8Unsafe(file_to_test.name); |
| 287 std::string contents; |
| 288 base::ReadFileToString(unzipped_path.AppendASCII(file_to_test.name), |
| 289 &contents); |
| 290 EXPECT_EQ(file_to_test.byte_size, contents.size()); |
| 291 EXPECT_EQ(ContentVerifyJob::NONE, |
| 292 RunContentVerifyJob(*extension.get(), resource_path, contents)); |
| 293 } |
| 294 } |
| 295 |
262 } // namespace extensions | 296 } // namespace extensions |
OLD | NEW |