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

Side by Side Diff: chrome/test/ppapi/ppapi_filechooser_browsertest.cc

Issue 1410423003: [SafeBrowsing] Conditionalize unverified download blocking on whitelist. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@flash-download-block
Patch Set: Created 5 years, 1 month 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
« no previous file with comments | « chrome/chrome_tests_unit.gypi ('k') | content/common/view_messages.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "base/bind.h" 5 #include "base/bind.h"
6 #include "base/command_line.h" 6 #include "base/command_line.h"
7 #include "base/files/file_util.h" 7 #include "base/files/file_util.h"
8 #include "base/files/scoped_temp_dir.h" 8 #include "base/files/scoped_temp_dir.h"
9 #include "base/thread_task_runner_handle.h" 9 #include "base/thread_task_runner_handle.h"
10 #include "chrome/common/chrome_switches.h" 10 #include "chrome/common/chrome_switches.h"
11 #include "chrome/test/ppapi/ppapi_test.h" 11 #include "chrome/test/ppapi/ppapi_test.h"
12 #include "ppapi/shared_impl/test_utils.h" 12 #include "ppapi/shared_impl/test_utils.h"
13 #include "ui/shell_dialogs/select_file_dialog.h" 13 #include "ui/shell_dialogs/select_file_dialog.h"
14 #include "ui/shell_dialogs/select_file_dialog_factory.h" 14 #include "ui/shell_dialogs/select_file_dialog_factory.h"
15 #include "ui/shell_dialogs/selected_file_info.h" 15 #include "ui/shell_dialogs/selected_file_info.h"
16 16
17 #if defined(FULL_SAFE_BROWSING)
18 #include "chrome/browser/safe_browsing/safe_browsing_service.h"
19 #include "chrome/browser/safe_browsing/test_database_manager.h"
20 #endif
21
17 namespace { 22 namespace {
18 23
19 class TestSelectFileDialogFactory final : public ui::SelectFileDialogFactory { 24 class TestSelectFileDialogFactory final : public ui::SelectFileDialogFactory {
20 public: 25 public:
21 using SelectedFileInfoList = std::vector<ui::SelectedFileInfo>; 26 using SelectedFileInfoList = std::vector<ui::SelectedFileInfo>;
22 27
23 enum Mode { 28 enum Mode {
24 RESPOND_WITH_FILE_LIST, 29 RESPOND_WITH_FILE_LIST,
25 CANCEL, 30 CANCEL,
26 REPLACE_BASENAME, 31 REPLACE_BASENAME,
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 } 115 }
111 116
112 SelectedFileInfoList selected_file_info_; 117 SelectedFileInfoList selected_file_info_;
113 Mode mode_; 118 Mode mode_;
114 }; 119 };
115 120
116 std::vector<ui::SelectedFileInfo> selected_file_info_; 121 std::vector<ui::SelectedFileInfo> selected_file_info_;
117 Mode mode_; 122 Mode mode_;
118 }; 123 };
119 124
125 class FakeDatabaseManager : public TestSafeBrowsingDatabaseManager {
126 public:
127 bool IsSupported() const override { return true; }
128 bool MatchDownloadWhitelistUrl(const GURL& url) override {
129 // This matches the behavior in RunTestViaHTTP().
130 return url.SchemeIsHTTPOrHTTPS() && url.has_path() &&
131 url.path().find("/files/test_case.html") == 0;
132 }
133
134 protected:
135 ~FakeDatabaseManager() override {}
136 };
137
138 class TestSafeBrowsingService : public SafeBrowsingService {
139 public:
140 SafeBrowsingDatabaseManager* CreateDatabaseManager() override {
141 return new FakeDatabaseManager();
142 }
143
144 protected:
145 ~TestSafeBrowsingService() override {}
146 };
147
148 class TestSafeBrowsingServiceFactory : public SafeBrowsingServiceFactory {
149 public:
150 SafeBrowsingService* CreateSafeBrowsingService() override {
151 SafeBrowsingService* service = new TestSafeBrowsingService();
152 return service;
153 }
154 };
155
120 class PPAPIFileChooserTest : public OutOfProcessPPAPITest {}; 156 class PPAPIFileChooserTest : public OutOfProcessPPAPITest {};
121 157
158 class PPAPIFileChooserTestWithSBService : public PPAPIFileChooserTest {
159 public:
160 void SetUp() override {
161 SafeBrowsingService::RegisterFactory(&safe_browsing_service_factory_);
162 PPAPIFileChooserTest::SetUp();
163 }
164 void TearDown() override {
165 PPAPIFileChooserTest::TearDown();
166 SafeBrowsingService::RegisterFactory(nullptr);
167 }
168
169 private:
170 TestSafeBrowsingServiceFactory safe_browsing_service_factory_;
171 };
172
122 } // namespace 173 } // namespace
123 174
124 IN_PROC_BROWSER_TEST_F(PPAPIFileChooserTest, FileChooser_Open_Success) { 175 IN_PROC_BROWSER_TEST_F(PPAPIFileChooserTest, FileChooser_Open_Success) {
125 const char kContents[] = "Hello from browser"; 176 const char kContents[] = "Hello from browser";
126 base::ScopedTempDir temp_dir; 177 base::ScopedTempDir temp_dir;
127 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 178 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
128 179
129 base::FilePath existing_filename = temp_dir.path().AppendASCII("foo"); 180 base::FilePath existing_filename = temp_dir.path().AppendASCII("foo");
130 ASSERT_EQ( 181 ASSERT_EQ(
131 static_cast<int>(sizeof(kContents) - 1), 182 static_cast<int>(sizeof(kContents) - 1),
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 } 255 }
205 256
206 IN_PROC_BROWSER_TEST_F(PPAPIFileChooserTest, FileChooser_SaveAs_Cancel) { 257 IN_PROC_BROWSER_TEST_F(PPAPIFileChooserTest, FileChooser_SaveAs_Cancel) {
207 TestSelectFileDialogFactory test_dialog_factory( 258 TestSelectFileDialogFactory test_dialog_factory(
208 TestSelectFileDialogFactory::CANCEL, 259 TestSelectFileDialogFactory::CANCEL,
209 TestSelectFileDialogFactory::SelectedFileInfoList()); 260 TestSelectFileDialogFactory::SelectedFileInfoList());
210 RunTestViaHTTP("FileChooser_SaveAsCancel"); 261 RunTestViaHTTP("FileChooser_SaveAsCancel");
211 } 262 }
212 263
213 #if defined(FULL_SAFE_BROWSING) 264 #if defined(FULL_SAFE_BROWSING)
214 // These two tests only make sense when SafeBrowsing is enabled. They verify 265 // These tests only make sense when SafeBrowsing is enabled. They verify
215 // that files written via the FileChooser_Trusted API are properly passed 266 // that files written via the FileChooser_Trusted API are properly passed
216 // through Safe Browsing. 267 // through Safe Browsing.
217 268
218 IN_PROC_BROWSER_TEST_F(PPAPIFileChooserTest, 269 IN_PROC_BROWSER_TEST_F(PPAPIFileChooserTest,
219 FileChooser_SaveAs_DangerousExecutable_Allowed) { 270 FileChooser_SaveAs_DangerousExecutable_Allowed) {
220 base::CommandLine::ForCurrentProcess()->AppendSwitch( 271 base::CommandLine::ForCurrentProcess()->AppendSwitch(
221 switches::kAllowUncheckedDangerousDownloads); 272 switches::kAllowUncheckedDangerousDownloads);
222 base::ScopedTempDir temp_dir; 273 base::ScopedTempDir temp_dir;
223 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 274 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
224 base::FilePath suggested_filename = temp_dir.path().AppendASCII("foo"); 275 base::FilePath suggested_filename = temp_dir.path().AppendASCII("foo");
(...skipping 16 matching lines...) Expand all
241 IN_PROC_BROWSER_TEST_F(PPAPIFileChooserTest, 292 IN_PROC_BROWSER_TEST_F(PPAPIFileChooserTest,
242 FileChooser_SaveAs_DangerousExecutable_Disallowed) { 293 FileChooser_SaveAs_DangerousExecutable_Disallowed) {
243 base::CommandLine::ForCurrentProcess()->AppendSwitch( 294 base::CommandLine::ForCurrentProcess()->AppendSwitch(
244 switches::kDisallowUncheckedDangerousDownloads); 295 switches::kDisallowUncheckedDangerousDownloads);
245 TestSelectFileDialogFactory test_dialog_factory( 296 TestSelectFileDialogFactory test_dialog_factory(
246 TestSelectFileDialogFactory::NOT_REACHED, 297 TestSelectFileDialogFactory::NOT_REACHED,
247 TestSelectFileDialogFactory::SelectedFileInfoList()); 298 TestSelectFileDialogFactory::SelectedFileInfoList());
248 RunTestViaHTTP("FileChooser_SaveAsDangerousExecutableDisallowed"); 299 RunTestViaHTTP("FileChooser_SaveAsDangerousExecutableDisallowed");
249 } 300 }
250 301
302 // The kDisallowUncheckedDangerousDownloads switch (whose behavior is verified
303 // by the FileChooser_SaveAs_DangerousExecutable_Disallowed test above) should
304 // block the file being downloaded. However, the FakeDatabaseManager reports
305 // that the requestors document URL matches the Safe Browsing whitelist. Hence
306 // the download succeeds.
307 IN_PROC_BROWSER_TEST_F(PPAPIFileChooserTestWithSBService,
308 FileChooser_SaveAs_DangerousExecutable_Whitelist) {
309 base::CommandLine::ForCurrentProcess()->AppendSwitch(
310 switches::kDisallowUncheckedDangerousDownloads);
311 base::ScopedTempDir temp_dir;
312 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
313 base::FilePath suggested_filename = temp_dir.path().AppendASCII("foo");
314
315 TestSelectFileDialogFactory::SelectedFileInfoList file_info_list;
316 file_info_list.push_back(
317 ui::SelectedFileInfo(suggested_filename, suggested_filename));
318 TestSelectFileDialogFactory test_dialog_factory(
319 TestSelectFileDialogFactory::REPLACE_BASENAME, file_info_list);
320
321 RunTestViaHTTP("FileChooser_SaveAsDangerousExecutableAllowed");
322 base::FilePath actual_filename = temp_dir.path().AppendASCII("dangerous.exe");
323
324 ASSERT_TRUE(base::PathExists(actual_filename));
325 std::string file_contents;
326 ASSERT_TRUE(base::ReadFileToString(actual_filename, &file_contents, 100));
327 EXPECT_EQ("Hello from PPAPI", file_contents);
328 }
329
251 #endif // FULL_SAFE_BROWSING 330 #endif // FULL_SAFE_BROWSING
OLDNEW
« no previous file with comments | « chrome/chrome_tests_unit.gypi ('k') | content/common/view_messages.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698