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

Side by Side Diff: chrome/browser/download/download_browsertest.cc

Issue 1784433003: Track CTR of uncommon download warning. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: cl format Created 4 years, 9 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
« no previous file with comments | « no previous file | chrome/browser/download/download_commands.cc » ('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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/download/download_browsertest.h" 5 #include "chrome/browser/download/download_browsertest.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 #include <sstream> 8 #include <sstream>
9 #include <utility> 9 #include <utility>
10 10
(...skipping 14 matching lines...) Expand all
25 #include "base/strings/string_util.h" 25 #include "base/strings/string_util.h"
26 #include "base/strings/stringprintf.h" 26 #include "base/strings/stringprintf.h"
27 #include "base/strings/utf_string_conversions.h" 27 #include "base/strings/utf_string_conversions.h"
28 #include "base/sys_info.h" 28 #include "base/sys_info.h"
29 #include "base/test/test_file_util.h" 29 #include "base/test/test_file_util.h"
30 #include "build/build_config.h" 30 #include "build/build_config.h"
31 #include "chrome/app/chrome_command_ids.h" 31 #include "chrome/app/chrome_command_ids.h"
32 #include "chrome/browser/browser_process.h" 32 #include "chrome/browser/browser_process.h"
33 #include "chrome/browser/chrome_notification_types.h" 33 #include "chrome/browser/chrome_notification_types.h"
34 #include "chrome/browser/download/chrome_download_manager_delegate.h" 34 #include "chrome/browser/download/chrome_download_manager_delegate.h"
35 #include "chrome/browser/download/download_commands.h"
35 #include "chrome/browser/download/download_crx_util.h" 36 #include "chrome/browser/download/download_crx_util.h"
36 #include "chrome/browser/download/download_history.h" 37 #include "chrome/browser/download/download_history.h"
37 #include "chrome/browser/download/download_item_model.h" 38 #include "chrome/browser/download/download_item_model.h"
38 #include "chrome/browser/download/download_prefs.h" 39 #include "chrome/browser/download/download_prefs.h"
39 #include "chrome/browser/download/download_request_limiter.h" 40 #include "chrome/browser/download/download_request_limiter.h"
40 #include "chrome/browser/download/download_service.h" 41 #include "chrome/browser/download/download_service.h"
41 #include "chrome/browser/download/download_service_factory.h" 42 #include "chrome/browser/download/download_service_factory.h"
42 #include "chrome/browser/download/download_shelf.h" 43 #include "chrome/browser/download/download_shelf.h"
43 #include "chrome/browser/download/download_target_determiner.h" 44 #include "chrome/browser/download/download_target_determiner.h"
44 #include "chrome/browser/download/download_test_file_activity_observer.h" 45 #include "chrome/browser/download/download_test_file_activity_observer.h"
(...skipping 23 matching lines...) Expand all
68 #include "chrome/test/base/in_process_browser_test.h" 69 #include "chrome/test/base/in_process_browser_test.h"
69 #include "chrome/test/base/test_switches.h" 70 #include "chrome/test/base/test_switches.h"
70 #include "chrome/test/base/ui_test_utils.h" 71 #include "chrome/test/base/ui_test_utils.h"
71 #include "components/history/content/browser/download_constants_utils.h" 72 #include "components/history/content/browser/download_constants_utils.h"
72 #include "components/history/core/browser/download_constants.h" 73 #include "components/history/core/browser/download_constants.h"
73 #include "components/history/core/browser/download_row.h" 74 #include "components/history/core/browser/download_row.h"
74 #include "components/history/core/browser/history_service.h" 75 #include "components/history/core/browser/history_service.h"
75 #include "components/infobars/core/confirm_infobar_delegate.h" 76 #include "components/infobars/core/confirm_infobar_delegate.h"
76 #include "components/infobars/core/infobar.h" 77 #include "components/infobars/core/infobar.h"
77 #include "components/prefs/pref_service.h" 78 #include "components/prefs/pref_service.h"
79 #include "content/public/browser/download_danger_type.h"
78 #include "content/public/browser/download_interrupt_reasons.h" 80 #include "content/public/browser/download_interrupt_reasons.h"
79 #include "content/public/browser/download_item.h" 81 #include "content/public/browser/download_item.h"
80 #include "content/public/browser/download_manager.h" 82 #include "content/public/browser/download_manager.h"
81 #include "content/public/browser/download_save_info.h" 83 #include "content/public/browser/download_save_info.h"
82 #include "content/public/browser/download_url_parameters.h" 84 #include "content/public/browser/download_url_parameters.h"
83 #include "content/public/browser/notification_source.h" 85 #include "content/public/browser/notification_source.h"
84 #include "content/public/browser/render_frame_host.h" 86 #include "content/public/browser/render_frame_host.h"
85 #include "content/public/browser/render_view_host.h" 87 #include "content/public/browser/render_view_host.h"
86 #include "content/public/browser/render_widget_host.h" 88 #include "content/public/browser/render_widget_host.h"
87 #include "content/public/browser/resource_context.h" 89 #include "content/public/browser/resource_context.h"
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
241 was_previously_resumable_ = is_resumable_now; 243 was_previously_resumable_ = is_resumable_now;
242 return transitions_left_ == 0; 244 return transitions_left_ == 0;
243 } 245 }
244 246
245 bool was_previously_resumable_; 247 bool was_previously_resumable_;
246 size_t transitions_left_; 248 size_t transitions_left_;
247 249
248 DISALLOW_COPY_AND_ASSIGN(DownloadTestObserverResumable); 250 DISALLOW_COPY_AND_ASSIGN(DownloadTestObserverResumable);
249 }; 251 };
250 252
253 // DownloadTestObserverTerminal subclass for testing.
254 class DownloadTestObserverAcceptUncommon
255 : public content::DownloadTestObserverTerminal {
256 public:
257 DownloadTestObserverAcceptUncommon(
258 DownloadManager* download_manager,
259 size_t wait_count,
260 content::DownloadTestObserver::DangerousDownloadAction
261 dangerous_download_action)
262 : content::DownloadTestObserverTerminal(download_manager,
263 wait_count,
264 dangerous_download_action),
265 weak_factory_(this) {}
266 ~DownloadTestObserverAcceptUncommon() override {}
267
268 void OnDownloadUpdated(DownloadItem* download) override {
269 // Real UI code gets the user's response after returning from the observer.
270 if (download->IsDangerous() &&
271 !ContainsKey(dangerous_downloads_seen(), download->GetId())) {
272 dangerous_downloads_seen().insert(download->GetId());
asanka 2016/03/11 03:43:26 This is inserting an item into a temporary set tha
Jialiu Lin 2016/03/11 05:03:48 Oops, should be return by reference instead. fixed
273
274 switch (dangerous_download_action()) {
275 case ON_DANGEROUS_DOWNLOAD_ACCEPT:
276 BrowserThread::PostTask(
277 BrowserThread::UI, FROM_HERE,
278 base::Bind(
279 &DownloadTestObserverAcceptUncommon::AcceptDangerousDownload,
280 weak_factory_.GetWeakPtr(), download->GetId()));
281 break;
282 default:
283 NOTREACHED();
284 }
285 }
286
287 if (IsDownloadInFinalState(download))
288 DownloadInFinalState(download);
289 }
290
291 private:
292 void AcceptDangerousDownload(uint32_t download_id) {
293 if (!download_manager())
294 return;
295 DownloadItem* download = download_manager()->GetDownload(download_id);
296 if (download && download->IsDangerous() && !download->IsDone()) {
297 DownloadCommands(download).ExecuteCommand(DownloadCommands::KEEP);
298 }
299 }
300
301 base::WeakPtrFactory<DownloadTestObserverAcceptUncommon> weak_factory_;
302 };
303
251 // IDs and paths of CRX files used in tests. 304 // IDs and paths of CRX files used in tests.
252 const char kGoodCrxId[] = "ldnnhddmnhbkjipkidpdiheffobcpfmf"; 305 const char kGoodCrxId[] = "ldnnhddmnhbkjipkidpdiheffobcpfmf";
253 const char kGoodCrxPath[] = "extensions/good.crx"; 306 const char kGoodCrxPath[] = "extensions/good.crx";
254 307
255 const char kLargeThemeCrxId[] = "pjpgmfcmabopnnfonnhmdjglfpjjfkbf"; 308 const char kLargeThemeCrxId[] = "pjpgmfcmabopnnfonnhmdjglfpjjfkbf";
256 const char kLargeThemePath[] = "extensions/theme2.crx"; 309 const char kLargeThemePath[] = "extensions/theme2.crx";
257 310
258 // Get History Information. 311 // Get History Information.
259 class DownloadsHistoryDataCollector { 312 class DownloadsHistoryDataCollector {
260 public: 313 public:
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
381 434
382 private: 435 private:
383 Profile* profile_; 436 Profile* profile_;
384 bool waiting_; 437 bool waiting_;
385 bool seen_stored_; 438 bool seen_stored_;
386 FilterCallback callback_; 439 FilterCallback callback_;
387 440
388 DISALLOW_COPY_AND_ASSIGN(HistoryObserver); 441 DISALLOW_COPY_AND_ASSIGN(HistoryObserver);
389 }; 442 };
390 443
444 class FakeSafeBrowsingService : public safe_browsing::SafeBrowsingService {
445 public:
446 FakeSafeBrowsingService() {}
447
448 std::string GetDownloadReport() const { return report_; }
449
450 protected:
451 ~FakeSafeBrowsingService() override {}
452
453 void SendSerializedDownloadReport(const std::string& report) override {
454 report_ = report;
455 }
456
457 std::string report_;
458 };
459
460 // Factory that creates FakeSafeBrowsingService instances.
461 class TestSafeBrowsingServiceFactory
462 : public safe_browsing::SafeBrowsingServiceFactory {
463 public:
464 TestSafeBrowsingServiceFactory() : fake_safe_browsing_service_(nullptr) {}
465 ~TestSafeBrowsingServiceFactory() override {}
466
467 safe_browsing::SafeBrowsingService* CreateSafeBrowsingService() override {
468 if (!fake_safe_browsing_service_) {
469 fake_safe_browsing_service_ = new FakeSafeBrowsingService();
470 }
471 return fake_safe_browsing_service_.get();
472 }
473
474 scoped_refptr<FakeSafeBrowsingService> fake_safe_browsing_service() {
475 return fake_safe_browsing_service_;
476 }
477
478 private:
479 scoped_refptr<FakeSafeBrowsingService> fake_safe_browsing_service_;
480 };
481
391 class DownloadTest : public InProcessBrowserTest { 482 class DownloadTest : public InProcessBrowserTest {
392 public: 483 public:
393 // Choice of navigation or direct fetch. Used by |DownloadFileCheckErrors()|. 484 // Choice of navigation or direct fetch. Used by
394 enum DownloadMethod { 485 // |DownloadFileCheckErrors()|.
395 DOWNLOAD_NAVIGATE, 486 enum DownloadMethod { DOWNLOAD_NAVIGATE, DOWNLOAD_DIRECT };
396 DOWNLOAD_DIRECT
397 };
398 487
399 // Information passed in to |DownloadFileCheckErrors()|. 488 // Information passed in to |DownloadFileCheckErrors()|.
400 struct DownloadInfo { 489 struct DownloadInfo {
401 const char* starting_url; // URL for initiating the download. 490 const char* starting_url; // URL for initiating the download.
402 const char* expected_download_url; // Expected value of DI::GetURL(). Can 491 const char* expected_download_url; // Expected value of DI::GetURL(). Can
403 // be different if |starting_url| 492 // be different if |starting_url|
404 // initiates a download from another 493 // initiates a download from another
405 // URL. 494 // URL.
406 DownloadMethod download_method; // Navigation or Direct. 495 DownloadMethod download_method; // Navigation or Direct.
407 // Download interrupt reason (NONE is OK). 496 // Download interrupt reason (NONE is OK).
408 content::DownloadInterruptReason reason; 497 content::DownloadInterruptReason reason;
409 bool show_download_item; // True if the download item appears on the shelf. 498 bool show_download_item; // True if the download item appears on the
410 bool should_redirect_to_documents; // True if we save it in "My Documents". 499 // shelf.
500 bool should_redirect_to_documents; // True if we save it in "My
501 // Documents".
411 }; 502 };
412 503
413 struct FileErrorInjectInfo { 504 struct FileErrorInjectInfo {
414 DownloadInfo download_info; 505 DownloadInfo download_info;
415 content::TestFileErrorInjector::FileErrorInfo error_info; 506 content::TestFileErrorInjector::FileErrorInfo error_info;
416 }; 507 };
417 508
418 DownloadTest() {} 509 DownloadTest()
510 : test_safe_browsing_factory_(new TestSafeBrowsingServiceFactory()) {}
511
512 void SetUp() override {
513 safe_browsing::SafeBrowsingService::RegisterFactory(
asanka 2016/03/11 03:43:26 Why is this necessary to be in SetUp() instead of
Jialiu Lin 2016/03/11 05:03:48 Because the registerFactory function needs to be c
514 test_safe_browsing_factory_.get());
515 InProcessBrowserTest::SetUp();
516 }
517
518 void TearDown() override {
519 safe_browsing::SafeBrowsingService::RegisterFactory(nullptr);
520 InProcessBrowserTest::TearDown();
521 }
419 522
420 void SetUpOnMainThread() override { 523 void SetUpOnMainThread() override {
421 base::FeatureList::ClearInstanceForTesting(); 524 base::FeatureList::ClearInstanceForTesting();
422 scoped_ptr<base::FeatureList> feature_list(new base::FeatureList); 525 scoped_ptr<base::FeatureList> feature_list(new base::FeatureList);
423 feature_list->InitializeFromCommandLine( 526 feature_list->InitializeFromCommandLine(features::kDownloadResumption.name,
asanka 2016/03/11 03:43:26 Nit: There's a number of formatting only changes t
Jialiu Lin 2016/03/11 05:03:48 No problem.... seems I need to be more careful wit
424 features::kDownloadResumption.name, std::string()); 527 std::string());
425 base::FeatureList::SetInstance(std::move(feature_list)); 528 base::FeatureList::SetInstance(std::move(feature_list));
426 BrowserThread::PostTask( 529 BrowserThread::PostTask(
427 BrowserThread::IO, FROM_HERE, 530 BrowserThread::IO, FROM_HERE,
428 base::Bind(&chrome_browser_net::SetUrlRequestMocksEnabled, true)); 531 base::Bind(&chrome_browser_net::SetUrlRequestMocksEnabled, true));
429 ASSERT_TRUE(InitialSetup()); 532 ASSERT_TRUE(InitialSetup());
430 } 533 }
431 534
432 void TearDownOnMainThread() override { 535 void TearDownOnMainThread() override {
433 // Needs to be torn down on the main thread. file_activity_observer_ holds a 536 // Needs to be torn down on the main thread. file_activity_observer_ holds
434 // reference to the ChromeDownloadManagerDelegate which should be destroyed 537 // a
538 // reference to the ChromeDownloadManagerDelegate which should be
539 // destroyed
435 // on the UI thread. 540 // on the UI thread.
436 file_activity_observer_.reset(); 541 file_activity_observer_.reset();
437 } 542 }
438 543
439 void SetUpCommandLine(base::CommandLine* command_line) override { 544 void SetUpCommandLine(base::CommandLine* command_line) override {
440 command_line->AppendSwitch(switches::kDisablePluginsDiscovery); 545 command_line->AppendSwitch(switches::kDisablePluginsDiscovery);
441 } 546 }
442 547
443 // Returning false indicates a failure of the setup, and should be asserted 548 // Returning false indicates a failure of the setup, and should be asserted
444 // in the caller. 549 // in the caller.
445 virtual bool InitialSetup() { 550 virtual bool InitialSetup() {
446 bool have_test_dir = PathService::Get(chrome::DIR_TEST_DATA, &test_dir_); 551 bool have_test_dir = PathService::Get(chrome::DIR_TEST_DATA, &test_dir_);
447 EXPECT_TRUE(have_test_dir); 552 EXPECT_TRUE(have_test_dir);
448 if (!have_test_dir) 553 if (!have_test_dir)
449 return false; 554 return false;
450 555
451 // Sanity check default values for window and tab count. 556 // Sanity check default values for window and tab count.
452 int window_count = chrome::GetTotalBrowserCount(); 557 int window_count = chrome::GetTotalBrowserCount();
453 EXPECT_EQ(1, window_count); 558 EXPECT_EQ(1, window_count);
454 EXPECT_EQ(1, browser()->tab_strip_model()->count()); 559 EXPECT_EQ(1, browser()->tab_strip_model()->count());
455 560
456 // Set up the temporary download folder. 561 // Set up the temporary download folder.
457 bool created_downloads_dir = CreateAndSetDownloadsDirectory(browser()); 562 bool created_downloads_dir = CreateAndSetDownloadsDirectory(browser());
458 EXPECT_TRUE(created_downloads_dir); 563 EXPECT_TRUE(created_downloads_dir);
459 if (!created_downloads_dir) 564 if (!created_downloads_dir)
460 return false; 565 return false;
461 browser()->profile()->GetPrefs()->SetBoolean( 566 browser()->profile()->GetPrefs()->SetBoolean(prefs::kPromptForDownload,
462 prefs::kPromptForDownload, false); 567 false);
463 568
464 DownloadManager* manager = DownloadManagerForBrowser(browser()); 569 DownloadManager* manager = DownloadManagerForBrowser(browser());
465 DownloadPrefs::FromDownloadManager(manager)->ResetAutoOpen(); 570 DownloadPrefs::FromDownloadManager(manager)->ResetAutoOpen();
466 manager->RemoveAllDownloads(); 571 manager->RemoveAllDownloads();
467 572
468 file_activity_observer_.reset( 573 file_activity_observer_.reset(
469 new DownloadTestFileActivityObserver(browser()->profile())); 574 new DownloadTestFileActivityObserver(browser()->profile()));
470 575
471 return true; 576 return true;
472 } 577 }
473 578
474 protected: 579 protected:
475 enum SizeTestType { 580 enum SizeTestType {
476 SIZE_TEST_TYPE_KNOWN, 581 SIZE_TEST_TYPE_KNOWN,
477 SIZE_TEST_TYPE_UNKNOWN, 582 SIZE_TEST_TYPE_UNKNOWN,
478 }; 583 };
479 584
480 base::FilePath GetTestDataDirectory() { 585 base::FilePath GetTestDataDirectory() {
481 base::FilePath test_file_directory; 586 base::FilePath test_file_directory;
482 PathService::Get(chrome::DIR_TEST_DATA, &test_file_directory); 587 PathService::Get(chrome::DIR_TEST_DATA, &test_file_directory);
483 return test_file_directory; 588 return test_file_directory;
484 } 589 }
485 590
486 base::FilePath GetDownloadsDirectory() { 591 base::FilePath GetDownloadsDirectory() { return downloads_directory_.path(); }
487 return downloads_directory_.path();
488 }
489 592
490 // Location of the file source (the place from which it is downloaded). 593 // Location of the file source (the place from which it is downloaded).
491 base::FilePath OriginFile(base::FilePath file) { 594 base::FilePath OriginFile(base::FilePath file) {
492 return test_dir_.Append(file); 595 return test_dir_.Append(file);
493 } 596 }
494 597
495 // Location of the file destination (place to which it is downloaded). 598 // Location of the file destination (place to which it is downloaded).
496 base::FilePath DestinationFile(Browser* browser, base::FilePath file) { 599 base::FilePath DestinationFile(Browser* browser, base::FilePath file) {
497 return GetDownloadDirectory(browser).Append(file.BaseName()); 600 return GetDownloadDirectory(browser).Append(file.BaseName());
498 } 601 }
499 602
500 // Must be called after browser creation. Creates a temporary 603 // Must be called after browser creation. Creates a temporary
501 // directory for downloads that is auto-deleted on destruction. 604 // directory for downloads that is auto-deleted on destruction.
502 // Returning false indicates a failure of the function, and should be asserted 605 // Returning false indicates a failure of the function, and should be
606 // asserted
503 // in the caller. 607 // in the caller.
504 bool CreateAndSetDownloadsDirectory(Browser* browser) { 608 bool CreateAndSetDownloadsDirectory(Browser* browser) {
505 if (!browser) 609 if (!browser)
506 return false; 610 return false;
507 611
508 if (!downloads_directory_.CreateUniqueTempDir()) 612 if (!downloads_directory_.CreateUniqueTempDir())
509 return false; 613 return false;
510 614
511 browser->profile()->GetPrefs()->SetFilePath( 615 browser->profile()->GetPrefs()->SetFilePath(
512 prefs::kDownloadDefaultDirectory, 616 prefs::kDownloadDefaultDirectory, downloads_directory_.path());
513 downloads_directory_.path());
514 browser->profile()->GetPrefs()->SetFilePath( 617 browser->profile()->GetPrefs()->SetFilePath(
515 prefs::kSaveFileDefaultDirectory, 618 prefs::kSaveFileDefaultDirectory, downloads_directory_.path());
516 downloads_directory_.path());
517 619
518 return true; 620 return true;
519 } 621 }
520 622
521 DownloadPrefs* GetDownloadPrefs(Browser* browser) { 623 DownloadPrefs* GetDownloadPrefs(Browser* browser) {
522 return DownloadPrefs::FromDownloadManager( 624 return DownloadPrefs::FromDownloadManager(
523 DownloadManagerForBrowser(browser)); 625 DownloadManagerForBrowser(browser));
524 } 626 }
525 627
526 base::FilePath GetDownloadDirectory(Browser* browser) { 628 base::FilePath GetDownloadDirectory(Browser* browser) {
527 return GetDownloadPrefs(browser)->DownloadPath(); 629 return GetDownloadPrefs(browser)->DownloadPath();
528 } 630 }
529 631
530 // Create a DownloadTestObserverTerminal that will wait for the 632 // Create a DownloadTestObserverTerminal that will wait for the
531 // specified number of downloads to finish. 633 // specified number of downloads to finish.
532 content::DownloadTestObserver* CreateWaiter( 634 content::DownloadTestObserver* CreateWaiter(Browser* browser,
533 Browser* browser, int num_downloads) { 635 int num_downloads) {
534 DownloadManager* download_manager = DownloadManagerForBrowser(browser); 636 DownloadManager* download_manager = DownloadManagerForBrowser(browser);
535 return new content::DownloadTestObserverTerminal( 637 return new content::DownloadTestObserverTerminal(
536 download_manager, num_downloads, 638 download_manager, num_downloads,
537 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL); 639 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL);
538 } 640 }
539 641
540 // Create a DownloadTestObserverInProgress that will wait for the 642 // Create a DownloadTestObserverInProgress that will wait for the
541 // specified number of downloads to start. 643 // specified number of downloads to start.
542 content::DownloadTestObserver* CreateInProgressWaiter( 644 content::DownloadTestObserver* CreateInProgressWaiter(Browser* browser,
543 Browser* browser, int num_downloads) { 645 int num_downloads) {
544 DownloadManager* download_manager = DownloadManagerForBrowser(browser); 646 DownloadManager* download_manager = DownloadManagerForBrowser(browser);
545 return new content::DownloadTestObserverInProgress( 647 return new content::DownloadTestObserverInProgress(download_manager,
546 download_manager, num_downloads); 648 num_downloads);
547 } 649 }
548 650
549 // Create a DownloadTestObserverTerminal that will wait for the 651 // Create a DownloadTestObserverTerminal that will wait for the
550 // specified number of downloads to finish, or for 652 // specified number of downloads to finish, or for
551 // a dangerous download warning to be shown. 653 // a dangerous download warning to be shown.
552 content::DownloadTestObserver* DangerousDownloadWaiter( 654 content::DownloadTestObserver* DangerousDownloadWaiter(
553 Browser* browser, 655 Browser* browser,
554 int num_downloads, 656 int num_downloads,
555 content::DownloadTestObserver::DangerousDownloadAction 657 content::DownloadTestObserver::DangerousDownloadAction
556 dangerous_download_action) { 658 dangerous_download_action) {
557 DownloadManager* download_manager = DownloadManagerForBrowser(browser); 659 DownloadManager* download_manager = DownloadManagerForBrowser(browser);
558 return new content::DownloadTestObserverTerminal( 660 return new content::DownloadTestObserverTerminal(
559 download_manager, num_downloads, dangerous_download_action); 661 download_manager, num_downloads, dangerous_download_action);
560 } 662 }
561 663
664 // Create a DownloadTestObserverAcceptUncommon that will wait for the
665 // specified number of downloads to finish, or for
666 // an uncommon download warning to be shown.
667 content::DownloadTestObserver* UncommonDownloadWaiter(
668 Browser* browser,
669 int num_downloads,
670 content::DownloadTestObserver::DangerousDownloadAction
671 dangerous_download_action) {
672 DownloadManager* download_manager = DownloadManagerForBrowser(browser);
673 return new DownloadTestObserverAcceptUncommon(
674 download_manager, num_downloads, dangerous_download_action);
675 }
676
562 void CheckDownloadStatesForBrowser(Browser* browser, 677 void CheckDownloadStatesForBrowser(Browser* browser,
563 size_t num, 678 size_t num,
564 DownloadItem::DownloadState state) { 679 DownloadItem::DownloadState state) {
565 std::vector<DownloadItem*> download_items; 680 std::vector<DownloadItem*> download_items;
566 GetDownloads(browser, &download_items); 681 GetDownloads(browser, &download_items);
567 682
568 EXPECT_EQ(num, download_items.size()); 683 EXPECT_EQ(num, download_items.size());
569 684
570 for (size_t i = 0; i < download_items.size(); ++i) { 685 for (size_t i = 0; i < download_items.size(); ++i) {
571 EXPECT_EQ(state, download_items[i]->GetState()) << " Item " << i; 686 EXPECT_EQ(state, download_items[i]->GetState()) << " Item " << i;
(...skipping 17 matching lines...) Expand all
589 // values in the ui_test_utils::BrowserTestWaitFlags enum. 704 // values in the ui_test_utils::BrowserTestWaitFlags enum.
590 void DownloadAndWaitWithDisposition(Browser* browser, 705 void DownloadAndWaitWithDisposition(Browser* browser,
591 const GURL& url, 706 const GURL& url,
592 WindowOpenDisposition disposition, 707 WindowOpenDisposition disposition,
593 int browser_test_flags) { 708 int browser_test_flags) {
594 // Setup notification, navigate, and block. 709 // Setup notification, navigate, and block.
595 scoped_ptr<content::DownloadTestObserver> observer( 710 scoped_ptr<content::DownloadTestObserver> observer(
596 CreateWaiter(browser, 1)); 711 CreateWaiter(browser, 1));
597 // This call will block until the condition specified by 712 // This call will block until the condition specified by
598 // |browser_test_flags|, but will not wait for the download to finish. 713 // |browser_test_flags|, but will not wait for the download to finish.
599 ui_test_utils::NavigateToURLWithDisposition(browser, 714 ui_test_utils::NavigateToURLWithDisposition(browser, url, disposition,
600 url,
601 disposition,
602 browser_test_flags); 715 browser_test_flags);
603 // Waits for the download to complete. 716 // Waits for the download to complete.
604 observer->WaitForFinished(); 717 observer->WaitForFinished();
605 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE)); 718 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE));
606 // We don't expect a file chooser to be shown. 719 // We don't expect a file chooser to be shown.
607 EXPECT_FALSE(DidShowFileChooser()); 720 EXPECT_FALSE(DidShowFileChooser());
608 } 721 }
609 722
610 // Download a file in the current tab, then wait for the download to finish. 723 // Download a file in the current tab, then wait for the download to finish.
611 void DownloadAndWait(Browser* browser, 724 void DownloadAndWait(Browser* browser, const GURL& url) {
612 const GURL& url) {
613 DownloadAndWaitWithDisposition( 725 DownloadAndWaitWithDisposition(
614 browser, 726 browser, url, CURRENT_TAB,
615 url,
616 CURRENT_TAB,
617 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); 727 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
618 } 728 }
619 729
620 // Should only be called when the download is known to have finished 730 // Should only be called when the download is known to have finished
621 // (in error or not). 731 // (in error or not).
622 // Returning false indicates a failure of the function, and should be asserted 732 // Returning false indicates a failure of the function, and should be
733 // asserted
623 // in the caller. 734 // in the caller.
624 bool CheckDownload(Browser* browser, 735 bool CheckDownload(Browser* browser,
625 const base::FilePath& downloaded_filename, 736 const base::FilePath& downloaded_filename,
626 const base::FilePath& origin_filename) { 737 const base::FilePath& origin_filename) {
627 // Find the path to which the data will be downloaded. 738 // Find the path to which the data will be downloaded.
628 base::FilePath downloaded_file( 739 base::FilePath downloaded_file(
629 DestinationFile(browser, downloaded_filename)); 740 DestinationFile(browser, downloaded_filename));
630 741
631 // Find the origin path (from which the data comes). 742 // Find the origin path (from which the data comes).
632 base::FilePath origin_file(OriginFile(origin_filename)); 743 base::FilePath origin_file(OriginFile(origin_filename));
(...skipping 24 matching lines...) Expand all
657 768
658 // Delete the downloaded copy of the file. 769 // Delete the downloaded copy of the file.
659 bool downloaded_file_deleted = base::DieFileDie(downloaded_file, false); 770 bool downloaded_file_deleted = base::DieFileDie(downloaded_file, false);
660 EXPECT_TRUE(downloaded_file_deleted); 771 EXPECT_TRUE(downloaded_file_deleted);
661 return downloaded_file_deleted; 772 return downloaded_file_deleted;
662 } 773 }
663 774
664 content::DownloadTestObserver* CreateInProgressDownloadObserver( 775 content::DownloadTestObserver* CreateInProgressDownloadObserver(
665 size_t download_count) { 776 size_t download_count) {
666 DownloadManager* manager = DownloadManagerForBrowser(browser()); 777 DownloadManager* manager = DownloadManagerForBrowser(browser());
667 return new content::DownloadTestObserverInProgress( 778 return new content::DownloadTestObserverInProgress(manager, download_count);
668 manager, download_count);
669 } 779 }
670 780
671 DownloadItem* CreateSlowTestDownload() { 781 DownloadItem* CreateSlowTestDownload() {
672 scoped_ptr<content::DownloadTestObserver> observer( 782 scoped_ptr<content::DownloadTestObserver> observer(
673 CreateInProgressDownloadObserver(1)); 783 CreateInProgressDownloadObserver(1));
674 GURL slow_download_url(net::URLRequestSlowDownloadJob::kUnknownSizeUrl); 784 GURL slow_download_url(net::URLRequestSlowDownloadJob::kUnknownSizeUrl);
675 DownloadManager* manager = DownloadManagerForBrowser(browser()); 785 DownloadManager* manager = DownloadManagerForBrowser(browser());
676 786
677 EXPECT_EQ(0, manager->NonMaliciousInProgressCount()); 787 EXPECT_EQ(0, manager->NonMaliciousInProgressCount());
678 EXPECT_EQ(0, manager->InProgressCount()); 788 EXPECT_EQ(0, manager->InProgressCount());
(...skipping 20 matching lines...) Expand all
699 return new_item; 809 return new_item;
700 } 810 }
701 811
702 bool RunSizeTest(Browser* browser, 812 bool RunSizeTest(Browser* browser,
703 SizeTestType type, 813 SizeTestType type,
704 const std::string& partial_indication, 814 const std::string& partial_indication,
705 const std::string& total_indication) { 815 const std::string& total_indication) {
706 EXPECT_TRUE(type == SIZE_TEST_TYPE_UNKNOWN || type == SIZE_TEST_TYPE_KNOWN); 816 EXPECT_TRUE(type == SIZE_TEST_TYPE_UNKNOWN || type == SIZE_TEST_TYPE_KNOWN);
707 if (type != SIZE_TEST_TYPE_KNOWN && type != SIZE_TEST_TYPE_UNKNOWN) 817 if (type != SIZE_TEST_TYPE_KNOWN && type != SIZE_TEST_TYPE_UNKNOWN)
708 return false; 818 return false;
709 GURL url(type == SIZE_TEST_TYPE_KNOWN ? 819 GURL url(type == SIZE_TEST_TYPE_KNOWN
710 net::URLRequestSlowDownloadJob::kKnownSizeUrl : 820 ? net::URLRequestSlowDownloadJob::kKnownSizeUrl
711 net::URLRequestSlowDownloadJob::kUnknownSizeUrl); 821 : net::URLRequestSlowDownloadJob::kUnknownSizeUrl);
712 822
713 // TODO(ahendrickson) -- |expected_title_in_progress| and 823 // TODO(ahendrickson) -- |expected_title_in_progress| and
714 // |expected_title_finished| need to be checked. 824 // |expected_title_finished| need to be checked.
715 base::FilePath filename; 825 base::FilePath filename;
716 net::FileURLToFilePath(url, &filename); 826 net::FileURLToFilePath(url, &filename);
717 base::string16 expected_title_in_progress( 827 base::string16 expected_title_in_progress(
718 base::ASCIIToUTF16(partial_indication) + filename.LossyDisplayName()); 828 base::ASCIIToUTF16(partial_indication) + filename.LossyDisplayName());
719 base::string16 expected_title_finished( 829 base::string16 expected_title_finished(
720 base::ASCIIToUTF16(total_indication) + filename.LossyDisplayName()); 830 base::ASCIIToUTF16(total_indication) + filename.LossyDisplayName());
721 831
722 // Download a partial web page in a background tab and wait. 832 // Download a partial web page in a background tab and wait.
723 // The mock system will not complete until it gets a special URL. 833 // The mock system will not complete until it gets a special URL.
724 scoped_ptr<content::DownloadTestObserver> observer( 834 scoped_ptr<content::DownloadTestObserver> observer(
725 CreateWaiter(browser, 1)); 835 CreateWaiter(browser, 1));
726 ui_test_utils::NavigateToURL(browser, url); 836 ui_test_utils::NavigateToURL(browser, url);
727 837
728 // TODO(ahendrickson): check download status text before downloading. 838 // TODO(ahendrickson): check download status text before downloading.
729 // Need to: 839 // Need to:
730 // - Add a member function to the |DownloadShelf| interface class, that 840 // - Add a member function to the |DownloadShelf| interface class, that
731 // indicates how many members it has. 841 // indicates how many members it has.
732 // - Add a member function to |DownloadShelf| to get the status text 842 // - Add a member function to |DownloadShelf| to get the status text
733 // of a given member (for example, via the name in |DownloadItemView|'s 843 // of a given member (for example, via the name in |DownloadItemView|'s
734 // GetAccessibleState() member function), by index. 844 // GetAccessibleState() member function), by index.
735 // - Iterate over browser->window()->GetDownloadShelf()'s members 845 // - Iterate over browser->window()->GetDownloadShelf()'s members
736 // to see if any match the status text we want. Start with the last one. 846 // to see if any match the status text we want. Start with the last
847 // one.
737 848
738 // Allow the request to finish. We do this by loading a second URL in a 849 // Allow the request to finish. We do this by loading a second URL in a
739 // separate tab. 850 // separate tab.
740 GURL finish_url(net::URLRequestSlowDownloadJob::kFinishDownloadUrl); 851 GURL finish_url(net::URLRequestSlowDownloadJob::kFinishDownloadUrl);
741 ui_test_utils::NavigateToURLWithDisposition( 852 ui_test_utils::NavigateToURLWithDisposition(
742 browser, 853 browser, finish_url, NEW_FOREGROUND_TAB,
743 finish_url,
744 NEW_FOREGROUND_TAB,
745 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); 854 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
746 observer->WaitForFinished(); 855 observer->WaitForFinished();
747 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE)); 856 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE));
748 CheckDownloadStatesForBrowser(browser, 1, DownloadItem::COMPLETE); 857 CheckDownloadStatesForBrowser(browser, 1, DownloadItem::COMPLETE);
749 858
750 EXPECT_EQ(2, browser->tab_strip_model()->count()); 859 EXPECT_EQ(2, browser->tab_strip_model()->count());
751 860
752 // TODO(ahendrickson): check download status text after downloading. 861 // TODO(ahendrickson): check download status text after downloading.
753 862
754 base::FilePath basefilename(filename.BaseName()); 863 base::FilePath basefilename(filename.BaseName());
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
899 } else { 1008 } else {
900 // Navigate to URL normally, wait until done. 1009 // Navigate to URL normally, wait until done.
901 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete( 1010 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(
902 browser(), starting_url, 1); 1011 browser(), starting_url, 1);
903 } 1012 }
904 1013
905 if (download_info.show_download_item) { 1014 if (download_info.show_download_item) {
906 downloads_expected++; 1015 downloads_expected++;
907 observer->WaitForFinished(); 1016 observer->WaitForFinished();
908 DownloadItem::DownloadState final_state = 1017 DownloadItem::DownloadState final_state =
909 (download_info.reason == content::DOWNLOAD_INTERRUPT_REASON_NONE) ? 1018 (download_info.reason == content::DOWNLOAD_INTERRUPT_REASON_NONE)
910 DownloadItem::COMPLETE : 1019 ? DownloadItem::COMPLETE
911 DownloadItem::INTERRUPTED; 1020 : DownloadItem::INTERRUPTED;
912 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(final_state)); 1021 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(final_state));
913 } 1022 }
914 1023
915 // Wait till the |DownloadFile|s are destroyed. 1024 // Wait till the |DownloadFile|s are destroyed.
916 content::RunAllPendingInMessageLoop(content::BrowserThread::FILE); 1025 content::RunAllPendingInMessageLoop(content::BrowserThread::FILE);
917 content::RunAllPendingInMessageLoop(content::BrowserThread::UI); 1026 content::RunAllPendingInMessageLoop(content::BrowserThread::UI);
918 1027
919 // Validate that the correct files were downloaded. 1028 // Validate that the correct files were downloaded.
920 download_items.clear(); 1029 download_items.clear();
921 GetDownloads(browser(), &download_items); 1030 GetDownloads(browser(), &download_items);
(...skipping 10 matching lines...) Expand all
932 EXPECT_EQ(download_url, item->GetURL()); 1041 EXPECT_EQ(download_url, item->GetURL());
933 EXPECT_EQ(download_info.reason, item->GetLastReason()); 1042 EXPECT_EQ(download_info.reason, item->GetLastReason());
934 1043
935 if (item->GetState() == content::DownloadItem::COMPLETE) { 1044 if (item->GetState() == content::DownloadItem::COMPLETE) {
936 // Clean up the file, in case it ended up in the My Documents folder. 1045 // Clean up the file, in case it ended up in the My Documents folder.
937 base::FilePath destination_folder = GetDownloadDirectory(browser()); 1046 base::FilePath destination_folder = GetDownloadDirectory(browser());
938 base::FilePath my_downloaded_file = item->GetTargetFilePath(); 1047 base::FilePath my_downloaded_file = item->GetTargetFilePath();
939 EXPECT_TRUE(base::PathExists(my_downloaded_file)); 1048 EXPECT_TRUE(base::PathExists(my_downloaded_file));
940 EXPECT_TRUE(base::DeleteFile(my_downloaded_file, false)); 1049 EXPECT_TRUE(base::DeleteFile(my_downloaded_file, false));
941 1050
942 EXPECT_EQ(download_info.should_redirect_to_documents ? 1051 EXPECT_EQ(
943 std::string::npos : 1052 download_info.should_redirect_to_documents ? std::string::npos : 0u,
944 0u, 1053 my_downloaded_file.value().find(destination_folder.value()));
945 my_downloaded_file.value().find(destination_folder.value()));
946 if (download_info.should_redirect_to_documents) { 1054 if (download_info.should_redirect_to_documents) {
947 // If it's not where we asked it to be, it should be in the 1055 // If it's not where we asked it to be, it should be in the
948 // My Documents folder. 1056 // My Documents folder.
949 base::FilePath my_docs_folder; 1057 base::FilePath my_docs_folder;
950 EXPECT_TRUE(PathService::Get(chrome::DIR_USER_DOCUMENTS, 1058 EXPECT_TRUE(
951 &my_docs_folder)); 1059 PathService::Get(chrome::DIR_USER_DOCUMENTS, &my_docs_folder));
952 EXPECT_EQ(0u, 1060 EXPECT_EQ(0u,
953 my_downloaded_file.value().find(my_docs_folder.value())); 1061 my_downloaded_file.value().find(my_docs_folder.value()));
954 } 1062 }
955 } 1063 }
956 } 1064 }
957 } 1065 }
958 1066
959 // Attempts to download a set of files, based on information in the 1067 // Attempts to download a set of files, based on information in the
960 // |download_info| array. |count| is the number of files. 1068 // |download_info| array. |count| is the number of files.
961 // If a Select File dialog appears, it will choose the default and return 1069 // If a Select File dialog appears, it will choose the default and return
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
1015 << " folder = '" << destination_folder.value() << "'"; 1123 << " folder = '" << destination_folder.value() << "'";
1016 base::FilePermissionRestorer permission_restorer(destination_folder); 1124 base::FilePermissionRestorer permission_restorer(destination_folder);
1017 EXPECT_TRUE(base::MakeFileUnwritable(destination_folder)); 1125 EXPECT_TRUE(base::MakeFileUnwritable(destination_folder));
1018 1126
1019 for (size_t i = 0; i < count; ++i) { 1127 for (size_t i = 0; i < count; ++i) {
1020 DownloadFilesCheckErrorsLoopBody(download_info[i], i); 1128 DownloadFilesCheckErrorsLoopBody(download_info[i], i);
1021 } 1129 }
1022 } 1130 }
1023 1131
1024 // This method: 1132 // This method:
1025 // * Starts a mock download by navigating browser() to a URLRequestMockHTTPJob 1133 // * Starts a mock download by navigating browser() to a
1134 // URLRequestMockHTTPJob
1026 // mock URL. 1135 // mock URL.
1027 // * Injects |error| on the first write using |error_injector|. 1136 // * Injects |error| on the first write using |error_injector|.
1028 // * Waits for the download to be interrupted. 1137 // * Waits for the download to be interrupted.
1029 // * Clears the errors on |error_injector|. 1138 // * Clears the errors on |error_injector|.
1030 // * Returns the resulting interrupted download. 1139 // * Returns the resulting interrupted download.
1031 DownloadItem* StartMockDownloadAndInjectError( 1140 DownloadItem* StartMockDownloadAndInjectError(
1032 content::TestFileErrorInjector* error_injector, 1141 content::TestFileErrorInjector* error_injector,
1033 content::DownloadInterruptReason error) { 1142 content::DownloadInterruptReason error) {
1034 content::TestFileErrorInjector::FileErrorInfo error_info; 1143 content::TestFileErrorInjector::FileErrorInfo error_info;
1035 error_info.code = content::TestFileErrorInjector::FILE_OPERATION_WRITE; 1144 error_info.code = content::TestFileErrorInjector::FILE_OPERATION_WRITE;
1036 error_info.operation_instance = 0; 1145 error_info.operation_instance = 0;
1037 error_info.error = error; 1146 error_info.error = error;
1038 error_injector->InjectError(error_info); 1147 error_injector->InjectError(error_info);
1039 1148
1040 scoped_ptr<content::DownloadTestObserver> observer( 1149 scoped_ptr<content::DownloadTestObserver> observer(
1041 new DownloadTestObserverResumable( 1150 new DownloadTestObserverResumable(DownloadManagerForBrowser(browser()),
1042 DownloadManagerForBrowser(browser()), 1)); 1151 1));
1043 1152
1044 GURL url = URLRequestMockHTTPJob::GetMockUrl(kDownloadTest1Path); 1153 GURL url = URLRequestMockHTTPJob::GetMockUrl(kDownloadTest1Path);
1045 ui_test_utils::NavigateToURL(browser(), url); 1154 ui_test_utils::NavigateToURL(browser(), url);
1046 observer->WaitForFinished(); 1155 observer->WaitForFinished();
1047 1156
1048 content::DownloadManager::DownloadVector downloads; 1157 content::DownloadManager::DownloadVector downloads;
1049 DownloadManagerForBrowser(browser())->GetAllDownloads(&downloads); 1158 DownloadManagerForBrowser(browser())->GetAllDownloads(&downloads);
1050 EXPECT_EQ(1u, downloads.size()); 1159 EXPECT_EQ(1u, downloads.size());
1051 1160
1052 if (downloads.size() != 1) 1161 if (downloads.size() != 1)
1053 return NULL; 1162 return NULL;
1054 1163
1055 error_injector->ClearError(); 1164 error_injector->ClearError();
1056 DownloadItem* download = downloads[0]; 1165 DownloadItem* download = downloads[0];
1057 EXPECT_EQ(DownloadItem::INTERRUPTED, download->GetState()); 1166 EXPECT_EQ(DownloadItem::INTERRUPTED, download->GetState());
1058 EXPECT_EQ(error, download->GetLastReason()); 1167 EXPECT_EQ(error, download->GetLastReason());
1059 return download; 1168 return download;
1060 } 1169 }
1061 1170
1171 protected:
1172 scoped_ptr<TestSafeBrowsingServiceFactory> test_safe_browsing_factory_;
1173
1062 private: 1174 private:
1063 static void EnsureNoPendingDownloadJobsOnIO(bool* result) { 1175 static void EnsureNoPendingDownloadJobsOnIO(bool* result) {
1064 if (net::URLRequestSlowDownloadJob::NumberOutstandingRequests()) 1176 if (net::URLRequestSlowDownloadJob::NumberOutstandingRequests())
1065 *result = false; 1177 *result = false;
1066 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, 1178 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
1067 base::MessageLoop::QuitWhenIdleClosure()); 1179 base::MessageLoop::QuitWhenIdleClosure());
1068 } 1180 }
1069 1181
1070 // Location of the test data. 1182 // Location of the test data.
1071 base::FilePath test_dir_; 1183 base::FilePath test_dir_;
(...skipping 2191 matching lines...) Expand 10 before | Expand all | Expand 10 after
3263 ASSERT_TRUE(safe_browsing::DownloadFeedbackService::IsEnabledForDownload( 3375 ASSERT_TRUE(safe_browsing::DownloadFeedbackService::IsEnabledForDownload(
3264 *(downloads[0]))); 3376 *(downloads[0])));
3265 3377
3266 // Begin feedback and check that the file is "stolen". 3378 // Begin feedback and check that the file is "stolen".
3267 download_protection_service->feedback_service()->BeginFeedbackForDownload( 3379 download_protection_service->feedback_service()->BeginFeedbackForDownload(
3268 downloads[0]); 3380 downloads[0]);
3269 std::vector<DownloadItem*> updated_downloads; 3381 std::vector<DownloadItem*> updated_downloads;
3270 GetDownloads(browser(), &updated_downloads); 3382 GetDownloads(browser(), &updated_downloads);
3271 ASSERT_TRUE(updated_downloads.empty()); 3383 ASSERT_TRUE(updated_downloads.empty());
3272 } 3384 }
3385
3386 IN_PROC_BROWSER_TEST_F(DownloadTest, SendUncommonDownloadAcceptReport) {
3387 browser()->profile()->GetPrefs()->SetBoolean(prefs::kSafeBrowsingEnabled,
3388 true);
3389 // Make a dangerous file.
3390 GURL download_url(
3391 net::URLRequestMockHTTPJob::GetMockUrl(kDangerousMockFilePath));
3392 scoped_ptr<content::DownloadTestObserver> dangerous_observer(
3393 UncommonDownloadWaiter(
3394 browser(), 1,
3395 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_ACCEPT));
3396 scoped_ptr<content::DownloadTestObserver> in_progress_observer(
3397 new content::DownloadTestObserverInProgress(
3398 DownloadManagerForBrowser(browser()), 1));
3399
3400 ui_test_utils::NavigateToURL(browser(), download_url);
3401 in_progress_observer->WaitForFinished();
3402
3403 std::vector<DownloadItem*> downloads;
3404 DownloadManagerForBrowser(browser())->GetAllDownloads(&downloads);
3405 ASSERT_EQ(1u, downloads.size());
3406 DownloadItem* download = downloads[0];
3407 // Simulates an uncommon download.
3408 download->OnContentCheckCompleted(
3409 content::DownloadDangerType::DOWNLOAD_DANGER_TYPE_UNCOMMON_CONTENT);
3410 ASSERT_EQ(download->GetDangerType(),
3411 content::DownloadDangerType::DOWNLOAD_DANGER_TYPE_UNCOMMON_CONTENT);
3412 dangerous_observer->WaitForFinished();
3413
3414 safe_browsing::ClientSafeBrowsingReportRequest actual_report;
3415 actual_report.ParseFromString(
3416 test_safe_browsing_factory_->fake_safe_browsing_service()
3417 ->GetDownloadReport());
3418 EXPECT_EQ(safe_browsing::ClientSafeBrowsingReportRequest::
3419 DANGEROUS_DOWNLOAD_WARNING,
3420 actual_report.type());
3421 EXPECT_EQ(safe_browsing::ClientDownloadResponse::UNCOMMON,
3422 actual_report.download_verdict());
3423 EXPECT_EQ(download->GetURL().spec(), actual_report.url());
3424 EXPECT_TRUE(actual_report.did_proceed());
3425
3426 download->Cancel(true);
3427 }
3273 #endif // FULL_SAFE_BROWSING 3428 #endif // FULL_SAFE_BROWSING
3274 3429
3275 class DownloadTestWithShelf : public DownloadTest { 3430 class DownloadTestWithShelf : public DownloadTest {
3276 void SetUpCommandLine(base::CommandLine* command_line) override { 3431 void SetUpCommandLine(base::CommandLine* command_line) override {
3277 #if defined(OS_CHROMEOS) 3432 #if defined(OS_CHROMEOS)
3278 command_line->AppendSwitch(switches::kDisableDownloadNotification); 3433 command_line->AppendSwitch(switches::kDisableDownloadNotification);
3279 #endif 3434 #endif
3280 DownloadTest::SetUpCommandLine(command_line); 3435 DownloadTest::SetUpCommandLine(command_line);
3281 } 3436 }
3282 }; 3437 };
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after
3525 3680
3526 scoped_ptr<content::DownloadTestObserver> observer(DangerousDownloadWaiter( 3681 scoped_ptr<content::DownloadTestObserver> observer(DangerousDownloadWaiter(
3527 browser(), 1, content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_DENY)); 3682 browser(), 1, content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_DENY));
3528 ui_test_utils::NavigateToURL(browser(), extension_url); 3683 ui_test_utils::NavigateToURL(browser(), extension_url);
3529 3684
3530 observer->WaitForFinished(); 3685 observer->WaitForFinished();
3531 3686
3532 // Download shelf should close. 3687 // Download shelf should close.
3533 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); 3688 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible());
3534 } 3689 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/download/download_commands.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698