Chromium Code Reviews| Index: content/browser/download/quarantine_win_unittest.cc |
| diff --git a/content/browser/download/quarantine_win_unittest.cc b/content/browser/download/quarantine_win_unittest.cc |
| index f0229f506efc09bb2079400bff32f0654053b996..6674c55cead6b67b0074c8d604f880e720663923 100644 |
| --- a/content/browser/download/quarantine_win_unittest.cc |
| +++ b/content/browser/download/quarantine_win_unittest.cc |
| @@ -6,11 +6,13 @@ |
| #include <wininet.h> |
| -#include "content/browser/download/quarantine.h" |
| #include "base/files/file_path.h" |
| #include "base/files/file_util.h" |
| #include "base/files/scoped_temp_dir.h" |
| +#include "base/macros.h" |
| #include "base/test/histogram_tester.h" |
| +#include "base/test/test_file_util.h" |
| +#include "content/browser/download/quarantine.h" |
| #include "net/base/filename_util.h" |
| #include "testing/gtest/include/gtest/gtest.h" |
| #include "url/gurl.h" |
| @@ -27,6 +29,10 @@ const char kMotwForInternetZone[] = "[ZoneTransfer]\r\nZoneId=3\r\n"; |
| const base::FilePath::CharType kMotwStreamSuffix[] = |
| FILE_PATH_LITERAL(":Zone.Identifier"); |
| +const char kTestData[] = { |
|
svaldez
2016/09/27 20:11:03
Any reason not to do (if it works):
const char kT
asanka
2016/09/27 20:19:17
None other than avoiding the terminating NUL.
I'l
|
| + 'H', 'e', 'l', 'l', 'o', ' ', 'w', 'o', 'r', 'l', 'd', '!', '\r', '\n', |
| +}; |
| + |
| const char* const kUntrustedURLs[] = { |
| "http://example.com/foo", |
| "https://example.com/foo", |
| @@ -68,7 +74,8 @@ TEST(QuarantineWinTest, LocalFile_DependsOnLocalConfig) { |
| for (const auto source_url : kLocalSourceURLs) { |
| SCOPED_TRACE(::testing::Message() << "Trying URL " << source_url); |
| - ASSERT_EQ(5, base::WriteFile(test_file, "Hello", 5u)); |
| + ASSERT_EQ(arraysize(kTestData), |
| + base::WriteFile(test_file, kTestData, arraysize(kTestData))); |
| EXPECT_EQ( |
| QuarantineFileResult::OK, |
| @@ -107,7 +114,8 @@ TEST(QuarantineWinTest, DownloadedFile_DependsOnLocalConfig) { |
| for (const auto source_url : kUntrustedURLs) { |
| SCOPED_TRACE(::testing::Message() << "Trying URL " << source_url); |
| - ASSERT_EQ(5, base::WriteFile(test_file, "Hello", 5u)); |
| + ASSERT_EQ(arraysize(kTestData), |
| + base::WriteFile(test_file, kTestData, arraysize(kTestData))); |
| EXPECT_EQ( |
| QuarantineFileResult::OK, |
| QuarantineFile(test_file, GURL(source_url), GURL(), kDummyClientGuid)); |
| @@ -145,7 +153,8 @@ TEST(QuarantineWinTest, UnsafeReferrer_DependsOnLocalConfig) { |
| for (const auto referrer_url : unsafe_referrers) { |
| SCOPED_TRACE(::testing::Message() << "Trying URL " << referrer_url); |
| - ASSERT_EQ(5, base::WriteFile(test_file, "Hello", 5u)); |
| + ASSERT_EQ(arraysize(kTestData), |
| + base::WriteFile(test_file, kTestData, arraysize(kTestData))); |
| EXPECT_EQ(QuarantineFileResult::OK, |
| QuarantineFile(test_file, GURL("http://example.com/good"), |
| GURL(referrer_url), kDummyClientGuid)); |
| @@ -175,7 +184,8 @@ TEST(QuarantineWinTest, EmptySource_DependsOnLocalConfig) { |
| base::ScopedTempDir test_dir; |
| ASSERT_TRUE(test_dir.CreateUniqueTempDir()); |
| base::FilePath test_file = test_dir.path().AppendASCII("foo.exe"); |
| - ASSERT_EQ(5, base::WriteFile(test_file, "Hello", 5u)); |
| + ASSERT_EQ(arraysize(kTestData), |
| + base::WriteFile(test_file, kTestData, arraysize(kTestData))); |
| EXPECT_EQ(QuarantineFileResult::OK, |
| QuarantineFile(test_file, GURL(), GURL(), kDummyClientGuid)); |
| @@ -195,6 +205,7 @@ TEST(QuarantineWinTest, EmptySource_DependsOnLocalConfig) { |
| // the file is passed to AVScanFile, then there wouldn't be a MOTW attached to |
| // it and the test would fail. |
| TEST(QuarantineWinTest, EmptyFile) { |
| + base::HistogramTester histogram_tester; |
| base::ScopedTempDir test_dir; |
| ASSERT_TRUE(test_dir.CreateUniqueTempDir()); |
| base::FilePath test_file = test_dir.path().AppendASCII("foo.exe"); |
| @@ -207,6 +218,9 @@ TEST(QuarantineWinTest, EmptyFile) { |
| ASSERT_TRUE(base::ReadFileToString( |
| base::FilePath(test_file.value() + kMotwStreamSuffix), &motw_contents)); |
| EXPECT_STREQ(kMotwForInternetZone, motw_contents.c_str()); |
| + |
| + // Attachment services shouldn't have been invoked at all. |
| + histogram_tester.ExpectTotalCount("Download.AttachmentServices.Result", 0); |
| } |
| // If there is no client GUID supplied to the QuarantineFile() call, then rather |
| @@ -217,7 +231,8 @@ TEST(QuarantineWinTest, NoClientGuid) { |
| base::ScopedTempDir test_dir; |
| ASSERT_TRUE(test_dir.CreateUniqueTempDir()); |
| base::FilePath test_file = test_dir.path().AppendASCII("foo.exe"); |
| - ASSERT_EQ(5, base::WriteFile(test_file, "Hello", 5u)); |
| + ASSERT_EQ(arraysize(kTestData), |
| + base::WriteFile(test_file, kTestData, arraysize(kTestData))); |
| EXPECT_EQ(QuarantineFileResult::OK, |
| QuarantineFile(test_file, net::FilePathToFileURL(test_file), GURL(), |
| @@ -235,7 +250,8 @@ TEST(QuarantineWinTest, SuperLongURL) { |
| base::ScopedTempDir test_dir; |
| ASSERT_TRUE(test_dir.CreateUniqueTempDir()); |
| base::FilePath test_file = test_dir.path().AppendASCII("foo.exe"); |
| - ASSERT_EQ(5, base::WriteFile(test_file, "Hello", 5u)); |
| + ASSERT_EQ(arraysize(kTestData), |
| + base::WriteFile(test_file, kTestData, arraysize(kTestData))); |
| std::string source_url("http://example.com/"); |
| source_url.append(INTERNET_MAX_URL_LENGTH * 2, 'a'); |