Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 Loading... | |
| 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 Loading... | |
| 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 | |
|
asanka
2016/03/11 22:05:32
Rather than going this route, can you create a Dow
Jialiu Lin
2016/03/12 00:15:27
This is brilliant!
| |
| 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()); | |
| 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 Loading... | |
| 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 |DownloadFileCheckErrors()|. |
| 394 enum DownloadMethod { | 485 enum DownloadMethod { |
| 395 DOWNLOAD_NAVIGATE, | 486 DOWNLOAD_NAVIGATE, |
| 396 DOWNLOAD_DIRECT | 487 DOWNLOAD_DIRECT |
| 397 }; | 488 }; |
| 398 | 489 |
| 399 // Information passed in to |DownloadFileCheckErrors()|. | 490 // Information passed in to |DownloadFileCheckErrors()|. |
| 400 struct DownloadInfo { | 491 struct DownloadInfo { |
| 401 const char* starting_url; // URL for initiating the download. | 492 const char* starting_url; // URL for initiating the download. |
| 402 const char* expected_download_url; // Expected value of DI::GetURL(). Can | 493 const char* expected_download_url; // Expected value of DI::GetURL(). Can |
| 403 // be different if |starting_url| | 494 // be different if |starting_url| |
| 404 // initiates a download from another | 495 // initiates a download from another |
| 405 // URL. | 496 // URL. |
| 406 DownloadMethod download_method; // Navigation or Direct. | 497 DownloadMethod download_method; // Navigation or Direct. |
| 407 // Download interrupt reason (NONE is OK). | 498 // Download interrupt reason (NONE is OK). |
| 408 content::DownloadInterruptReason reason; | 499 content::DownloadInterruptReason reason; |
| 409 bool show_download_item; // True if the download item appears on the shelf. | 500 bool show_download_item; // True if the download item appears on the shelf. |
| 410 bool should_redirect_to_documents; // True if we save it in "My Documents". | 501 bool should_redirect_to_documents; // True if we save it in "My 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( | |
| 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 22:05:32
Nit: unnecessary change.
Jialiu Lin
2016/03/12 00:15:27
Done.
| |
| 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 a |
| 434 // reference to the ChromeDownloadManagerDelegate which should be destroyed | 537 // reference to the ChromeDownloadManagerDelegate which should be destroyed |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 552 content::DownloadTestObserver* DangerousDownloadWaiter( | 655 content::DownloadTestObserver* DangerousDownloadWaiter( |
| 553 Browser* browser, | 656 Browser* browser, |
| 554 int num_downloads, | 657 int num_downloads, |
| 555 content::DownloadTestObserver::DangerousDownloadAction | 658 content::DownloadTestObserver::DangerousDownloadAction |
| 556 dangerous_download_action) { | 659 dangerous_download_action) { |
| 557 DownloadManager* download_manager = DownloadManagerForBrowser(browser); | 660 DownloadManager* download_manager = DownloadManagerForBrowser(browser); |
| 558 return new content::DownloadTestObserverTerminal( | 661 return new content::DownloadTestObserverTerminal( |
| 559 download_manager, num_downloads, dangerous_download_action); | 662 download_manager, num_downloads, dangerous_download_action); |
| 560 } | 663 } |
| 561 | 664 |
| 665 // Create a DownloadTestObserverAcceptUncommon that will wait for the | |
| 666 // specified number of downloads to finish, or for | |
| 667 // an uncommon download warning to be shown. | |
| 668 content::DownloadTestObserver* UncommonDownloadWaiter( | |
| 669 Browser* browser, | |
| 670 int num_downloads, | |
| 671 content::DownloadTestObserver::DangerousDownloadAction | |
| 672 dangerous_download_action) { | |
| 673 DownloadManager* download_manager = DownloadManagerForBrowser(browser); | |
| 674 return new DownloadTestObserverAcceptUncommon( | |
| 675 download_manager, num_downloads, dangerous_download_action); | |
| 676 } | |
| 677 | |
| 562 void CheckDownloadStatesForBrowser(Browser* browser, | 678 void CheckDownloadStatesForBrowser(Browser* browser, |
| 563 size_t num, | 679 size_t num, |
| 564 DownloadItem::DownloadState state) { | 680 DownloadItem::DownloadState state) { |
| 565 std::vector<DownloadItem*> download_items; | 681 std::vector<DownloadItem*> download_items; |
| 566 GetDownloads(browser, &download_items); | 682 GetDownloads(browser, &download_items); |
| 567 | 683 |
| 568 EXPECT_EQ(num, download_items.size()); | 684 EXPECT_EQ(num, download_items.size()); |
| 569 | 685 |
| 570 for (size_t i = 0; i < download_items.size(); ++i) { | 686 for (size_t i = 0; i < download_items.size(); ++i) { |
| 571 EXPECT_EQ(state, download_items[i]->GetState()) << " Item " << i; | 687 EXPECT_EQ(state, download_items[i]->GetState()) << " Item " << i; |
| (...skipping 480 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1052 if (downloads.size() != 1) | 1168 if (downloads.size() != 1) |
| 1053 return NULL; | 1169 return NULL; |
| 1054 | 1170 |
| 1055 error_injector->ClearError(); | 1171 error_injector->ClearError(); |
| 1056 DownloadItem* download = downloads[0]; | 1172 DownloadItem* download = downloads[0]; |
| 1057 EXPECT_EQ(DownloadItem::INTERRUPTED, download->GetState()); | 1173 EXPECT_EQ(DownloadItem::INTERRUPTED, download->GetState()); |
| 1058 EXPECT_EQ(error, download->GetLastReason()); | 1174 EXPECT_EQ(error, download->GetLastReason()); |
| 1059 return download; | 1175 return download; |
| 1060 } | 1176 } |
| 1061 | 1177 |
| 1178 protected: | |
| 1179 scoped_ptr<TestSafeBrowsingServiceFactory> test_safe_browsing_factory_; | |
| 1180 | |
| 1062 private: | 1181 private: |
| 1063 static void EnsureNoPendingDownloadJobsOnIO(bool* result) { | 1182 static void EnsureNoPendingDownloadJobsOnIO(bool* result) { |
| 1064 if (net::URLRequestSlowDownloadJob::NumberOutstandingRequests()) | 1183 if (net::URLRequestSlowDownloadJob::NumberOutstandingRequests()) |
| 1065 *result = false; | 1184 *result = false; |
| 1066 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 1185 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| 1067 base::MessageLoop::QuitWhenIdleClosure()); | 1186 base::MessageLoop::QuitWhenIdleClosure()); |
| 1068 } | 1187 } |
| 1069 | 1188 |
| 1070 // Location of the test data. | 1189 // Location of the test data. |
| 1071 base::FilePath test_dir_; | 1190 base::FilePath test_dir_; |
| (...skipping 2191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3263 ASSERT_TRUE(safe_browsing::DownloadFeedbackService::IsEnabledForDownload( | 3382 ASSERT_TRUE(safe_browsing::DownloadFeedbackService::IsEnabledForDownload( |
| 3264 *(downloads[0]))); | 3383 *(downloads[0]))); |
| 3265 | 3384 |
| 3266 // Begin feedback and check that the file is "stolen". | 3385 // Begin feedback and check that the file is "stolen". |
| 3267 download_protection_service->feedback_service()->BeginFeedbackForDownload( | 3386 download_protection_service->feedback_service()->BeginFeedbackForDownload( |
| 3268 downloads[0]); | 3387 downloads[0]); |
| 3269 std::vector<DownloadItem*> updated_downloads; | 3388 std::vector<DownloadItem*> updated_downloads; |
| 3270 GetDownloads(browser(), &updated_downloads); | 3389 GetDownloads(browser(), &updated_downloads); |
| 3271 ASSERT_TRUE(updated_downloads.empty()); | 3390 ASSERT_TRUE(updated_downloads.empty()); |
| 3272 } | 3391 } |
| 3392 | |
| 3393 IN_PROC_BROWSER_TEST_F(DownloadTest, SendUncommonDownloadAcceptReport) { | |
| 3394 browser()->profile()->GetPrefs()->SetBoolean(prefs::kSafeBrowsingEnabled, | |
| 3395 true); | |
| 3396 // Make a dangerous file. | |
| 3397 GURL download_url( | |
| 3398 net::URLRequestMockHTTPJob::GetMockUrl(kDangerousMockFilePath)); | |
| 3399 scoped_ptr<content::DownloadTestObserver> dangerous_observer( | |
| 3400 UncommonDownloadWaiter( | |
| 3401 browser(), 1, | |
| 3402 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_ACCEPT)); | |
| 3403 scoped_ptr<content::DownloadTestObserver> in_progress_observer( | |
| 3404 new content::DownloadTestObserverInProgress( | |
| 3405 DownloadManagerForBrowser(browser()), 1)); | |
| 3406 | |
| 3407 ui_test_utils::NavigateToURL(browser(), download_url); | |
| 3408 in_progress_observer->WaitForFinished(); | |
| 3409 | |
| 3410 std::vector<DownloadItem*> downloads; | |
| 3411 DownloadManagerForBrowser(browser())->GetAllDownloads(&downloads); | |
| 3412 ASSERT_EQ(1u, downloads.size()); | |
| 3413 DownloadItem* download = downloads[0]; | |
| 3414 // Simulates an uncommon download. | |
| 3415 download->OnContentCheckCompleted( | |
| 3416 content::DownloadDangerType::DOWNLOAD_DANGER_TYPE_UNCOMMON_CONTENT); | |
| 3417 ASSERT_EQ(download->GetDangerType(), | |
| 3418 content::DownloadDangerType::DOWNLOAD_DANGER_TYPE_UNCOMMON_CONTENT); | |
| 3419 dangerous_observer->WaitForFinished(); | |
| 3420 | |
| 3421 safe_browsing::ClientSafeBrowsingReportRequest actual_report; | |
| 3422 actual_report.ParseFromString( | |
| 3423 test_safe_browsing_factory_->fake_safe_browsing_service() | |
| 3424 ->GetDownloadReport()); | |
| 3425 EXPECT_EQ(safe_browsing::ClientSafeBrowsingReportRequest:: | |
| 3426 DANGEROUS_DOWNLOAD_WARNING, | |
| 3427 actual_report.type()); | |
| 3428 EXPECT_EQ(safe_browsing::ClientDownloadResponse::UNCOMMON, | |
| 3429 actual_report.download_verdict()); | |
| 3430 EXPECT_EQ(download->GetURL().spec(), actual_report.url()); | |
| 3431 EXPECT_TRUE(actual_report.did_proceed()); | |
| 3432 | |
| 3433 download->Cancel(true); | |
| 3434 } | |
| 3273 #endif // FULL_SAFE_BROWSING | 3435 #endif // FULL_SAFE_BROWSING |
| 3274 | 3436 |
| 3275 class DownloadTestWithShelf : public DownloadTest { | 3437 class DownloadTestWithShelf : public DownloadTest { |
| 3276 void SetUpCommandLine(base::CommandLine* command_line) override { | 3438 void SetUpCommandLine(base::CommandLine* command_line) override { |
| 3277 #if defined(OS_CHROMEOS) | 3439 #if defined(OS_CHROMEOS) |
| 3278 command_line->AppendSwitch(switches::kDisableDownloadNotification); | 3440 command_line->AppendSwitch(switches::kDisableDownloadNotification); |
| 3279 #endif | 3441 #endif |
| 3280 DownloadTest::SetUpCommandLine(command_line); | 3442 DownloadTest::SetUpCommandLine(command_line); |
| 3281 } | 3443 } |
| 3282 }; | 3444 }; |
| (...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3525 | 3687 |
| 3526 scoped_ptr<content::DownloadTestObserver> observer(DangerousDownloadWaiter( | 3688 scoped_ptr<content::DownloadTestObserver> observer(DangerousDownloadWaiter( |
| 3527 browser(), 1, content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_DENY)); | 3689 browser(), 1, content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_DENY)); |
| 3528 ui_test_utils::NavigateToURL(browser(), extension_url); | 3690 ui_test_utils::NavigateToURL(browser(), extension_url); |
| 3529 | 3691 |
| 3530 observer->WaitForFinished(); | 3692 observer->WaitForFinished(); |
| 3531 | 3693 |
| 3532 // Download shelf should close. | 3694 // Download shelf should close. |
| 3533 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); | 3695 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); |
| 3534 } | 3696 } |
| OLD | NEW |