| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 <stddef.h> | 5 #include <stddef.h> |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 535 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 546 EXPECT_EQ(net::ERR_ACCESS_DENIED, DoRequest(*extension, kFooJs)); | 546 EXPECT_EQ(net::ERR_ACCESS_DENIED, DoRequest(*extension, kFooJs)); |
| 547 test_job_delegate.WaitForDoneReading(extension->id()); | 547 test_job_delegate.WaitForDoneReading(extension->id()); |
| 548 | 548 |
| 549 // Delete foo.js. | 549 // Delete foo.js. |
| 550 ASSERT_TRUE(base::DieFileDie(foo_path, false)); | 550 ASSERT_TRUE(base::DieFileDie(foo_path, false)); |
| 551 test_job_delegate.Reset(); | 551 test_job_delegate.Reset(); |
| 552 EXPECT_EQ(net::ERR_FILE_NOT_FOUND, DoRequest(*extension, kFooJs)); | 552 EXPECT_EQ(net::ERR_FILE_NOT_FOUND, DoRequest(*extension, kFooJs)); |
| 553 test_job_delegate.WaitForDoneReading(extension->id()); | 553 test_job_delegate.WaitForDoneReading(extension->id()); |
| 554 } | 554 } |
| 555 | 555 |
| 556 // Tests that zero byte files correctly go through ContentVerifyJob. |
| 557 TEST_F(ExtensionProtocolsTest, VerificationSeenForZeroByteFile) { |
| 558 const char kFooJsContents[] = ""; // Empty. |
| 559 JobDelegate test_job_delegate(kFooJsContents); |
| 560 SetProtocolHandler(false); |
| 561 |
| 562 const std::string kFooJs("foo.js"); |
| 563 // Create a temporary directory that a fake extension will live in and fill |
| 564 // it with some test files. |
| 565 base::ScopedTempDir temp_dir; |
| 566 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
| 567 base::FilePath foo_js(FILE_PATH_LITERAL("foo.js")); |
| 568 ASSERT_TRUE(AddFileToDirectory(temp_dir.GetPath(), foo_js, kFooJsContents)) |
| 569 << "Failed to write " << temp_dir.GetPath().value() << "/" |
| 570 << foo_js.value(); |
| 571 |
| 572 // Sanity check foo.js. |
| 573 base::FilePath foo_path = temp_dir.GetPath().AppendASCII(kFooJs); |
| 574 int64_t foo_file_size = -1; |
| 575 ASSERT_TRUE(base::GetFileSize(foo_path, &foo_file_size)); |
| 576 ASSERT_EQ(0, foo_file_size); |
| 577 |
| 578 ExtensionBuilder builder; |
| 579 builder |
| 580 .SetManifest(DictionaryBuilder() |
| 581 .Set("name", "Foo") |
| 582 .Set("version", "1.0") |
| 583 .Set("manifest_version", 2) |
| 584 .Set("update_url", |
| 585 "https://clients2.google.com/service/update2/crx") |
| 586 .Build()) |
| 587 .SetID(crx_file::id_util::GenerateId("whatever")) |
| 588 .SetPath(temp_dir.GetPath()) |
| 589 .SetLocation(Manifest::INTERNAL); |
| 590 scoped_refptr<Extension> extension(builder.Build()); |
| 591 |
| 592 ASSERT_TRUE(extension.get()); |
| 593 content_verifier_->OnExtensionLoaded(testing_profile_.get(), extension.get()); |
| 594 // Wait for PostTask to ContentVerifierIOData::AddData() to finish. |
| 595 content::RunAllPendingInMessageLoop(); |
| 596 |
| 597 // Request foo.js. |
| 598 EXPECT_EQ(net::OK, DoRequest(*extension, kFooJs)); |
| 599 test_job_delegate.WaitForDoneReading(extension->id()); |
| 600 } |
| 601 |
| 556 } // namespace extensions | 602 } // namespace extensions |
| OLD | NEW |