| 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 <sstream> | 5 #include <sstream> |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/file_path.h" | 9 #include "base/file_path.h" |
| 10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
| 11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
| 12 #include "base/path_service.h" | 12 #include "base/path_service.h" |
| 13 #include "base/scoped_temp_dir.h" | 13 #include "base/scoped_temp_dir.h" |
| 14 #include "base/stl_util.h" | 14 #include "base/stl_util.h" |
| 15 #include "base/stringprintf.h" | 15 #include "base/stringprintf.h" |
| 16 #include "base/test/test_file_util.h" | 16 #include "base/test/test_file_util.h" |
| 17 #include "base/utf_string_conversions.h" | 17 #include "base/utf_string_conversions.h" |
| 18 #include "chrome/app/chrome_command_ids.h" | 18 #include "chrome/app/chrome_command_ids.h" |
| 19 #include "chrome/browser/browser_process.h" | 19 #include "chrome/browser/browser_process.h" |
| 20 #include "chrome/browser/cancelable_request.h" | 20 #include "chrome/browser/cancelable_request.h" |
| 21 #include "chrome/browser/download/chrome_download_manager_delegate.h" | 21 #include "chrome/browser/download/chrome_download_manager_delegate.h" |
| 22 #include "chrome/browser/download/download_crx_util.h" | 22 #include "chrome/browser/download/download_crx_util.h" |
| 23 #include "chrome/browser/download/download_history.h" | 23 #include "chrome/browser/download/download_history.h" |
| 24 #include "chrome/browser/download/download_prefs.h" | 24 #include "chrome/browser/download/download_prefs.h" |
| 25 #include "chrome/browser/download/download_request_limiter.h" | 25 #include "chrome/browser/download/download_request_limiter.h" |
| 26 #include "chrome/browser/download/download_service.h" | |
| 27 #include "chrome/browser/download/download_service_factory.h" | |
| 28 #include "chrome/browser/download/download_shelf.h" | 26 #include "chrome/browser/download/download_shelf.h" |
| 29 #include "chrome/browser/download/download_test_observer.h" | 27 #include "chrome/browser/download/download_test_observer.h" |
| 30 #include "chrome/browser/download/download_util.h" | 28 #include "chrome/browser/download/download_util.h" |
| 31 #include "chrome/browser/extensions/extension_install_prompt.h" | 29 #include "chrome/browser/extensions/extension_install_prompt.h" |
| 32 #include "chrome/browser/extensions/extension_service.h" | 30 #include "chrome/browser/extensions/extension_service.h" |
| 33 #include "chrome/browser/history/history.h" | 31 #include "chrome/browser/history/history.h" |
| 34 #include "chrome/browser/history/history_service_factory.h" | 32 #include "chrome/browser/history/history_service_factory.h" |
| 35 #include "chrome/browser/net/url_request_mock_util.h" | 33 #include "chrome/browser/net/url_request_mock_util.h" |
| 36 #include "chrome/browser/prefs/pref_service.h" | 34 #include "chrome/browser/prefs/pref_service.h" |
| 37 #include "chrome/browser/profiles/profile.h" | 35 #include "chrome/browser/profiles/profile.h" |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 | 77 |
| 80 namespace { | 78 namespace { |
| 81 | 79 |
| 82 // IDs and paths of CRX files used in tests. | 80 // IDs and paths of CRX files used in tests. |
| 83 const char kGoodCrxId[] = "ldnnhddmnhbkjipkidpdiheffobcpfmf"; | 81 const char kGoodCrxId[] = "ldnnhddmnhbkjipkidpdiheffobcpfmf"; |
| 84 const FilePath kGoodCrxPath(FILE_PATH_LITERAL("extensions/good.crx")); | 82 const FilePath kGoodCrxPath(FILE_PATH_LITERAL("extensions/good.crx")); |
| 85 | 83 |
| 86 const char kLargeThemeCrxId[] = "pjpgmfcmabopnnfonnhmdjglfpjjfkbf"; | 84 const char kLargeThemeCrxId[] = "pjpgmfcmabopnnfonnhmdjglfpjjfkbf"; |
| 87 const FilePath kLargeThemePath(FILE_PATH_LITERAL("extensions/theme2.crx")); | 85 const FilePath kLargeThemePath(FILE_PATH_LITERAL("extensions/theme2.crx")); |
| 88 | 86 |
| 89 class PickSuggestedFileDelegate : public ChromeDownloadManagerDelegate { | |
| 90 public: | |
| 91 explicit PickSuggestedFileDelegate(Profile* profile) | |
| 92 : ChromeDownloadManagerDelegate(profile) { | |
| 93 } | |
| 94 | |
| 95 virtual void ChooseDownloadPath(DownloadItem* item) OVERRIDE { | |
| 96 if (download_manager_) | |
| 97 download_manager_->FileSelected(item->GetTargetFilePath(), item->GetId()); | |
| 98 } | |
| 99 | |
| 100 protected: | |
| 101 virtual ~PickSuggestedFileDelegate() {} | |
| 102 }; | |
| 103 | |
| 104 // Get History Information. | 87 // Get History Information. |
| 105 class DownloadsHistoryDataCollector { | 88 class DownloadsHistoryDataCollector { |
| 106 public: | 89 public: |
| 107 DownloadsHistoryDataCollector(int64 download_db_handle, | 90 DownloadsHistoryDataCollector(int64 download_db_handle, |
| 108 DownloadManager* manager) | 91 DownloadManager* manager) |
| 109 : result_valid_(false), | 92 : result_valid_(false), |
| 110 download_db_handle_(download_db_handle) { | 93 download_db_handle_(download_db_handle) { |
| 111 HistoryService* hs = HistoryServiceFactory::GetForProfile( | 94 HistoryService* hs = HistoryServiceFactory::GetForProfile( |
| 112 Profile::FromBrowserContext(manager->GetBrowserContext()), | 95 Profile::FromBrowserContext(manager->GetBrowserContext()), |
| 113 Profile::EXPLICIT_ACCESS); | 96 Profile::EXPLICIT_ACCESS); |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 240 } | 223 } |
| 241 | 224 |
| 242 private: | 225 private: |
| 243 DownloadManager* download_manager_; | 226 DownloadManager* download_manager_; |
| 244 | 227 |
| 245 DISALLOW_COPY_AND_ASSIGN(MockDownloadOpeningObserver); | 228 DISALLOW_COPY_AND_ASSIGN(MockDownloadOpeningObserver); |
| 246 }; | 229 }; |
| 247 | 230 |
| 248 class DownloadTest : public InProcessBrowserTest { | 231 class DownloadTest : public InProcessBrowserTest { |
| 249 public: | 232 public: |
| 250 enum SelectExpectation { | |
| 251 EXPECT_NO_SELECT_DIALOG = -1, | |
| 252 EXPECT_NOTHING, | |
| 253 EXPECT_SELECT_DIALOG | |
| 254 }; | |
| 255 | |
| 256 // Choice of navigation or direct fetch. Used by |DownloadFileCheckErrors()|. | 233 // Choice of navigation or direct fetch. Used by |DownloadFileCheckErrors()|. |
| 257 enum DownloadMethod { | 234 enum DownloadMethod { |
| 258 DOWNLOAD_NAVIGATE, | 235 DOWNLOAD_NAVIGATE, |
| 259 DOWNLOAD_DIRECT | 236 DOWNLOAD_DIRECT |
| 260 }; | 237 }; |
| 261 | 238 |
| 262 // Information passed in to |DownloadFileCheckErrors()|. | 239 // Information passed in to |DownloadFileCheckErrors()|. |
| 263 struct DownloadInfo { | 240 struct DownloadInfo { |
| 264 const char* url_name; // URL for the download. | 241 const char* url_name; // URL for the download. |
| 265 DownloadMethod download_method; // Navigation or Direct. | 242 DownloadMethod download_method; // Navigation or Direct. |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 304 EXPECT_TRUE(created_downloads_dir); | 281 EXPECT_TRUE(created_downloads_dir); |
| 305 if (!created_downloads_dir) | 282 if (!created_downloads_dir) |
| 306 return false; | 283 return false; |
| 307 browser()->profile()->GetPrefs()->SetBoolean( | 284 browser()->profile()->GetPrefs()->SetBoolean( |
| 308 prefs::kPromptForDownload, false); | 285 prefs::kPromptForDownload, false); |
| 309 | 286 |
| 310 DownloadManager* manager = DownloadManagerForBrowser(browser()); | 287 DownloadManager* manager = DownloadManagerForBrowser(browser()); |
| 311 DownloadPrefs::FromDownloadManager(manager)->ResetAutoOpen(); | 288 DownloadPrefs::FromDownloadManager(manager)->ResetAutoOpen(); |
| 312 manager->RemoveAllDownloads(); | 289 manager->RemoveAllDownloads(); |
| 313 | 290 |
| 291 file_chooser_observer_.reset( |
| 292 new DownloadTestFileChooserObserver(browser()->profile())); |
| 293 |
| 314 return true; | 294 return true; |
| 315 } | 295 } |
| 316 | 296 |
| 317 protected: | 297 protected: |
| 318 | 298 |
| 319 enum SizeTestType { | 299 enum SizeTestType { |
| 320 SIZE_TEST_TYPE_KNOWN, | 300 SIZE_TEST_TYPE_KNOWN, |
| 321 SIZE_TEST_TYPE_UNKNOWN, | 301 SIZE_TEST_TYPE_UNKNOWN, |
| 322 }; | 302 }; |
| 323 | 303 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 357 FilePath GetDownloadDirectory(Browser* browser) { | 337 FilePath GetDownloadDirectory(Browser* browser) { |
| 358 return GetDownloadPrefs(browser)->download_path(); | 338 return GetDownloadPrefs(browser)->download_path(); |
| 359 } | 339 } |
| 360 | 340 |
| 361 // Create a DownloadTestObserverTerminal that will wait for the | 341 // Create a DownloadTestObserverTerminal that will wait for the |
| 362 // specified number of downloads to finish. | 342 // specified number of downloads to finish. |
| 363 DownloadTestObserver* CreateWaiter(Browser* browser, int num_downloads) { | 343 DownloadTestObserver* CreateWaiter(Browser* browser, int num_downloads) { |
| 364 DownloadManager* download_manager = DownloadManagerForBrowser(browser); | 344 DownloadManager* download_manager = DownloadManagerForBrowser(browser); |
| 365 return new DownloadTestObserverTerminal( | 345 return new DownloadTestObserverTerminal( |
| 366 download_manager, num_downloads, | 346 download_manager, num_downloads, |
| 367 true, // Bail on select file | |
| 368 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL); | 347 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL); |
| 369 } | 348 } |
| 370 | 349 |
| 371 // Create a DownloadTestObserverInProgress that will wait for the | 350 // Create a DownloadTestObserverInProgress that will wait for the |
| 372 // specified number of downloads to start. | 351 // specified number of downloads to start. |
| 373 DownloadTestObserver* CreateInProgressWaiter(Browser* browser, | 352 DownloadTestObserver* CreateInProgressWaiter(Browser* browser, |
| 374 int num_downloads) { | 353 int num_downloads) { |
| 375 DownloadManager* download_manager = DownloadManagerForBrowser(browser); | 354 DownloadManager* download_manager = DownloadManagerForBrowser(browser); |
| 376 return new DownloadTestObserverInProgress( | 355 return new DownloadTestObserverInProgress( |
| 377 download_manager, num_downloads, true); // Bail on select file. | 356 download_manager, num_downloads); |
| 378 } | 357 } |
| 379 | 358 |
| 380 // Create a DownloadTestObserverTerminal that will wait for the | 359 // Create a DownloadTestObserverTerminal that will wait for the |
| 381 // specified number of downloads to finish, or for | 360 // specified number of downloads to finish, or for |
| 382 // a dangerous download warning to be shown. | 361 // a dangerous download warning to be shown. |
| 383 DownloadTestObserver* DangerousDownloadWaiter( | 362 DownloadTestObserver* DangerousDownloadWaiter( |
| 384 Browser* browser, | 363 Browser* browser, |
| 385 int num_downloads, | 364 int num_downloads, |
| 386 DownloadTestObserver::DangerousDownloadAction dangerous_download_action) { | 365 DownloadTestObserver::DangerousDownloadAction dangerous_download_action) { |
| 387 DownloadManager* download_manager = DownloadManagerForBrowser(browser); | 366 DownloadManager* download_manager = DownloadManagerForBrowser(browser); |
| 388 return new DownloadTestObserverTerminal( | 367 return new DownloadTestObserverTerminal( |
| 389 download_manager, num_downloads, | 368 download_manager, num_downloads, |
| 390 true, // Bail on select file | |
| 391 dangerous_download_action); | 369 dangerous_download_action); |
| 392 } | 370 } |
| 393 | 371 |
| 394 void CheckDownloadStatesForBrowser(Browser* browser, | 372 void CheckDownloadStatesForBrowser(Browser* browser, |
| 395 size_t num, | 373 size_t num, |
| 396 DownloadItem::DownloadState state) { | 374 DownloadItem::DownloadState state) { |
| 397 std::vector<DownloadItem*> download_items; | 375 std::vector<DownloadItem*> download_items; |
| 398 GetDownloads(browser, &download_items); | 376 GetDownloads(browser, &download_items); |
| 399 | 377 |
| 400 EXPECT_EQ(num, download_items.size()); | 378 EXPECT_EQ(num, download_items.size()); |
| 401 | 379 |
| 402 for (size_t i = 0; i < download_items.size(); ++i) { | 380 for (size_t i = 0; i < download_items.size(); ++i) { |
| 403 EXPECT_EQ(state, download_items[i]->GetState()) << " Item " << i; | 381 EXPECT_EQ(state, download_items[i]->GetState()) << " Item " << i; |
| 404 } | 382 } |
| 405 } | 383 } |
| 406 | 384 |
| 407 void CheckDownloadStates(size_t num, DownloadItem::DownloadState state) { | 385 void CheckDownloadStates(size_t num, DownloadItem::DownloadState state) { |
| 408 CheckDownloadStatesForBrowser(browser(), num, state); | 386 CheckDownloadStatesForBrowser(browser(), num, state); |
| 409 } | 387 } |
| 410 | 388 |
| 411 // Download |url|, then wait for the download to finish. | 389 // Download |url|, then wait for the download to finish. |
| 412 // |disposition| indicates where the navigation occurs (current tab, new | 390 // |disposition| indicates where the navigation occurs (current tab, new |
| 413 // foreground tab, etc). | 391 // foreground tab, etc). |
| 414 // |expectation| indicates whether or not a Select File dialog should be | |
| 415 // open when the download is finished, or if we don't care. | |
| 416 // If the dialog appears, the routine exits. The only effect |expectation| | |
| 417 // has is whether or not the test succeeds. | |
| 418 // |browser_test_flags| indicate what to wait for, and is an OR of 0 or more | 392 // |browser_test_flags| indicate what to wait for, and is an OR of 0 or more |
| 419 // values in the ui_test_utils::BrowserTestWaitFlags enum. | 393 // values in the ui_test_utils::BrowserTestWaitFlags enum. |
| 420 void DownloadAndWaitWithDisposition(Browser* browser, | 394 void DownloadAndWaitWithDisposition(Browser* browser, |
| 421 const GURL& url, | 395 const GURL& url, |
| 422 WindowOpenDisposition disposition, | 396 WindowOpenDisposition disposition, |
| 423 SelectExpectation expectation, | |
| 424 int browser_test_flags) { | 397 int browser_test_flags) { |
| 425 // Setup notification, navigate, and block. | 398 // Setup notification, navigate, and block. |
| 426 scoped_ptr<DownloadTestObserver> observer(CreateWaiter(browser, 1)); | 399 scoped_ptr<DownloadTestObserver> observer(CreateWaiter(browser, 1)); |
| 427 // This call will block until the condition specified by | 400 // This call will block until the condition specified by |
| 428 // |browser_test_flags|, but will not wait for the download to finish. | 401 // |browser_test_flags|, but will not wait for the download to finish. |
| 429 ui_test_utils::NavigateToURLWithDisposition(browser, | 402 ui_test_utils::NavigateToURLWithDisposition(browser, |
| 430 url, | 403 url, |
| 431 disposition, | 404 disposition, |
| 432 browser_test_flags); | 405 browser_test_flags); |
| 433 // Waits for the download to complete. | 406 // Waits for the download to complete. |
| 434 observer->WaitForFinished(); | 407 observer->WaitForFinished(); |
| 435 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE)); | 408 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE)); |
| 436 | 409 // We don't expect a file chooser to be shown. |
| 437 // If specified, check the state of the select file dialog. | 410 EXPECT_FALSE(DidShowFileChooser()); |
| 438 if (expectation != EXPECT_NOTHING) { | |
| 439 EXPECT_EQ(expectation == EXPECT_SELECT_DIALOG, | |
| 440 observer->select_file_dialog_seen()); | |
| 441 } | |
| 442 } | 411 } |
| 443 | 412 |
| 444 // Download a file in the current tab, then wait for the download to finish. | 413 // Download a file in the current tab, then wait for the download to finish. |
| 445 void DownloadAndWait(Browser* browser, | 414 void DownloadAndWait(Browser* browser, |
| 446 const GURL& url, | 415 const GURL& url) { |
| 447 SelectExpectation expectation) { | |
| 448 DownloadAndWaitWithDisposition( | 416 DownloadAndWaitWithDisposition( |
| 449 browser, | 417 browser, |
| 450 url, | 418 url, |
| 451 CURRENT_TAB, | 419 CURRENT_TAB, |
| 452 expectation, | |
| 453 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); | 420 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
| 454 } | 421 } |
| 455 | 422 |
| 456 // Should only be called when the download is known to have finished | 423 // Should only be called when the download is known to have finished |
| 457 // (in error or not). | 424 // (in error or not). |
| 458 // Returning false indicates a failure of the function, and should be asserted | 425 // Returning false indicates a failure of the function, and should be asserted |
| 459 // in the caller. | 426 // in the caller. |
| 460 bool CheckDownload(Browser* browser, | 427 bool CheckDownload(Browser* browser, |
| 461 const FilePath& downloaded_filename, | 428 const FilePath& downloaded_filename, |
| 462 const FilePath& origin_filename) { | 429 const FilePath& origin_filename) { |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 575 void GetDownloads(Browser* browser, std::vector<DownloadItem*>* downloads) { | 542 void GetDownloads(Browser* browser, std::vector<DownloadItem*>* downloads) { |
| 576 DCHECK(downloads); | 543 DCHECK(downloads); |
| 577 DownloadManager* manager = DownloadManagerForBrowser(browser); | 544 DownloadManager* manager = DownloadManagerForBrowser(browser); |
| 578 manager->SearchDownloads(string16(), downloads); | 545 manager->SearchDownloads(string16(), downloads); |
| 579 } | 546 } |
| 580 | 547 |
| 581 static void ExpectWindowCountAfterDownload(size_t expected) { | 548 static void ExpectWindowCountAfterDownload(size_t expected) { |
| 582 EXPECT_EQ(expected, BrowserList::size()); | 549 EXPECT_EQ(expected, BrowserList::size()); |
| 583 } | 550 } |
| 584 | 551 |
| 585 // Arrange for select file calls on the given browser from the | 552 void EnableFileChooser(bool enable) { |
| 586 // download manager to always choose the suggested file. | 553 file_chooser_observer_->EnableFileChooser(enable); |
| 587 void NullSelectFile(Browser* browser) { | 554 } |
| 588 PickSuggestedFileDelegate* new_delegate = | |
| 589 new PickSuggestedFileDelegate(browser->profile()); | |
| 590 | 555 |
| 591 // Gives ownership to DownloadService. | 556 bool DidShowFileChooser() { |
| 592 DownloadServiceFactory::GetForProfile( | 557 return file_chooser_observer_->TestAndResetDidShowFileChooser(); |
| 593 browser->profile())->SetDownloadManagerDelegateForTesting(new_delegate); | |
| 594 } | 558 } |
| 595 | 559 |
| 596 // Checks that |path| is has |file_size| bytes, and matches the |value| | 560 // Checks that |path| is has |file_size| bytes, and matches the |value| |
| 597 // string. | 561 // string. |
| 598 bool VerifyFile(const FilePath& path, | 562 bool VerifyFile(const FilePath& path, |
| 599 const std::string& value, | 563 const std::string& value, |
| 600 const int64 file_size) { | 564 const int64 file_size) { |
| 601 std::string file_contents; | 565 std::string file_contents; |
| 602 | 566 |
| 603 bool read = file_util::ReadFileToString(path, &file_contents); | 567 bool read = file_util::ReadFileToString(path, &file_contents); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 623 } | 587 } |
| 624 | 588 |
| 625 // Attempts to download a file, based on information in |download_info|. | 589 // Attempts to download a file, based on information in |download_info|. |
| 626 // If a Select File dialog opens, will automatically choose the default. | 590 // If a Select File dialog opens, will automatically choose the default. |
| 627 void DownloadFilesCheckErrorsSetup() { | 591 void DownloadFilesCheckErrorsSetup() { |
| 628 ASSERT_TRUE(test_server()->Start()); | 592 ASSERT_TRUE(test_server()->Start()); |
| 629 std::vector<DownloadItem*> download_items; | 593 std::vector<DownloadItem*> download_items; |
| 630 GetDownloads(browser(), &download_items); | 594 GetDownloads(browser(), &download_items); |
| 631 ASSERT_TRUE(download_items.empty()); | 595 ASSERT_TRUE(download_items.empty()); |
| 632 | 596 |
| 633 NullSelectFile(browser()); | 597 EnableFileChooser(true); |
| 634 } | 598 } |
| 635 | 599 |
| 636 void DownloadFilesCheckErrorsLoopBody(const DownloadInfo& download_info, | 600 void DownloadFilesCheckErrorsLoopBody(const DownloadInfo& download_info, |
| 637 size_t i) { | 601 size_t i) { |
| 638 std::stringstream s; | 602 std::stringstream s; |
| 639 s << " " << __FUNCTION__ << "()" | 603 s << " " << __FUNCTION__ << "()" |
| 640 << " index = " << i | 604 << " index = " << i |
| 641 << " url = '" << download_info.url_name << "'" | 605 << " url = '" << download_info.url_name << "'" |
| 642 << " method = " | 606 << " method = " |
| 643 << ((download_info.download_method == DOWNLOAD_DIRECT) ? | 607 << ((download_info.download_method == DOWNLOAD_DIRECT) ? |
| (...skipping 12 matching lines...) Expand all Loading... |
| 656 ASSERT_TRUE(url.is_valid()) << s.str(); | 620 ASSERT_TRUE(url.is_valid()) << s.str(); |
| 657 | 621 |
| 658 DownloadManager* download_manager = DownloadManagerForBrowser(browser()); | 622 DownloadManager* download_manager = DownloadManagerForBrowser(browser()); |
| 659 WebContents* web_contents = chrome::GetActiveWebContents(browser()); | 623 WebContents* web_contents = chrome::GetActiveWebContents(browser()); |
| 660 ASSERT_TRUE(web_contents) << s.str(); | 624 ASSERT_TRUE(web_contents) << s.str(); |
| 661 | 625 |
| 662 scoped_ptr<DownloadTestObserver> observer( | 626 scoped_ptr<DownloadTestObserver> observer( |
| 663 new DownloadTestObserverTerminal( | 627 new DownloadTestObserverTerminal( |
| 664 download_manager, | 628 download_manager, |
| 665 1, | 629 1, |
| 666 false, // Don't bail on select file. | |
| 667 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL)); | 630 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL)); |
| 668 | 631 |
| 669 if (download_info.download_method == DOWNLOAD_DIRECT) { | 632 if (download_info.download_method == DOWNLOAD_DIRECT) { |
| 670 // Go directly to download. Don't wait for navigation. | 633 // Go directly to download. Don't wait for navigation. |
| 671 content::DownloadSaveInfo save_info; | 634 content::DownloadSaveInfo save_info; |
| 672 // NOTE: |prompt_for_save_location| may change during the download. | 635 // NOTE: |prompt_for_save_location| may change during the download. |
| 673 save_info.prompt_for_save_location = false; | 636 save_info.prompt_for_save_location = false; |
| 674 | 637 |
| 675 scoped_refptr<DownloadTestItemCreationObserver> creation_observer( | 638 scoped_refptr<DownloadTestItemCreationObserver> creation_observer( |
| 676 new DownloadTestItemCreationObserver); | 639 new DownloadTestItemCreationObserver); |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 860 *result = false; | 823 *result = false; |
| 861 BrowserThread::PostTask( | 824 BrowserThread::PostTask( |
| 862 BrowserThread::UI, FROM_HERE, MessageLoop::QuitClosure()); | 825 BrowserThread::UI, FROM_HERE, MessageLoop::QuitClosure()); |
| 863 } | 826 } |
| 864 | 827 |
| 865 // Location of the test data. | 828 // Location of the test data. |
| 866 FilePath test_dir_; | 829 FilePath test_dir_; |
| 867 | 830 |
| 868 // Location of the downloads directory for these tests | 831 // Location of the downloads directory for these tests |
| 869 ScopedTempDir downloads_directory_; | 832 ScopedTempDir downloads_directory_; |
| 833 |
| 834 scoped_ptr<DownloadTestFileChooserObserver> file_chooser_observer_; |
| 870 }; | 835 }; |
| 871 | 836 |
| 872 // NOTES: | 837 // NOTES: |
| 873 // | 838 // |
| 874 // Files for these tests are found in DIR_TEST_DATA (currently | 839 // Files for these tests are found in DIR_TEST_DATA (currently |
| 875 // "chrome\test\data\", see chrome_paths.cc). | 840 // "chrome\test\data\", see chrome_paths.cc). |
| 876 // Mock responses have extension .mock-http-headers appended to the file name. | 841 // Mock responses have extension .mock-http-headers appended to the file name. |
| 877 | 842 |
| 878 // Download a file due to the associated MIME type. | 843 // Download a file due to the associated MIME type. |
| 879 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadMimeType) { | 844 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadMimeType) { |
| 880 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); | 845 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); |
| 881 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); | 846 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); |
| 882 | 847 |
| 883 // Download the file and wait. We do not expect the Select File dialog. | 848 // Download the file and wait. We do not expect the Select File dialog. |
| 884 DownloadAndWait(browser(), url, EXPECT_NO_SELECT_DIALOG); | 849 DownloadAndWait(browser(), url); |
| 885 | 850 |
| 886 // Check state. | 851 // Check state. |
| 887 EXPECT_EQ(1, browser()->tab_count()); | 852 EXPECT_EQ(1, browser()->tab_count()); |
| 888 CheckDownload(browser(), file, file); | 853 CheckDownload(browser(), file, file); |
| 889 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); | 854 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); |
| 890 } | 855 } |
| 891 | 856 |
| 892 #if defined(OS_WIN) | 857 #if defined(OS_WIN) |
| 893 // Download a file and confirm that the zone identifier (on windows) | 858 // Download a file and confirm that the zone identifier (on windows) |
| 894 // is set to internet. | 859 // is set to internet. |
| 895 IN_PROC_BROWSER_TEST_F(DownloadTest, CheckInternetZone) { | 860 IN_PROC_BROWSER_TEST_F(DownloadTest, CheckInternetZone) { |
| 896 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); | 861 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); |
| 897 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); | 862 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); |
| 898 | 863 |
| 899 // Download the file and wait. We do not expect the Select File dialog. | 864 // Download the file and wait. We do not expect the Select File dialog. |
| 900 DownloadAndWait(browser(), url, EXPECT_NO_SELECT_DIALOG); | 865 DownloadAndWait(browser(), url); |
| 901 | 866 |
| 902 // Check state. Special file state must be checked before CheckDownload, | 867 // Check state. Special file state must be checked before CheckDownload, |
| 903 // as CheckDownload will delete the output file. | 868 // as CheckDownload will delete the output file. |
| 904 EXPECT_EQ(1, browser()->tab_count()); | 869 EXPECT_EQ(1, browser()->tab_count()); |
| 905 FilePath downloaded_file(DestinationFile(browser(), file)); | 870 FilePath downloaded_file(DestinationFile(browser(), file)); |
| 906 if (file_util::VolumeSupportsADS(downloaded_file)) | 871 if (file_util::VolumeSupportsADS(downloaded_file)) |
| 907 EXPECT_TRUE(file_util::HasInternetZoneIdentifier(downloaded_file)); | 872 EXPECT_TRUE(file_util::HasInternetZoneIdentifier(downloaded_file)); |
| 908 CheckDownload(browser(), file, file); | 873 CheckDownload(browser(), file, file); |
| 909 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); | 874 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); |
| 910 } | 875 } |
| 911 #endif | 876 #endif |
| 912 | 877 |
| 913 // Put up a Select File dialog when the file is downloaded, due to | 878 // Put up a Select File dialog when the file is downloaded, due to |
| 914 // downloads preferences settings. | 879 // downloads preferences settings. |
| 915 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadMimeTypeSelect) { | 880 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadMimeTypeSelect) { |
| 916 // Re-enable prompting. | 881 // Re-enable prompting. |
| 917 browser()->profile()->GetPrefs()->SetBoolean( | 882 browser()->profile()->GetPrefs()->SetBoolean( |
| 918 prefs::kPromptForDownload, true); | 883 prefs::kPromptForDownload, true); |
| 919 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); | 884 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); |
| 920 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); | 885 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); |
| 921 | 886 |
| 922 NullSelectFile(browser()); | 887 EnableFileChooser(true); |
| 923 | 888 |
| 924 // Download the file and wait. We expect the Select File dialog to appear | 889 // Download the file and wait. We expect the Select File dialog to appear |
| 925 // due to the MIME type, but we still wait until the download completes. | 890 // due to the MIME type, but we still wait until the download completes. |
| 926 scoped_ptr<DownloadTestObserver> observer( | 891 scoped_ptr<DownloadTestObserver> observer( |
| 927 new DownloadTestObserverTerminal( | 892 new DownloadTestObserverTerminal( |
| 928 DownloadManagerForBrowser(browser()), | 893 DownloadManagerForBrowser(browser()), |
| 929 1, | 894 1, |
| 930 false, // Continue on select file. | |
| 931 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL)); | 895 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL)); |
| 932 ui_test_utils::NavigateToURLWithDisposition( | 896 ui_test_utils::NavigateToURLWithDisposition( |
| 933 browser(), url, CURRENT_TAB, | 897 browser(), url, CURRENT_TAB, |
| 934 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); | 898 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
| 935 observer->WaitForFinished(); | 899 observer->WaitForFinished(); |
| 936 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE)); | 900 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE)); |
| 937 CheckDownloadStates(1, DownloadItem::COMPLETE); | 901 CheckDownloadStates(1, DownloadItem::COMPLETE); |
| 938 EXPECT_TRUE(observer->select_file_dialog_seen()); | 902 EXPECT_TRUE(DidShowFileChooser()); |
| 939 | 903 |
| 940 // Check state. | 904 // Check state. |
| 941 EXPECT_EQ(1, browser()->tab_count()); | 905 EXPECT_EQ(1, browser()->tab_count()); |
| 942 CheckDownload(browser(), file, file); | 906 CheckDownload(browser(), file, file); |
| 943 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); | 907 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); |
| 944 } | 908 } |
| 945 | 909 |
| 946 // Access a file with a viewable mime-type, verify that a download | 910 // Access a file with a viewable mime-type, verify that a download |
| 947 // did not initiate. | 911 // did not initiate. |
| 948 IN_PROC_BROWSER_TEST_F(DownloadTest, NoDownload) { | 912 IN_PROC_BROWSER_TEST_F(DownloadTest, NoDownload) { |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1055 // Download a 0-size file with a content-disposition header, verify that the | 1019 // Download a 0-size file with a content-disposition header, verify that the |
| 1056 // download tab opened and the file exists as the filename specified in the | 1020 // download tab opened and the file exists as the filename specified in the |
| 1057 // header. This also ensures we properly handle empty file downloads. | 1021 // header. This also ensures we properly handle empty file downloads. |
| 1058 // The download shelf should be visible in the current tab. | 1022 // The download shelf should be visible in the current tab. |
| 1059 IN_PROC_BROWSER_TEST_F(DownloadTest, ContentDisposition) { | 1023 IN_PROC_BROWSER_TEST_F(DownloadTest, ContentDisposition) { |
| 1060 FilePath file(FILE_PATH_LITERAL("download-test3.gif")); | 1024 FilePath file(FILE_PATH_LITERAL("download-test3.gif")); |
| 1061 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); | 1025 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); |
| 1062 FilePath download_file(FILE_PATH_LITERAL("download-test3-attachment.gif")); | 1026 FilePath download_file(FILE_PATH_LITERAL("download-test3-attachment.gif")); |
| 1063 | 1027 |
| 1064 // Download a file and wait. | 1028 // Download a file and wait. |
| 1065 DownloadAndWait(browser(), url, EXPECT_NO_SELECT_DIALOG); | 1029 DownloadAndWait(browser(), url); |
| 1066 | 1030 |
| 1067 CheckDownload(browser(), download_file, file); | 1031 CheckDownload(browser(), download_file, file); |
| 1068 | 1032 |
| 1069 // Check state. | 1033 // Check state. |
| 1070 EXPECT_EQ(1, browser()->tab_count()); | 1034 EXPECT_EQ(1, browser()->tab_count()); |
| 1071 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); | 1035 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); |
| 1072 } | 1036 } |
| 1073 | 1037 |
| 1074 // Test that the download shelf is per-window by starting a download in one | 1038 // Test that the download shelf is per-window by starting a download in one |
| 1075 // tab, opening a second tab, closing the shelf, going back to the first tab, | 1039 // tab, opening a second tab, closing the shelf, going back to the first tab, |
| 1076 // and checking that the shelf is closed. | 1040 // and checking that the shelf is closed. |
| 1077 IN_PROC_BROWSER_TEST_F(DownloadTest, PerWindowShelf) { | 1041 IN_PROC_BROWSER_TEST_F(DownloadTest, PerWindowShelf) { |
| 1078 FilePath file(FILE_PATH_LITERAL("download-test3.gif")); | 1042 FilePath file(FILE_PATH_LITERAL("download-test3.gif")); |
| 1079 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); | 1043 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); |
| 1080 FilePath download_file(FILE_PATH_LITERAL("download-test3-attachment.gif")); | 1044 FilePath download_file(FILE_PATH_LITERAL("download-test3-attachment.gif")); |
| 1081 | 1045 |
| 1082 // Download a file and wait. | 1046 // Download a file and wait. |
| 1083 DownloadAndWait(browser(), url, EXPECT_NO_SELECT_DIALOG); | 1047 DownloadAndWait(browser(), url); |
| 1084 | 1048 |
| 1085 CheckDownload(browser(), download_file, file); | 1049 CheckDownload(browser(), download_file, file); |
| 1086 | 1050 |
| 1087 // Check state. | 1051 // Check state. |
| 1088 EXPECT_EQ(1, browser()->tab_count()); | 1052 EXPECT_EQ(1, browser()->tab_count()); |
| 1089 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); | 1053 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); |
| 1090 | 1054 |
| 1091 // Open a second tab and wait. | 1055 // Open a second tab and wait. |
| 1092 EXPECT_NE(static_cast<TabContents*>(NULL), | 1056 EXPECT_NE(static_cast<TabContents*>(NULL), |
| 1093 chrome::AddSelectedTabWithURL(browser(), GURL(), | 1057 chrome::AddSelectedTabWithURL(browser(), GURL(), |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1107 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); | 1071 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); |
| 1108 } | 1072 } |
| 1109 | 1073 |
| 1110 // Check whether the downloads shelf is closed when the downloads tab is | 1074 // Check whether the downloads shelf is closed when the downloads tab is |
| 1111 // invoked. | 1075 // invoked. |
| 1112 IN_PROC_BROWSER_TEST_F(DownloadTest, CloseShelfOnDownloadsTab) { | 1076 IN_PROC_BROWSER_TEST_F(DownloadTest, CloseShelfOnDownloadsTab) { |
| 1113 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); | 1077 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); |
| 1114 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); | 1078 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); |
| 1115 | 1079 |
| 1116 // Download the file and wait. We do not expect the Select File dialog. | 1080 // Download the file and wait. We do not expect the Select File dialog. |
| 1117 DownloadAndWait(browser(), url, EXPECT_NO_SELECT_DIALOG); | 1081 DownloadAndWait(browser(), url); |
| 1118 | 1082 |
| 1119 // Check state. | 1083 // Check state. |
| 1120 EXPECT_EQ(1, browser()->tab_count()); | 1084 EXPECT_EQ(1, browser()->tab_count()); |
| 1121 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); | 1085 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); |
| 1122 | 1086 |
| 1123 // Open the downloads tab. | 1087 // Open the downloads tab. |
| 1124 chrome::ShowDownloads(browser()); | 1088 chrome::ShowDownloads(browser()); |
| 1125 // The shelf should now be closed. | 1089 // The shelf should now be closed. |
| 1126 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); | 1090 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); |
| 1127 } | 1091 } |
| (...skipping 27 matching lines...) Expand all Loading... |
| 1155 int window_count = BrowserList::size(); | 1119 int window_count = BrowserList::size(); |
| 1156 EXPECT_EQ(2, window_count); | 1120 EXPECT_EQ(2, window_count); |
| 1157 | 1121 |
| 1158 // Download a file in the Incognito window and wait. | 1122 // Download a file in the Incognito window and wait. |
| 1159 CreateAndSetDownloadsDirectory(incognito); | 1123 CreateAndSetDownloadsDirectory(incognito); |
| 1160 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); | 1124 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); |
| 1161 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); | 1125 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); |
| 1162 // Since |incognito| is a separate browser, we have to set it up explicitly. | 1126 // Since |incognito| is a separate browser, we have to set it up explicitly. |
| 1163 incognito->profile()->GetPrefs()->SetBoolean(prefs::kPromptForDownload, | 1127 incognito->profile()->GetPrefs()->SetBoolean(prefs::kPromptForDownload, |
| 1164 false); | 1128 false); |
| 1165 DownloadAndWait(incognito, url, EXPECT_NO_SELECT_DIALOG); | 1129 DownloadAndWait(incognito, url); |
| 1166 | 1130 |
| 1167 // We should still have 2 windows. | 1131 // We should still have 2 windows. |
| 1168 ExpectWindowCountAfterDownload(2); | 1132 ExpectWindowCountAfterDownload(2); |
| 1169 | 1133 |
| 1170 // Verify that the download shelf is showing for the Incognito window. | 1134 // Verify that the download shelf is showing for the Incognito window. |
| 1171 EXPECT_TRUE(incognito->window()->IsDownloadShelfVisible()); | 1135 EXPECT_TRUE(incognito->window()->IsDownloadShelfVisible()); |
| 1172 | 1136 |
| 1173 #if !defined(OS_MACOSX) | 1137 #if !defined(OS_MACOSX) |
| 1174 // On Mac OS X, the UI window close is delayed until the outermost | 1138 // On Mac OS X, the UI window close is delayed until the outermost |
| 1175 // message loop runs. So it isn't possible to get a BROWSER_CLOSED | 1139 // message loop runs. So it isn't possible to get a BROWSER_CLOSED |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1219 // automatically, and that the download shelf is visible in the current tab. | 1183 // automatically, and that the download shelf is visible in the current tab. |
| 1220 IN_PROC_BROWSER_TEST_F(DownloadTest, CloseNewTab1) { | 1184 IN_PROC_BROWSER_TEST_F(DownloadTest, CloseNewTab1) { |
| 1221 // Download a file in a new background tab and wait. The tab is automatically | 1185 // Download a file in a new background tab and wait. The tab is automatically |
| 1222 // closed when the download begins. | 1186 // closed when the download begins. |
| 1223 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); | 1187 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); |
| 1224 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); | 1188 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); |
| 1225 DownloadAndWaitWithDisposition( | 1189 DownloadAndWaitWithDisposition( |
| 1226 browser(), | 1190 browser(), |
| 1227 url, | 1191 url, |
| 1228 NEW_BACKGROUND_TAB, | 1192 NEW_BACKGROUND_TAB, |
| 1229 EXPECT_NO_SELECT_DIALOG, | |
| 1230 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); | 1193 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
| 1231 | 1194 |
| 1232 // When the download finishes, we should still have one tab. | 1195 // When the download finishes, we should still have one tab. |
| 1233 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); | 1196 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); |
| 1234 EXPECT_EQ(1, browser()->tab_count()); | 1197 EXPECT_EQ(1, browser()->tab_count()); |
| 1235 | 1198 |
| 1236 CheckDownload(browser(), file, file); | 1199 CheckDownload(browser(), file, file); |
| 1237 } | 1200 } |
| 1238 | 1201 |
| 1239 // Open a web page in the current tab, then download a file in another tab via | 1202 // Open a web page in the current tab, then download a file in another tab via |
| (...skipping 10 matching lines...) Expand all Loading... |
| 1250 GURL url(URLRequestMockHTTPJob::GetMockUrl(file1)); | 1213 GURL url(URLRequestMockHTTPJob::GetMockUrl(file1)); |
| 1251 | 1214 |
| 1252 // Open a web page and wait. | 1215 // Open a web page and wait. |
| 1253 ui_test_utils::NavigateToURL(browser(), url); | 1216 ui_test_utils::NavigateToURL(browser(), url); |
| 1254 | 1217 |
| 1255 // Download a file in a new tab and wait (via Javascript). | 1218 // Download a file in a new tab and wait (via Javascript). |
| 1256 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); | 1219 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); |
| 1257 DownloadAndWaitWithDisposition(browser(), | 1220 DownloadAndWaitWithDisposition(browser(), |
| 1258 GURL("javascript:openNew()"), | 1221 GURL("javascript:openNew()"), |
| 1259 CURRENT_TAB, | 1222 CURRENT_TAB, |
| 1260 EXPECT_NO_SELECT_DIALOG, | |
| 1261 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); | 1223 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); |
| 1262 | 1224 |
| 1263 // When the download finishes, we should have two tabs. | 1225 // When the download finishes, we should have two tabs. |
| 1264 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); | 1226 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); |
| 1265 EXPECT_EQ(2, browser()->tab_count()); | 1227 EXPECT_EQ(2, browser()->tab_count()); |
| 1266 | 1228 |
| 1267 CheckDownload(browser(), file, file); | 1229 CheckDownload(browser(), file, file); |
| 1268 } | 1230 } |
| 1269 | 1231 |
| 1270 // Open a web page in the current tab, open another tab via a Javascript call, | 1232 // Open a web page in the current tab, open another tab via a Javascript call, |
| (...skipping 20 matching lines...) Expand all Loading... |
| 1291 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); | 1253 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); |
| 1292 | 1254 |
| 1293 EXPECT_EQ(2, browser()->tab_count()); | 1255 EXPECT_EQ(2, browser()->tab_count()); |
| 1294 | 1256 |
| 1295 // Download a file and wait. | 1257 // Download a file and wait. |
| 1296 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); | 1258 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); |
| 1297 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); | 1259 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); |
| 1298 DownloadAndWaitWithDisposition(browser(), | 1260 DownloadAndWaitWithDisposition(browser(), |
| 1299 url, | 1261 url, |
| 1300 CURRENT_TAB, | 1262 CURRENT_TAB, |
| 1301 EXPECT_NO_SELECT_DIALOG, | |
| 1302 ui_test_utils::BROWSER_TEST_NONE); | 1263 ui_test_utils::BROWSER_TEST_NONE); |
| 1303 | 1264 |
| 1304 // When the download finishes, we should have two tabs. | 1265 // When the download finishes, we should have two tabs. |
| 1305 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); | 1266 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); |
| 1306 EXPECT_EQ(2, browser()->tab_count()); | 1267 EXPECT_EQ(2, browser()->tab_count()); |
| 1307 | 1268 |
| 1308 CheckDownload(browser(), file, file); | 1269 CheckDownload(browser(), file, file); |
| 1309 } | 1270 } |
| 1310 | 1271 |
| 1311 // Open a web page in the current tab, then download a file via Javascript, | 1272 // Open a web page in the current tab, then download a file via Javascript, |
| (...skipping 11 matching lines...) Expand all Loading... |
| 1323 | 1284 |
| 1324 // Open a web page and wait. | 1285 // Open a web page and wait. |
| 1325 ui_test_utils::NavigateToURL(browser(), url); | 1286 ui_test_utils::NavigateToURL(browser(), url); |
| 1326 | 1287 |
| 1327 // Download a file and wait. | 1288 // Download a file and wait. |
| 1328 // The file to download is "download-test1.lib". | 1289 // The file to download is "download-test1.lib". |
| 1329 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); | 1290 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); |
| 1330 DownloadAndWaitWithDisposition(browser(), | 1291 DownloadAndWaitWithDisposition(browser(), |
| 1331 GURL("javascript:openNew()"), | 1292 GURL("javascript:openNew()"), |
| 1332 CURRENT_TAB, | 1293 CURRENT_TAB, |
| 1333 EXPECT_NO_SELECT_DIALOG, | |
| 1334 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); | 1294 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); |
| 1335 | 1295 |
| 1336 // When the download finishes, we should still have one tab. | 1296 // When the download finishes, we should still have one tab. |
| 1337 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); | 1297 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); |
| 1338 EXPECT_EQ(1, browser()->tab_count()); | 1298 EXPECT_EQ(1, browser()->tab_count()); |
| 1339 | 1299 |
| 1340 CheckDownload(browser(), file, file); | 1300 CheckDownload(browser(), file, file); |
| 1341 } | 1301 } |
| 1342 | 1302 |
| 1343 // Open a web page in the current tab, then call Javascript via a button to | 1303 // Open a web page in the current tab, then call Javascript via a button to |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1357 ui_test_utils::NavigateToURL(browser(), url); | 1317 ui_test_utils::NavigateToURL(browser(), url); |
| 1358 | 1318 |
| 1359 // Download a file in a new tab and wait. The tab will automatically close | 1319 // Download a file in a new tab and wait. The tab will automatically close |
| 1360 // when the download begins. | 1320 // when the download begins. |
| 1361 // The file to download is "download-test1.lib". | 1321 // The file to download is "download-test1.lib". |
| 1362 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); | 1322 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); |
| 1363 DownloadAndWaitWithDisposition( | 1323 DownloadAndWaitWithDisposition( |
| 1364 browser(), | 1324 browser(), |
| 1365 GURL("javascript:document.getElementById('form').submit()"), | 1325 GURL("javascript:document.getElementById('form').submit()"), |
| 1366 CURRENT_TAB, | 1326 CURRENT_TAB, |
| 1367 EXPECT_NO_SELECT_DIALOG, | |
| 1368 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); | 1327 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); |
| 1369 | 1328 |
| 1370 // When the download finishes, we should still have one tab. | 1329 // When the download finishes, we should still have one tab. |
| 1371 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); | 1330 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); |
| 1372 EXPECT_EQ(1, browser()->tab_count()); | 1331 EXPECT_EQ(1, browser()->tab_count()); |
| 1373 | 1332 |
| 1374 CheckDownload(browser(), file, file); | 1333 CheckDownload(browser(), file, file); |
| 1375 } | 1334 } |
| 1376 | 1335 |
| 1377 // Download a file in a new window. | 1336 // Download a file in a new window. |
| 1378 // Verify that we have 2 windows, and the download shelf is not visible in the | 1337 // Verify that we have 2 windows, and the download shelf is not visible in the |
| 1379 // first window, but is visible in the second window. | 1338 // first window, but is visible in the second window. |
| 1380 // Close the new window. | 1339 // Close the new window. |
| 1381 // Verify that we have 1 window, and the download shelf is not visible. | 1340 // Verify that we have 1 window, and the download shelf is not visible. |
| 1382 // | 1341 // |
| 1383 // Regression test for http://crbug.com/44454 | 1342 // Regression test for http://crbug.com/44454 |
| 1384 IN_PROC_BROWSER_TEST_F(DownloadTest, NewWindow) { | 1343 IN_PROC_BROWSER_TEST_F(DownloadTest, NewWindow) { |
| 1385 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); | 1344 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); |
| 1386 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); | 1345 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); |
| 1387 #if !defined(OS_MACOSX) | 1346 #if !defined(OS_MACOSX) |
| 1388 // See below. | 1347 // See below. |
| 1389 Browser* first_browser = browser(); | 1348 Browser* first_browser = browser(); |
| 1390 #endif | 1349 #endif |
| 1391 | 1350 |
| 1392 // Download a file in a new window and wait. | 1351 // Download a file in a new window and wait. |
| 1393 DownloadAndWaitWithDisposition(browser(), | 1352 DownloadAndWaitWithDisposition(browser(), |
| 1394 url, | 1353 url, |
| 1395 NEW_WINDOW, | 1354 NEW_WINDOW, |
| 1396 EXPECT_NO_SELECT_DIALOG, | |
| 1397 ui_test_utils::BROWSER_TEST_NONE); | 1355 ui_test_utils::BROWSER_TEST_NONE); |
| 1398 | 1356 |
| 1399 // When the download finishes, the download shelf SHOULD NOT be visible in | 1357 // When the download finishes, the download shelf SHOULD NOT be visible in |
| 1400 // the first window. | 1358 // the first window. |
| 1401 ExpectWindowCountAfterDownload(2); | 1359 ExpectWindowCountAfterDownload(2); |
| 1402 EXPECT_EQ(1, browser()->tab_count()); | 1360 EXPECT_EQ(1, browser()->tab_count()); |
| 1403 // Download shelf should close. Download panel stays open on ChromeOS. | 1361 // Download shelf should close. Download panel stays open on ChromeOS. |
| 1404 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); | 1362 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); |
| 1405 | 1363 |
| 1406 // The download shelf SHOULD be visible in the second window. | 1364 // The download shelf SHOULD be visible in the second window. |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1456 string16(), &downloads); | 1414 string16(), &downloads); |
| 1457 ASSERT_EQ(1u, downloads.size()); | 1415 ASSERT_EQ(1u, downloads.size()); |
| 1458 ASSERT_EQ(DownloadItem::IN_PROGRESS, downloads[0]->GetState()); | 1416 ASSERT_EQ(DownloadItem::IN_PROGRESS, downloads[0]->GetState()); |
| 1459 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); | 1417 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); |
| 1460 DownloadItem* download1 = downloads[0]; // The only download. | 1418 DownloadItem* download1 = downloads[0]; // The only download. |
| 1461 | 1419 |
| 1462 // Start the second download and wait until it's done. | 1420 // Start the second download and wait until it's done. |
| 1463 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); | 1421 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); |
| 1464 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); | 1422 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); |
| 1465 // Download the file and wait. We do not expect the Select File dialog. | 1423 // Download the file and wait. We do not expect the Select File dialog. |
| 1466 DownloadAndWait(browser(), url, EXPECT_NO_SELECT_DIALOG); | 1424 DownloadAndWait(browser(), url); |
| 1467 | 1425 |
| 1468 // Should now have 2 items on the download shelf. | 1426 // Should now have 2 items on the download shelf. |
| 1469 downloads.clear(); | 1427 downloads.clear(); |
| 1470 DownloadManagerForBrowser(browser())->SearchDownloads( | 1428 DownloadManagerForBrowser(browser())->SearchDownloads( |
| 1471 string16(), &downloads); | 1429 string16(), &downloads); |
| 1472 ASSERT_EQ(2u, downloads.size()); | 1430 ASSERT_EQ(2u, downloads.size()); |
| 1473 // We don't know the order of the downloads. | 1431 // We don't know the order of the downloads. |
| 1474 DownloadItem* download2 = downloads[(download1 == downloads[0]) ? 1 : 0]; | 1432 DownloadItem* download2 = downloads[(download1 == downloads[0]) ? 1 : 0]; |
| 1475 | 1433 |
| 1476 ASSERT_EQ(DownloadItem::IN_PROGRESS, download1->GetState()); | 1434 ASSERT_EQ(DownloadItem::IN_PROGRESS, download1->GetState()); |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1561 | 1519 |
| 1562 // Confirm a download makes it into the history properly. | 1520 // Confirm a download makes it into the history properly. |
| 1563 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadHistoryCheck) { | 1521 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadHistoryCheck) { |
| 1564 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); | 1522 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); |
| 1565 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); | 1523 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); |
| 1566 FilePath origin_file(OriginFile(file)); | 1524 FilePath origin_file(OriginFile(file)); |
| 1567 int64 origin_size; | 1525 int64 origin_size; |
| 1568 file_util::GetFileSize(origin_file, &origin_size); | 1526 file_util::GetFileSize(origin_file, &origin_size); |
| 1569 | 1527 |
| 1570 // Download the file and wait. We do not expect the Select File dialog. | 1528 // Download the file and wait. We do not expect the Select File dialog. |
| 1571 DownloadAndWait(browser(), url, EXPECT_NO_SELECT_DIALOG); | 1529 DownloadAndWait(browser(), url); |
| 1572 | 1530 |
| 1573 // Get details of what downloads have just happened. | 1531 // Get details of what downloads have just happened. |
| 1574 std::vector<DownloadItem*> downloads; | 1532 std::vector<DownloadItem*> downloads; |
| 1575 GetDownloads(browser(), &downloads); | 1533 GetDownloads(browser(), &downloads); |
| 1576 ASSERT_EQ(1u, downloads.size()); | 1534 ASSERT_EQ(1u, downloads.size()); |
| 1577 int64 db_handle = downloads[0]->GetDbHandle(); | 1535 int64 db_handle = downloads[0]->GetDbHandle(); |
| 1578 | 1536 |
| 1579 // Check state. | 1537 // Check state. |
| 1580 EXPECT_EQ(1, browser()->tab_count()); | 1538 EXPECT_EQ(1, browser()->tab_count()); |
| 1581 CheckDownload(browser(), file, file); | 1539 CheckDownload(browser(), file, file); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 1597 | 1555 |
| 1598 // Test for crbug.com/14505. This tests that chrome:// urls are still functional | 1556 // Test for crbug.com/14505. This tests that chrome:// urls are still functional |
| 1599 // after download of a file while viewing another chrome://. | 1557 // after download of a file while viewing another chrome://. |
| 1600 IN_PROC_BROWSER_TEST_F(DownloadTest, ChromeURLAfterDownload) { | 1558 IN_PROC_BROWSER_TEST_F(DownloadTest, ChromeURLAfterDownload) { |
| 1601 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); | 1559 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); |
| 1602 GURL download_url(URLRequestMockHTTPJob::GetMockUrl(file)); | 1560 GURL download_url(URLRequestMockHTTPJob::GetMockUrl(file)); |
| 1603 GURL flags_url(chrome::kChromeUIFlagsURL); | 1561 GURL flags_url(chrome::kChromeUIFlagsURL); |
| 1604 GURL extensions_url(chrome::kChromeUIExtensionsFrameURL); | 1562 GURL extensions_url(chrome::kChromeUIExtensionsFrameURL); |
| 1605 | 1563 |
| 1606 ui_test_utils::NavigateToURL(browser(), flags_url); | 1564 ui_test_utils::NavigateToURL(browser(), flags_url); |
| 1607 DownloadAndWait(browser(), download_url, EXPECT_NO_SELECT_DIALOG); | 1565 DownloadAndWait(browser(), download_url); |
| 1608 ui_test_utils::NavigateToURL(browser(), extensions_url); | 1566 ui_test_utils::NavigateToURL(browser(), extensions_url); |
| 1609 WebContents* contents = chrome::GetActiveWebContents(browser()); | 1567 WebContents* contents = chrome::GetActiveWebContents(browser()); |
| 1610 ASSERT_TRUE(contents); | 1568 ASSERT_TRUE(contents); |
| 1611 bool webui_responded = false; | 1569 bool webui_responded = false; |
| 1612 EXPECT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( | 1570 EXPECT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( |
| 1613 contents->GetRenderViewHost(), | 1571 contents->GetRenderViewHost(), |
| 1614 L"", | 1572 L"", |
| 1615 L"window.domAutomationController.send(window.webui_responded_);", | 1573 L"window.domAutomationController.send(window.webui_responded_);", |
| 1616 &webui_responded)); | 1574 &webui_responded)); |
| 1617 EXPECT_TRUE(webui_responded); | 1575 EXPECT_TRUE(webui_responded); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 1630 ASSERT_TRUE(contents); | 1588 ASSERT_TRUE(contents); |
| 1631 bool result = false; | 1589 bool result = false; |
| 1632 EXPECT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( | 1590 EXPECT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( |
| 1633 contents->GetRenderViewHost(), | 1591 contents->GetRenderViewHost(), |
| 1634 L"", | 1592 L"", |
| 1635 L"window.onunload = function() { var do_nothing = 0; }; " | 1593 L"window.onunload = function() { var do_nothing = 0; }; " |
| 1636 L"window.domAutomationController.send(true);", | 1594 L"window.domAutomationController.send(true);", |
| 1637 &result)); | 1595 &result)); |
| 1638 EXPECT_TRUE(result); | 1596 EXPECT_TRUE(result); |
| 1639 | 1597 |
| 1640 DownloadAndWait(browser(), download_url, EXPECT_NO_SELECT_DIALOG); | 1598 DownloadAndWait(browser(), download_url); |
| 1641 | 1599 |
| 1642 ui_test_utils::WindowedNotificationObserver signal( | 1600 ui_test_utils::WindowedNotificationObserver signal( |
| 1643 chrome::NOTIFICATION_BROWSER_CLOSED, | 1601 chrome::NOTIFICATION_BROWSER_CLOSED, |
| 1644 content::Source<Browser>(browser())); | 1602 content::Source<Browser>(browser())); |
| 1645 chrome::CloseWindow(browser()); | 1603 chrome::CloseWindow(browser()); |
| 1646 signal.Wait(); | 1604 signal.Wait(); |
| 1647 } | 1605 } |
| 1648 | 1606 |
| 1649 // Test to make sure the 'download' attribute in anchor tag is respected. | 1607 // Test to make sure the 'download' attribute in anchor tag is respected. |
| 1650 IN_PROC_BROWSER_TEST_F(DownloadTest, AnchorDownloadTag) { | 1608 IN_PROC_BROWSER_TEST_F(DownloadTest, AnchorDownloadTag) { |
| (...skipping 21 matching lines...) Expand all Loading... |
| 1672 FilePath file(FILE_PATH_LITERAL("download-autoopen.txt")); | 1630 FilePath file(FILE_PATH_LITERAL("download-autoopen.txt")); |
| 1673 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); | 1631 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); |
| 1674 | 1632 |
| 1675 ASSERT_TRUE( | 1633 ASSERT_TRUE( |
| 1676 GetDownloadPrefs(browser())->EnableAutoOpenBasedOnExtension(file)); | 1634 GetDownloadPrefs(browser())->EnableAutoOpenBasedOnExtension(file)); |
| 1677 | 1635 |
| 1678 // Mock out external opening on all downloads until end of test. | 1636 // Mock out external opening on all downloads until end of test. |
| 1679 MockDownloadOpeningObserver observer( | 1637 MockDownloadOpeningObserver observer( |
| 1680 DownloadManagerForBrowser(browser())); | 1638 DownloadManagerForBrowser(browser())); |
| 1681 | 1639 |
| 1682 DownloadAndWait(browser(), url, EXPECT_NO_SELECT_DIALOG); | 1640 DownloadAndWait(browser(), url); |
| 1683 | 1641 |
| 1684 // Find the download and confirm it was opened. | 1642 // Find the download and confirm it was opened. |
| 1685 std::vector<DownloadItem*> downloads; | 1643 std::vector<DownloadItem*> downloads; |
| 1686 DownloadManagerForBrowser(browser())->SearchDownloads( | 1644 DownloadManagerForBrowser(browser())->SearchDownloads( |
| 1687 string16(), &downloads); | 1645 string16(), &downloads); |
| 1688 ASSERT_EQ(1u, downloads.size()); | 1646 ASSERT_EQ(1u, downloads.size()); |
| 1689 EXPECT_EQ(DownloadItem::COMPLETE, downloads[0]->GetState()); | 1647 EXPECT_EQ(DownloadItem::COMPLETE, downloads[0]->GetState()); |
| 1690 EXPECT_TRUE(downloads[0]->GetOpened()); | 1648 EXPECT_TRUE(downloads[0]->GetOpened()); |
| 1691 | 1649 |
| 1692 // As long as we're here, confirmed everything else is good. | 1650 // As long as we're here, confirmed everything else is good. |
| (...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1974 EXPECT_EQ(3, search_results[1]->GetDbHandle()); | 1932 EXPECT_EQ(3, search_results[1]->GetDbHandle()); |
| 1975 search_results.clear(); | 1933 search_results.clear(); |
| 1976 } | 1934 } |
| 1977 | 1935 |
| 1978 // Tests for download initiation functions. | 1936 // Tests for download initiation functions. |
| 1979 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadUrl) { | 1937 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadUrl) { |
| 1980 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); | 1938 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); |
| 1981 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); | 1939 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); |
| 1982 | 1940 |
| 1983 // DownloadUrl always prompts; return acceptance of whatever it prompts. | 1941 // DownloadUrl always prompts; return acceptance of whatever it prompts. |
| 1984 NullSelectFile(browser()); | 1942 EnableFileChooser(true); |
| 1985 | 1943 |
| 1986 WebContents* web_contents = chrome::GetActiveWebContents(browser()); | 1944 WebContents* web_contents = chrome::GetActiveWebContents(browser()); |
| 1987 ASSERT_TRUE(web_contents); | 1945 ASSERT_TRUE(web_contents); |
| 1988 | 1946 |
| 1989 DownloadTestObserver* observer( | 1947 DownloadTestObserver* observer( |
| 1990 new DownloadTestObserverTerminal( | 1948 new DownloadTestObserverTerminal( |
| 1991 DownloadManagerForBrowser(browser()), 1, | 1949 DownloadManagerForBrowser(browser()), 1, |
| 1992 false, // Ignore select file. | |
| 1993 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL)); | 1950 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL)); |
| 1994 content::DownloadSaveInfo save_info; | 1951 content::DownloadSaveInfo save_info; |
| 1995 save_info.prompt_for_save_location = true; | 1952 save_info.prompt_for_save_location = true; |
| 1996 scoped_ptr<DownloadUrlParameters> params( | 1953 scoped_ptr<DownloadUrlParameters> params( |
| 1997 DownloadUrlParameters::FromWebContents(web_contents, url, save_info)); | 1954 DownloadUrlParameters::FromWebContents(web_contents, url, save_info)); |
| 1998 DownloadManagerForBrowser(browser())->DownloadUrl(params.Pass()); | 1955 DownloadManagerForBrowser(browser())->DownloadUrl(params.Pass()); |
| 1999 observer->WaitForFinished(); | 1956 observer->WaitForFinished(); |
| 2000 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE)); | 1957 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE)); |
| 2001 CheckDownloadStates(1, DownloadItem::COMPLETE); | 1958 CheckDownloadStates(1, DownloadItem::COMPLETE); |
| 2002 EXPECT_TRUE(observer->select_file_dialog_seen()); | 1959 EXPECT_TRUE(DidShowFileChooser()); |
| 2003 | 1960 |
| 2004 // Check state. | 1961 // Check state. |
| 2005 EXPECT_EQ(1, browser()->tab_count()); | 1962 EXPECT_EQ(1, browser()->tab_count()); |
| 2006 ASSERT_TRUE(CheckDownload(browser(), file, file)); | 1963 ASSERT_TRUE(CheckDownload(browser(), file, file)); |
| 2007 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); | 1964 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); |
| 2008 } | 1965 } |
| 2009 | 1966 |
| 2010 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadUrlToPath) { | 1967 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadUrlToPath) { |
| 2011 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); | 1968 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); |
| 2012 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); | 1969 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 2034 target_file_full_path, | 1991 target_file_full_path, |
| 2035 OriginFile(file))); | 1992 OriginFile(file))); |
| 2036 | 1993 |
| 2037 // Temporary downloads won't be visible. | 1994 // Temporary downloads won't be visible. |
| 2038 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); | 1995 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); |
| 2039 } | 1996 } |
| 2040 | 1997 |
| 2041 IN_PROC_BROWSER_TEST_F(DownloadTest, SavePageNonHTMLViaGet) { | 1998 IN_PROC_BROWSER_TEST_F(DownloadTest, SavePageNonHTMLViaGet) { |
| 2042 // Do initial setup. | 1999 // Do initial setup. |
| 2043 ASSERT_TRUE(test_server()->Start()); | 2000 ASSERT_TRUE(test_server()->Start()); |
| 2044 NullSelectFile(browser()); | 2001 EnableFileChooser(true); |
| 2045 std::vector<DownloadItem*> download_items; | 2002 std::vector<DownloadItem*> download_items; |
| 2046 GetDownloads(browser(), &download_items); | 2003 GetDownloads(browser(), &download_items); |
| 2047 ASSERT_TRUE(download_items.empty()); | 2004 ASSERT_TRUE(download_items.empty()); |
| 2048 | 2005 |
| 2049 // Navigate to a non-HTML resource. The resource also has | 2006 // Navigate to a non-HTML resource. The resource also has |
| 2050 // Cache-Control: no-cache set, which normally requires revalidation | 2007 // Cache-Control: no-cache set, which normally requires revalidation |
| 2051 // each time. | 2008 // each time. |
| 2052 GURL url = test_server()->GetURL("files/downloads/image.jpg"); | 2009 GURL url = test_server()->GetURL("files/downloads/image.jpg"); |
| 2053 ASSERT_TRUE(url.is_valid()); | 2010 ASSERT_TRUE(url.is_valid()); |
| 2054 ui_test_utils::NavigateToURL(browser(), url); | 2011 ui_test_utils::NavigateToURL(browser(), url); |
| 2055 | 2012 |
| 2056 // Stop the test server, and then try to save the page. If cache validation | 2013 // Stop the test server, and then try to save the page. If cache validation |
| 2057 // is not bypassed then this will fail since the server is no longer | 2014 // is not bypassed then this will fail since the server is no longer |
| 2058 // reachable. | 2015 // reachable. |
| 2059 ASSERT_TRUE(test_server()->Stop()); | 2016 ASSERT_TRUE(test_server()->Stop()); |
| 2060 scoped_ptr<DownloadTestObserver> waiter( | 2017 scoped_ptr<DownloadTestObserver> waiter( |
| 2061 new DownloadTestObserverTerminal( | 2018 new DownloadTestObserverTerminal( |
| 2062 DownloadManagerForBrowser(browser()), 1, | 2019 DownloadManagerForBrowser(browser()), 1, |
| 2063 false, DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL)); | 2020 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL)); |
| 2064 chrome::SavePage(browser()); | 2021 chrome::SavePage(browser()); |
| 2065 waiter->WaitForFinished(); | 2022 waiter->WaitForFinished(); |
| 2066 EXPECT_EQ(1u, waiter->NumDownloadsSeenInState(DownloadItem::COMPLETE)); | 2023 EXPECT_EQ(1u, waiter->NumDownloadsSeenInState(DownloadItem::COMPLETE)); |
| 2067 CheckDownloadStates(1, DownloadItem::COMPLETE); | 2024 CheckDownloadStates(1, DownloadItem::COMPLETE); |
| 2068 | 2025 |
| 2069 // Validate that the correct file was downloaded. | 2026 // Validate that the correct file was downloaded. |
| 2070 GetDownloads(browser(), &download_items); | 2027 GetDownloads(browser(), &download_items); |
| 2071 EXPECT_TRUE(waiter->select_file_dialog_seen()); | 2028 EXPECT_TRUE(DidShowFileChooser()); |
| 2072 ASSERT_EQ(1u, download_items.size()); | 2029 ASSERT_EQ(1u, download_items.size()); |
| 2073 ASSERT_EQ(url, download_items[0]->GetOriginalUrl()); | 2030 ASSERT_EQ(url, download_items[0]->GetOriginalUrl()); |
| 2074 | 2031 |
| 2075 // Try to download it via a context menu. | 2032 // Try to download it via a context menu. |
| 2076 scoped_ptr<DownloadTestObserver> waiter_context_menu( | 2033 scoped_ptr<DownloadTestObserver> waiter_context_menu( |
| 2077 new DownloadTestObserverTerminal( | 2034 new DownloadTestObserverTerminal( |
| 2078 DownloadManagerForBrowser(browser()), 1, | 2035 DownloadManagerForBrowser(browser()), 1, |
| 2079 false, DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL)); | 2036 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL)); |
| 2080 content::ContextMenuParams context_menu_params; | 2037 content::ContextMenuParams context_menu_params; |
| 2081 context_menu_params.media_type = WebKit::WebContextMenuData::MediaTypeImage; | 2038 context_menu_params.media_type = WebKit::WebContextMenuData::MediaTypeImage; |
| 2082 context_menu_params.src_url = url; | 2039 context_menu_params.src_url = url; |
| 2083 context_menu_params.page_url = url; | 2040 context_menu_params.page_url = url; |
| 2084 TestRenderViewContextMenu menu(chrome::GetActiveWebContents(browser()), | 2041 TestRenderViewContextMenu menu(chrome::GetActiveWebContents(browser()), |
| 2085 context_menu_params); | 2042 context_menu_params); |
| 2086 menu.Init(); | 2043 menu.Init(); |
| 2087 menu.ExecuteCommand(IDC_CONTENT_CONTEXT_SAVEIMAGEAS); | 2044 menu.ExecuteCommand(IDC_CONTENT_CONTEXT_SAVEIMAGEAS); |
| 2088 waiter_context_menu->WaitForFinished(); | 2045 waiter_context_menu->WaitForFinished(); |
| 2089 EXPECT_EQ( | 2046 EXPECT_EQ( |
| 2090 1u, waiter_context_menu->NumDownloadsSeenInState(DownloadItem::COMPLETE)); | 2047 1u, waiter_context_menu->NumDownloadsSeenInState(DownloadItem::COMPLETE)); |
| 2091 CheckDownloadStates(2, DownloadItem::COMPLETE); | 2048 CheckDownloadStates(2, DownloadItem::COMPLETE); |
| 2092 | 2049 |
| 2093 // Validate that the correct file was downloaded via the context menu. | 2050 // Validate that the correct file was downloaded via the context menu. |
| 2094 download_items.clear(); | 2051 download_items.clear(); |
| 2095 GetDownloads(browser(), &download_items); | 2052 GetDownloads(browser(), &download_items); |
| 2096 EXPECT_TRUE(waiter_context_menu->select_file_dialog_seen()); | 2053 EXPECT_TRUE(DidShowFileChooser()); |
| 2097 ASSERT_EQ(2u, download_items.size()); | 2054 ASSERT_EQ(2u, download_items.size()); |
| 2098 ASSERT_EQ(url, download_items[0]->GetOriginalUrl()); | 2055 ASSERT_EQ(url, download_items[0]->GetOriginalUrl()); |
| 2099 ASSERT_EQ(url, download_items[1]->GetOriginalUrl()); | 2056 ASSERT_EQ(url, download_items[1]->GetOriginalUrl()); |
| 2100 } | 2057 } |
| 2101 | 2058 |
| 2102 IN_PROC_BROWSER_TEST_F(DownloadTest, SavePageNonHTMLViaPost) { | 2059 IN_PROC_BROWSER_TEST_F(DownloadTest, SavePageNonHTMLViaPost) { |
| 2103 // Do initial setup. | 2060 // Do initial setup. |
| 2104 ASSERT_TRUE(test_server()->Start()); | 2061 ASSERT_TRUE(test_server()->Start()); |
| 2105 NullSelectFile(browser()); | 2062 EnableFileChooser(true); |
| 2106 std::vector<DownloadItem*> download_items; | 2063 std::vector<DownloadItem*> download_items; |
| 2107 GetDownloads(browser(), &download_items); | 2064 GetDownloads(browser(), &download_items); |
| 2108 ASSERT_TRUE(download_items.empty()); | 2065 ASSERT_TRUE(download_items.empty()); |
| 2109 | 2066 |
| 2110 // Navigate to a form page. | 2067 // Navigate to a form page. |
| 2111 GURL form_url = test_server()->GetURL( | 2068 GURL form_url = test_server()->GetURL( |
| 2112 "files/downloads/form_page_to_post.html"); | 2069 "files/downloads/form_page_to_post.html"); |
| 2113 ASSERT_TRUE(form_url.is_valid()); | 2070 ASSERT_TRUE(form_url.is_valid()); |
| 2114 ui_test_utils::NavigateToURL(browser(), form_url); | 2071 ui_test_utils::NavigateToURL(browser(), form_url); |
| 2115 | 2072 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 2132 EXPECT_EQ(jpeg_url, web_contents->GetURL()); | 2089 EXPECT_EQ(jpeg_url, web_contents->GetURL()); |
| 2133 | 2090 |
| 2134 // Stop the test server, and then try to save the page. If cache validation | 2091 // Stop the test server, and then try to save the page. If cache validation |
| 2135 // is not bypassed then this will fail since the server is no longer | 2092 // is not bypassed then this will fail since the server is no longer |
| 2136 // reachable. This will also fail if it tries to be retrieved via "GET" | 2093 // reachable. This will also fail if it tries to be retrieved via "GET" |
| 2137 // rather than "POST". | 2094 // rather than "POST". |
| 2138 ASSERT_TRUE(test_server()->Stop()); | 2095 ASSERT_TRUE(test_server()->Stop()); |
| 2139 scoped_ptr<DownloadTestObserver> waiter( | 2096 scoped_ptr<DownloadTestObserver> waiter( |
| 2140 new DownloadTestObserverTerminal( | 2097 new DownloadTestObserverTerminal( |
| 2141 DownloadManagerForBrowser(browser()), 1, | 2098 DownloadManagerForBrowser(browser()), 1, |
| 2142 false, DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL)); | 2099 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL)); |
| 2143 chrome::SavePage(browser()); | 2100 chrome::SavePage(browser()); |
| 2144 waiter->WaitForFinished(); | 2101 waiter->WaitForFinished(); |
| 2145 EXPECT_EQ(1u, waiter->NumDownloadsSeenInState(DownloadItem::COMPLETE)); | 2102 EXPECT_EQ(1u, waiter->NumDownloadsSeenInState(DownloadItem::COMPLETE)); |
| 2146 CheckDownloadStates(1, DownloadItem::COMPLETE); | 2103 CheckDownloadStates(1, DownloadItem::COMPLETE); |
| 2147 | 2104 |
| 2148 // Validate that the correct file was downloaded. | 2105 // Validate that the correct file was downloaded. |
| 2149 GetDownloads(browser(), &download_items); | 2106 GetDownloads(browser(), &download_items); |
| 2150 EXPECT_TRUE(waiter->select_file_dialog_seen()); | 2107 EXPECT_TRUE(DidShowFileChooser()); |
| 2151 ASSERT_EQ(1u, download_items.size()); | 2108 ASSERT_EQ(1u, download_items.size()); |
| 2152 ASSERT_EQ(jpeg_url, download_items[0]->GetOriginalUrl()); | 2109 ASSERT_EQ(jpeg_url, download_items[0]->GetOriginalUrl()); |
| 2153 | 2110 |
| 2154 // Try to download it via a context menu. | 2111 // Try to download it via a context menu. |
| 2155 scoped_ptr<DownloadTestObserver> waiter_context_menu( | 2112 scoped_ptr<DownloadTestObserver> waiter_context_menu( |
| 2156 new DownloadTestObserverTerminal( | 2113 new DownloadTestObserverTerminal( |
| 2157 DownloadManagerForBrowser(browser()), 1, | 2114 DownloadManagerForBrowser(browser()), 1, |
| 2158 false, DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL)); | 2115 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL)); |
| 2159 content::ContextMenuParams context_menu_params; | 2116 content::ContextMenuParams context_menu_params; |
| 2160 context_menu_params.media_type = WebKit::WebContextMenuData::MediaTypeImage; | 2117 context_menu_params.media_type = WebKit::WebContextMenuData::MediaTypeImage; |
| 2161 context_menu_params.src_url = jpeg_url; | 2118 context_menu_params.src_url = jpeg_url; |
| 2162 context_menu_params.page_url = jpeg_url; | 2119 context_menu_params.page_url = jpeg_url; |
| 2163 TestRenderViewContextMenu menu(web_contents, context_menu_params); | 2120 TestRenderViewContextMenu menu(web_contents, context_menu_params); |
| 2164 menu.Init(); | 2121 menu.Init(); |
| 2165 menu.ExecuteCommand(IDC_CONTENT_CONTEXT_SAVEIMAGEAS); | 2122 menu.ExecuteCommand(IDC_CONTENT_CONTEXT_SAVEIMAGEAS); |
| 2166 waiter_context_menu->WaitForFinished(); | 2123 waiter_context_menu->WaitForFinished(); |
| 2167 EXPECT_EQ( | 2124 EXPECT_EQ( |
| 2168 1u, waiter_context_menu->NumDownloadsSeenInState(DownloadItem::COMPLETE)); | 2125 1u, waiter_context_menu->NumDownloadsSeenInState(DownloadItem::COMPLETE)); |
| 2169 CheckDownloadStates(2, DownloadItem::COMPLETE); | 2126 CheckDownloadStates(2, DownloadItem::COMPLETE); |
| 2170 | 2127 |
| 2171 // Validate that the correct file was downloaded via the context menu. | 2128 // Validate that the correct file was downloaded via the context menu. |
| 2172 download_items.clear(); | 2129 download_items.clear(); |
| 2173 GetDownloads(browser(), &download_items); | 2130 GetDownloads(browser(), &download_items); |
| 2174 EXPECT_TRUE(waiter_context_menu->select_file_dialog_seen()); | 2131 EXPECT_TRUE(DidShowFileChooser()); |
| 2175 ASSERT_EQ(2u, download_items.size()); | 2132 ASSERT_EQ(2u, download_items.size()); |
| 2176 ASSERT_EQ(jpeg_url, download_items[0]->GetOriginalUrl()); | 2133 ASSERT_EQ(jpeg_url, download_items[0]->GetOriginalUrl()); |
| 2177 ASSERT_EQ(jpeg_url, download_items[1]->GetOriginalUrl()); | 2134 ASSERT_EQ(jpeg_url, download_items[1]->GetOriginalUrl()); |
| 2178 } | 2135 } |
| 2179 | 2136 |
| 2180 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadErrorsServer) { | 2137 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadErrorsServer) { |
| 2181 DownloadInfo download_info[] = { | 2138 DownloadInfo download_info[] = { |
| 2182 { // Normal navigated download. | 2139 { // Normal navigated download. |
| 2183 "a_zip_file.zip", | 2140 "a_zip_file.zip", |
| 2184 DOWNLOAD_NAVIGATE, | 2141 DOWNLOAD_NAVIGATE, |
| (...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2453 ui_test_utils::NavigateToURL(browser(), url); | 2410 ui_test_utils::NavigateToURL(browser(), url); |
| 2454 observer->WaitForFinished(); | 2411 observer->WaitForFinished(); |
| 2455 | 2412 |
| 2456 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE)); | 2413 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE)); |
| 2457 EXPECT_EQ(1u, observer->NumDangerousDownloadsSeen()); | 2414 EXPECT_EQ(1u, observer->NumDangerousDownloadsSeen()); |
| 2458 } | 2415 } |
| 2459 | 2416 |
| 2460 IN_PROC_BROWSER_TEST_F(DownloadTest, LoadURLExternallyReferrerPolicy) { | 2417 IN_PROC_BROWSER_TEST_F(DownloadTest, LoadURLExternallyReferrerPolicy) { |
| 2461 // Do initial setup. | 2418 // Do initial setup. |
| 2462 ASSERT_TRUE(test_server()->Start()); | 2419 ASSERT_TRUE(test_server()->Start()); |
| 2463 NullSelectFile(browser()); | 2420 EnableFileChooser(true); |
| 2464 std::vector<DownloadItem*> download_items; | 2421 std::vector<DownloadItem*> download_items; |
| 2465 GetDownloads(browser(), &download_items); | 2422 GetDownloads(browser(), &download_items); |
| 2466 ASSERT_TRUE(download_items.empty()); | 2423 ASSERT_TRUE(download_items.empty()); |
| 2467 | 2424 |
| 2468 // Navigate to a page with a referrer policy and a link on it. The link points | 2425 // Navigate to a page with a referrer policy and a link on it. The link points |
| 2469 // to testserver's /echoheader. | 2426 // to testserver's /echoheader. |
| 2470 GURL url = test_server()->GetURL("files/downloads/referrer_policy.html"); | 2427 GURL url = test_server()->GetURL("files/downloads/referrer_policy.html"); |
| 2471 ASSERT_TRUE(url.is_valid()); | 2428 ASSERT_TRUE(url.is_valid()); |
| 2472 ui_test_utils::NavigateToURL(browser(), url); | 2429 ui_test_utils::NavigateToURL(browser(), url); |
| 2473 | 2430 |
| 2474 scoped_ptr<DownloadTestObserver> waiter( | 2431 scoped_ptr<DownloadTestObserver> waiter( |
| 2475 new DownloadTestObserverTerminal( | 2432 new DownloadTestObserverTerminal( |
| 2476 DownloadManagerForBrowser(browser()), 1, | 2433 DownloadManagerForBrowser(browser()), 1, |
| 2477 false, DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL)); | 2434 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL)); |
| 2478 | 2435 |
| 2479 // Click on the link with the alt key pressed. This will download the link | 2436 // Click on the link with the alt key pressed. This will download the link |
| 2480 // target. | 2437 // target. |
| 2481 WebContents* tab = chrome::GetActiveWebContents(browser()); | 2438 WebContents* tab = chrome::GetActiveWebContents(browser()); |
| 2482 WebKit::WebMouseEvent mouse_event; | 2439 WebKit::WebMouseEvent mouse_event; |
| 2483 mouse_event.type = WebKit::WebInputEvent::MouseDown; | 2440 mouse_event.type = WebKit::WebInputEvent::MouseDown; |
| 2484 mouse_event.button = WebKit::WebMouseEvent::ButtonLeft; | 2441 mouse_event.button = WebKit::WebMouseEvent::ButtonLeft; |
| 2485 mouse_event.x = 15; | 2442 mouse_event.x = 15; |
| 2486 mouse_event.y = 15; | 2443 mouse_event.y = 15; |
| 2487 mouse_event.clickCount = 1; | 2444 mouse_event.clickCount = 1; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 2498 GetDownloads(browser(), &download_items); | 2455 GetDownloads(browser(), &download_items); |
| 2499 ASSERT_EQ(1u, download_items.size()); | 2456 ASSERT_EQ(1u, download_items.size()); |
| 2500 ASSERT_EQ(test_server()->GetURL("echoheader?Referer"), | 2457 ASSERT_EQ(test_server()->GetURL("echoheader?Referer"), |
| 2501 download_items[0]->GetOriginalUrl()); | 2458 download_items[0]->GetOriginalUrl()); |
| 2502 | 2459 |
| 2503 // Check that the file contains the expected referrer. | 2460 // Check that the file contains the expected referrer. |
| 2504 FilePath file(download_items[0]->GetFullPath()); | 2461 FilePath file(download_items[0]->GetFullPath()); |
| 2505 std::string expected_contents = test_server()->GetURL("").spec(); | 2462 std::string expected_contents = test_server()->GetURL("").spec(); |
| 2506 ASSERT_TRUE(VerifyFile(file, expected_contents, expected_contents.length())); | 2463 ASSERT_TRUE(VerifyFile(file, expected_contents, expected_contents.length())); |
| 2507 } | 2464 } |
| OLD | NEW |