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

Unified Diff: chrome/browser/extensions/extension_protocols_unittest.cc

Issue 2779083005: Make content verification see 0-byte files. (Closed)
Patch Set: sync Created 3 years, 9 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | extensions/browser/extension_protocols.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/extensions/extension_protocols_unittest.cc
diff --git a/chrome/browser/extensions/extension_protocols_unittest.cc b/chrome/browser/extensions/extension_protocols_unittest.cc
index c762e8d5599b815cced82bf59933402c5a3a1010..ae9d107511977a5dcf53a4c8103fadc44b089c5e 100644
--- a/chrome/browser/extensions/extension_protocols_unittest.cc
+++ b/chrome/browser/extensions/extension_protocols_unittest.cc
@@ -553,4 +553,50 @@ TEST_F(ExtensionProtocolsTest, VerificationSeenForFileAccessErrors) {
test_job_delegate.WaitForDoneReading(extension->id());
}
+// Tests that zero byte files correctly go through ContentVerifyJob.
+TEST_F(ExtensionProtocolsTest, VerificationSeenForZeroByteFile) {
+ const char kFooJsContents[] = ""; // Empty.
+ JobDelegate test_job_delegate(kFooJsContents);
+ SetProtocolHandler(false);
+
+ const std::string kFooJs("foo.js");
+ // Create a temporary directory that a fake extension will live in and fill
+ // it with some test files.
+ base::ScopedTempDir temp_dir;
+ ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
+ base::FilePath foo_js(FILE_PATH_LITERAL("foo.js"));
+ ASSERT_TRUE(AddFileToDirectory(temp_dir.GetPath(), foo_js, kFooJsContents))
+ << "Failed to write " << temp_dir.GetPath().value() << "/"
+ << foo_js.value();
+
+ // Sanity check foo.js.
+ base::FilePath foo_path = temp_dir.GetPath().AppendASCII(kFooJs);
+ int64_t foo_file_size = -1;
+ ASSERT_TRUE(base::GetFileSize(foo_path, &foo_file_size));
+ ASSERT_EQ(0, foo_file_size);
+
+ ExtensionBuilder builder;
+ builder
+ .SetManifest(DictionaryBuilder()
+ .Set("name", "Foo")
+ .Set("version", "1.0")
+ .Set("manifest_version", 2)
+ .Set("update_url",
+ "https://clients2.google.com/service/update2/crx")
+ .Build())
+ .SetID(crx_file::id_util::GenerateId("whatever"))
+ .SetPath(temp_dir.GetPath())
+ .SetLocation(Manifest::INTERNAL);
+ scoped_refptr<Extension> extension(builder.Build());
+
+ ASSERT_TRUE(extension.get());
+ content_verifier_->OnExtensionLoaded(testing_profile_.get(), extension.get());
+ // Wait for PostTask to ContentVerifierIOData::AddData() to finish.
+ content::RunAllPendingInMessageLoop();
+
+ // Request foo.js.
+ EXPECT_EQ(net::OK, DoRequest(*extension, kFooJs));
+ test_job_delegate.WaitForDoneReading(extension->id());
+}
+
} // namespace extensions
« no previous file with comments | « no previous file | extensions/browser/extension_protocols.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698