Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(265)

Side by Side Diff: extensions/browser/content_verify_job_unittest.cc

Issue 2928693002: [Content verification] Fix a bug for files that are multiple of 4k bytes. (Closed)
Patch Set: Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 // Each of these files are named based on their byte sizes.
278 const std::string files_to_test[] = {"1024.js", "4096.js", "8192.js",
279 "8191.js", "8193.js"};
280 for (size_t i = 0; i < arraysize(files_to_test); ++i) {
Devlin 2017/06/07 13:27:31 nit: why not const auto& file_to_test : files_to_t
lazyboy 2017/06/07 18:54:15 Done.
281 base::FilePath resource_path =
282 base::FilePath::FromUTF8Unsafe(files_to_test[i]);
283 std::string contents;
284 base::ReadFileToString(unzipped_path.Append(files_to_test[i]), &contents);
Devlin 2017/06/07 13:27:31 as a sanity check, can we expect_eq the size of th
lazyboy 2017/06/07 18:54:15 Done.
285 EXPECT_EQ(ContentVerifyJob::NONE,
286 RunContentVerifyJob(*extension.get(), resource_path, contents));
287 }
288 }
289
262 } // namespace extensions 290 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/browser/content_verify_job.cc ('k') | extensions/test/data/content_hash_fetcher/different_sized_files/README.txt » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698