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

Side by Side Diff: chrome/common/safe_browsing/download_protection_util_unittest.cc

Issue 1979153002: Use FileTypePolicies for is_archive and is_supported classifications. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@split_by_platform
Patch Set: rebase Created 4 years, 7 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "chrome/common/safe_browsing/download_protection_util.h" 5 #include "chrome/common/safe_browsing/download_protection_util.h"
6 6
7 #include "base/files/file_path.h" 7 #include "base/files/file_path.h"
8 #include "chrome/common/safe_browsing/file_type_policies.h"
8 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
9 10
10 namespace safe_browsing { 11 namespace safe_browsing {
11 namespace download_protection_util { 12 namespace download_protection_util {
12 13
13 TEST(DownloadProtectionUtilTest, KnownValues) { 14 class DownloadProtectionUtilTest : public testing::Test {
14 EXPECT_EQ(0, GetSBClientDownloadExtensionValueForUMA( 15 public:
15 base::FilePath(FILE_PATH_LITERAL("foo.exe")))); 16 ~DownloadProtectionUtilTest() override {}
16 EXPECT_EQ(0, GetSBClientDownloadExtensionValueForUMA(
17 base::FilePath(FILE_PATH_LITERAL("foo.exe."))));
18 EXPECT_EQ(0, GetSBClientDownloadExtensionValueForUMA(
19 base::FilePath(FILE_PATH_LITERAL("foo.exe "))));
20 EXPECT_EQ(0, GetSBClientDownloadExtensionValueForUMA(
21 base::FilePath(FILE_PATH_LITERAL("foo.exe.. . . . "))));
22 EXPECT_EQ(9, GetSBClientDownloadExtensionValueForUMA(
23 base::FilePath(FILE_PATH_LITERAL("foo.dll"))));
24 EXPECT_EQ(29, GetSBClientDownloadExtensionValueForUMA(
25 base::FilePath(FILE_PATH_LITERAL("foo.jse"))));
26 EXPECT_EQ(18, GetSBClientDownloadExtensionValueForUMA(
27 base::FilePath(FILE_PATH_LITERAL("foo.111"))));
28 EXPECT_EQ(18, GetSBClientDownloadExtensionValueForUMA(
29 base::FilePath(FILE_PATH_LITERAL("foo.zzz"))));
30 EXPECT_EQ(152, GetSBClientDownloadExtensionValueForUMA(
31 base::FilePath(FILE_PATH_LITERAL("foo.tbz2"))));
32 EXPECT_TRUE(IsArchiveFile(base::FilePath(FILE_PATH_LITERAL("foo.zip"))));
33 EXPECT_TRUE(IsArchiveFile(base::FilePath(FILE_PATH_LITERAL("foo.zip."))));
34 EXPECT_TRUE(IsArchiveFile(base::FilePath(FILE_PATH_LITERAL("foo.zip "))));
35 EXPECT_TRUE(
36 IsArchiveFile(base::FilePath(FILE_PATH_LITERAL("foo.zip ...."))));
37 EXPECT_TRUE(
38 IsSupportedBinaryFile(base::FilePath(FILE_PATH_LITERAL("foo.zip"))));
39 EXPECT_TRUE(IsArchiveFile(base::FilePath(FILE_PATH_LITERAL("foo.rar"))));
40 EXPECT_TRUE(
41 IsSupportedBinaryFile(base::FilePath(FILE_PATH_LITERAL("foo.rar"))));
42 EXPECT_FALSE(IsArchiveFile(base::FilePath(FILE_PATH_LITERAL("foo.ps1"))));
43 EXPECT_FALSE(
44 IsArchiveFile(base::FilePath(FILE_PATH_LITERAL("foo.unknownextension"))));
45 EXPECT_FALSE(
46 IsArchiveFile(base::FilePath(FILE_PATH_LITERAL("no_extension"))));
47 EXPECT_TRUE(IsSupportedBinaryFile(base::FilePath(FILE_PATH_LITERAL(".exe"))));
48 EXPECT_TRUE(
49 IsSupportedBinaryFile(base::FilePath(FILE_PATH_LITERAL("foo.msi"))));
50 EXPECT_TRUE(
51 IsSupportedBinaryFile(base::FilePath(FILE_PATH_LITERAL("foo.msi."))));
52 EXPECT_TRUE(
53 IsSupportedBinaryFile(base::FilePath(FILE_PATH_LITERAL("foo.msi "))));
54 EXPECT_TRUE(IsSupportedBinaryFile(
55 base::FilePath(FILE_PATH_LITERAL("foo.msi .. .."))));
56 EXPECT_FALSE(
57 IsSupportedBinaryFile(base::FilePath(FILE_PATH_LITERAL("foo.txt"))));
58 EXPECT_FALSE(IsSupportedBinaryFile(
59 base::FilePath(FILE_PATH_LITERAL("foo.unknownextension"))));
60 EXPECT_FALSE(
61 IsSupportedBinaryFile(base::FilePath(FILE_PATH_LITERAL("no_extension"))));
62 17
18 protected:
19 FileTypePoliciesManager file_type_policies_manager_;
20 };
21
22 TEST_F(DownloadProtectionUtilTest, KnownValues) {
63 EXPECT_EQ(ClientDownloadRequest::WIN_EXECUTABLE, 23 EXPECT_EQ(ClientDownloadRequest::WIN_EXECUTABLE,
64 GetDownloadType(base::FilePath(FILE_PATH_LITERAL("foo.exe")))); 24 GetDownloadType(base::FilePath(FILE_PATH_LITERAL("foo.exe"))));
65 EXPECT_EQ(ClientDownloadRequest::CHROME_EXTENSION, 25 EXPECT_EQ(ClientDownloadRequest::CHROME_EXTENSION,
66 GetDownloadType(base::FilePath(FILE_PATH_LITERAL("foo.crx")))); 26 GetDownloadType(base::FilePath(FILE_PATH_LITERAL("foo.crx"))));
67 EXPECT_EQ(ClientDownloadRequest::ZIPPED_EXECUTABLE, 27 EXPECT_EQ(ClientDownloadRequest::ZIPPED_EXECUTABLE,
68 GetDownloadType(base::FilePath(FILE_PATH_LITERAL("foo.zip")))); 28 GetDownloadType(base::FilePath(FILE_PATH_LITERAL("foo.zip"))));
69 EXPECT_EQ(ClientDownloadRequest::ARCHIVE, 29 EXPECT_EQ(ClientDownloadRequest::ARCHIVE,
70 GetDownloadType(base::FilePath(FILE_PATH_LITERAL("foo.rar")))); 30 GetDownloadType(base::FilePath(FILE_PATH_LITERAL("foo.rar"))));
71 EXPECT_EQ(ClientDownloadRequest::MAC_EXECUTABLE, 31 EXPECT_EQ(ClientDownloadRequest::MAC_EXECUTABLE,
72 GetDownloadType(base::FilePath(FILE_PATH_LITERAL("foo.pkg")))); 32 GetDownloadType(base::FilePath(FILE_PATH_LITERAL("foo.pkg"))));
73 EXPECT_EQ(ClientDownloadRequest::ANDROID_APK, 33 EXPECT_EQ(ClientDownloadRequest::ANDROID_APK,
74 GetDownloadType(base::FilePath(FILE_PATH_LITERAL("foo.apk")))); 34 GetDownloadType(base::FilePath(FILE_PATH_LITERAL("foo.apk"))));
75 } 35 }
76 36
77 } // namespace download_protection_util 37 } // namespace download_protection_util
78 } // namespace safe_browsing 38 } // namespace safe_browsing
79 39
80 40
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698