OLD | NEW |
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/browser/safe_browsing/unverified_download_field_trial.h" | 5 #include "chrome/browser/safe_browsing/unverified_download_field_trial.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
9 #include "base/metrics/field_trial.h" | 9 #include "base/metrics/field_trial.h" |
10 #include "chrome/common/chrome_switches.h" | 10 #include "chrome/common/chrome_switches.h" |
11 #include "chrome/common/safe_browsing/download_protection_util.h" | 11 #include "chrome/common/safe_browsing/download_protection_util.h" |
| 12 #include "chrome/common/safe_browsing/file_type_policies.h" |
12 #include "components/variations/variations_associated_data.h" | 13 #include "components/variations/variations_associated_data.h" |
13 #include "testing/gmock/include/gmock/gmock.h" | 14 #include "testing/gmock/include/gmock/gmock.h" |
14 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
15 | 16 |
16 namespace safe_browsing { | 17 namespace safe_browsing { |
17 | 18 |
18 namespace { | 19 namespace { |
19 | 20 |
20 const base::FilePath::CharType kSafeFilename[] = FILE_PATH_LITERAL("foo.txt"); | 21 const base::FilePath::CharType kSafeFilename[] = FILE_PATH_LITERAL("foo.txt"); |
21 const base::FilePath::CharType kHandledFilename[] = | 22 const base::FilePath::CharType kHandledFilename[] = |
(...skipping 27 matching lines...) Expand all Loading... |
49 | 50 |
50 private: | 51 private: |
51 base::FieldTrialList field_trial_list_; | 52 base::FieldTrialList field_trial_list_; |
52 }; | 53 }; |
53 | 54 |
54 } // namespace | 55 } // namespace |
55 | 56 |
56 // Verify some test assumptions. Namely, that kSafeFilename is not a supported | 57 // Verify some test assumptions. Namely, that kSafeFilename is not a supported |
57 // binary file and that kHandledFilename is. | 58 // binary file and that kHandledFilename is. |
58 TEST(UnverifiedDownloadFieldTrialTest, Assumptions) { | 59 TEST(UnverifiedDownloadFieldTrialTest, Assumptions) { |
59 EXPECT_TRUE(download_protection_util::IsSupportedBinaryFile( | 60 FileTypePolicies* policies = FileTypePolicies::GetInstance(); |
60 base::FilePath(kHandledFilename))); | 61 EXPECT_TRUE(policies->IsCheckedBinaryFile(base::FilePath(kHandledFilename))); |
61 EXPECT_FALSE(download_protection_util::IsSupportedBinaryFile( | 62 EXPECT_FALSE(policies->IsCheckedBinaryFile(base::FilePath(kSafeFilename))); |
62 base::FilePath(kSafeFilename))); | |
63 } | 63 } |
64 | 64 |
65 // Verify that disallow-unchecked-dangerous-downloads command line switch causes | 65 // Verify that disallow-unchecked-dangerous-downloads command line switch causes |
66 // all dangerous file types to be blocked, and that safe files types are still | 66 // all dangerous file types to be blocked, and that safe files types are still |
67 // allowed. | 67 // allowed. |
68 TEST(UnverifiedDownloadFieldTrialTest, CommandLine_DisallowDangerous) { | 68 TEST(UnverifiedDownloadFieldTrialTest, CommandLine_DisallowDangerous) { |
69 base::CommandLine::ForCurrentProcess()->AppendSwitch( | 69 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
70 switches::kDisallowUncheckedDangerousDownloads); | 70 switches::kDisallowUncheckedDangerousDownloads); |
71 EXPECT_TRUE(IsUnverifiedDownloadAllowedByFieldTrial( | 71 EXPECT_TRUE(IsUnverifiedDownloadAllowedByFieldTrial( |
72 base::FilePath(kSafeFilename))); | 72 base::FilePath(kSafeFilename))); |
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
286 | 286 |
287 EXPECT_TRUE(IsUnverifiedDownloadAllowedByFieldTrial( | 287 EXPECT_TRUE(IsUnverifiedDownloadAllowedByFieldTrial( |
288 base::FilePath(kSafeFilename))); | 288 base::FilePath(kSafeFilename))); |
289 EXPECT_FALSE(IsUnverifiedDownloadAllowedByFieldTrial( | 289 EXPECT_FALSE(IsUnverifiedDownloadAllowedByFieldTrial( |
290 base::FilePath(kHandledFilename))); | 290 base::FilePath(kHandledFilename))); |
291 EXPECT_FALSE(IsUnverifiedDownloadAllowedByFieldTrial( | 291 EXPECT_FALSE(IsUnverifiedDownloadAllowedByFieldTrial( |
292 base::FilePath(FILE_PATH_LITERAL("foo.abc")))); | 292 base::FilePath(FILE_PATH_LITERAL("foo.abc")))); |
293 } | 293 } |
294 | 294 |
295 } // namespace safe_browsing | 295 } // namespace safe_browsing |
OLD | NEW |