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

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 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 } 209 }
205 210
206 IN_PROC_BROWSER_TEST_F(PPAPIFileChooserTest, FileChooser_SaveAs_Cancel) { 211 IN_PROC_BROWSER_TEST_F(PPAPIFileChooserTest, FileChooser_SaveAs_Cancel) {
207 TestSelectFileDialogFactory test_dialog_factory( 212 TestSelectFileDialogFactory test_dialog_factory(
208 TestSelectFileDialogFactory::CANCEL, 213 TestSelectFileDialogFactory::CANCEL,
209 TestSelectFileDialogFactory::SelectedFileInfoList()); 214 TestSelectFileDialogFactory::SelectedFileInfoList());
210 RunTestViaHTTP("FileChooser_SaveAsCancel"); 215 RunTestViaHTTP("FileChooser_SaveAsCancel");
211 } 216 }
212 217
213 #if defined(FULL_SAFE_BROWSING) 218 #if defined(FULL_SAFE_BROWSING)
214 // These two tests only make sense when SafeBrowsing is enabled. They verify 219 // These tests only make sense when SafeBrowsing is enabled. They verify
215 // that files written via the FileChooser_Trusted API are properly passed 220 // that files written via the FileChooser_Trusted API are properly passed
216 // through Safe Browsing. 221 // through Safe Browsing.
217 222
218 IN_PROC_BROWSER_TEST_F(PPAPIFileChooserTest, 223 IN_PROC_BROWSER_TEST_F(PPAPIFileChooserTest,
219 FileChooser_SaveAs_DangerousExecutable_Allowed) { 224 FileChooser_SaveAs_DangerousExecutable_Allowed) {
220 base::CommandLine::ForCurrentProcess()->AppendSwitch( 225 base::CommandLine::ForCurrentProcess()->AppendSwitch(
221 switches::kAllowUncheckedDangerousDownloads); 226 switches::kAllowUncheckedDangerousDownloads);
222 base::ScopedTempDir temp_dir; 227 base::ScopedTempDir temp_dir;
223 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 228 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
224 base::FilePath suggested_filename = temp_dir.path().AppendASCII("foo"); 229 base::FilePath suggested_filename = temp_dir.path().AppendASCII("foo");
(...skipping 16 matching lines...) Expand all
241 IN_PROC_BROWSER_TEST_F(PPAPIFileChooserTest, 246 IN_PROC_BROWSER_TEST_F(PPAPIFileChooserTest,
242 FileChooser_SaveAs_DangerousExecutable_Disallowed) { 247 FileChooser_SaveAs_DangerousExecutable_Disallowed) {
243 base::CommandLine::ForCurrentProcess()->AppendSwitch( 248 base::CommandLine::ForCurrentProcess()->AppendSwitch(
244 switches::kDisallowUncheckedDangerousDownloads); 249 switches::kDisallowUncheckedDangerousDownloads);
245 TestSelectFileDialogFactory test_dialog_factory( 250 TestSelectFileDialogFactory test_dialog_factory(
246 TestSelectFileDialogFactory::NOT_REACHED, 251 TestSelectFileDialogFactory::NOT_REACHED,
247 TestSelectFileDialogFactory::SelectedFileInfoList()); 252 TestSelectFileDialogFactory::SelectedFileInfoList());
248 RunTestViaHTTP("FileChooser_SaveAsDangerousExecutableDisallowed"); 253 RunTestViaHTTP("FileChooser_SaveAsDangerousExecutableDisallowed");
249 } 254 }
250 255
256 namespace {
bbudge 2015/10/28 00:13:20 Can these classes be moved to the first anonymous
asanka 2015/10/28 14:10:04 Done.
257
258 class FakeDatabaseManager : public TestSafeBrowsingDatabaseManager {
259 public:
260 bool IsSupported() const override { return true; }
261 bool MatchDownloadWhitelistUrl(const GURL& url) override {
262 // This matches the behavior in RunTestViaHTTP().
263 return url.SchemeIsHTTPOrHTTPS() && url.has_path() &&
264 url.path().find("/files/test_case.html") == 0;
265 }
266
267 protected:
268 ~FakeDatabaseManager() override {}
269 };
270
271 class TestSafeBrowsingService : public SafeBrowsingService {
272 public:
273 SafeBrowsingDatabaseManager* CreateDatabaseManager() override {
274 return new FakeDatabaseManager();
275 }
276
277 protected:
278 ~TestSafeBrowsingService() override {}
279 };
280
281 class TestSafeBrowsingServiceFactory : public SafeBrowsingServiceFactory {
282 public:
283 SafeBrowsingService* CreateSafeBrowsingService() override {
284 SafeBrowsingService* service = new TestSafeBrowsingService();
285 return service;
286 }
287 };
288
289 class PPAPIFileChooserTestWithSBService : public PPAPIFileChooserTest {
290 public:
291 void SetUp() override {
292 SafeBrowsingService::RegisterFactory(&safe_browsing_service_factory_);
293 PPAPIFileChooserTest::SetUp();
294 }
295 void TearDown() override {
296 PPAPIFileChooserTest::TearDown();
297 SafeBrowsingService::RegisterFactory(nullptr);
298 }
299
300 private:
301 TestSafeBrowsingServiceFactory safe_browsing_service_factory_;
302 };
303
304 // The kDisallowUncheckedDangerousDownloads switch (whose behavior is verified
305 // by the FileChooser_SaveAs_DangerousExecutable_Disallowed test above) should
306 // block the file being downloaded. However, the FakeDatabaseManager reports
307 // that the requestors document URL matches the Safe Browsing whitelist. Hence
308 // the download succeeds.
309 IN_PROC_BROWSER_TEST_F(PPAPIFileChooserTestWithSBService,
bbudge 2015/10/28 00:13:20 Is there a reason this is in the anonymous namespa
asanka 2015/10/28 14:10:04 Nope. Accidental. Fixed!
310 FileChooser_SaveAs_DangerousExecutable_Whitelist) {
311 base::CommandLine::ForCurrentProcess()->AppendSwitch(
312 switches::kDisallowUncheckedDangerousDownloads);
313 base::ScopedTempDir temp_dir;
314 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
315 base::FilePath suggested_filename = temp_dir.path().AppendASCII("foo");
316
317 TestSelectFileDialogFactory::SelectedFileInfoList file_info_list;
318 file_info_list.push_back(
319 ui::SelectedFileInfo(suggested_filename, suggested_filename));
320 TestSelectFileDialogFactory test_dialog_factory(
321 TestSelectFileDialogFactory::REPLACE_BASENAME, file_info_list);
322
323 RunTestViaHTTP("FileChooser_SaveAsDangerousExecutableAllowed");
324 base::FilePath actual_filename = temp_dir.path().AppendASCII("dangerous.exe");
325
326 ASSERT_TRUE(base::PathExists(actual_filename));
327 std::string file_contents;
328 ASSERT_TRUE(base::ReadFileToString(actual_filename, &file_contents, 100));
329 EXPECT_EQ("Hello from PPAPI", file_contents);
330 }
331
332 } // namespace
333
251 #endif // FULL_SAFE_BROWSING 334 #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