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 "base/bind.h" | 5 #include "base/bind.h" |
| 6 #include "base/bind_helpers.h" | 6 #include "base/bind_helpers.h" |
| 7 #include "base/file_path.h" | 7 #include "base/file_path.h" |
| 8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
| 9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
| 10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
| (...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 382 | 382 |
| 383 DownloadPrefs* GetDownloadPrefs(Browser* browser) { | 383 DownloadPrefs* GetDownloadPrefs(Browser* browser) { |
| 384 return DownloadPrefs::FromDownloadManager( | 384 return DownloadPrefs::FromDownloadManager( |
| 385 DownloadManagerForBrowser(browser)); | 385 DownloadManagerForBrowser(browser)); |
| 386 } | 386 } |
| 387 | 387 |
| 388 FilePath GetDownloadDirectory(Browser* browser) { | 388 FilePath GetDownloadDirectory(Browser* browser) { |
| 389 return GetDownloadPrefs(browser)->download_path(); | 389 return GetDownloadPrefs(browser)->download_path(); |
| 390 } | 390 } |
| 391 | 391 |
| 392 // Create a DownloadTestObserver that will wait for the | 392 // Create a DownloadTestObserverTerminal that will wait for the |
| 393 // specified number of downloads to finish. | 393 // specified number of downloads to finish. |
| 394 DownloadTestObserver* CreateWaiter(Browser* browser, int num_downloads) { | 394 DownloadTestObserverTerminal* CreateWaiter(Browser* browser, |
| 395 int num_downloads) { | |
| 395 DownloadManager* download_manager = DownloadManagerForBrowser(browser); | 396 DownloadManager* download_manager = DownloadManagerForBrowser(browser); |
| 396 return new DownloadTestObserver( | 397 return new DownloadTestObserverTerminal( |
| 397 download_manager, num_downloads, | 398 download_manager, num_downloads, |
| 398 DownloadItem::COMPLETE, // Really done | |
| 399 true, // Bail on select file | 399 true, // Bail on select file |
| 400 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL); | 400 DownloadTestObserverTerminal::ON_DANGEROUS_DOWNLOAD_FAIL); |
| 401 } | 401 } |
| 402 | 402 |
| 403 // Create a DownloadTestObserver that will wait for the | 403 // Create a DownloadTestObserverInProgress that will wait for the |
| 404 // specified number of downloads to start. | 404 // specified number of downloads to start. |
| 405 DownloadTestObserver* CreateInProgressWaiter(Browser* browser, | 405 DownloadTestObserverInProgress* CreateInProgressWaiter(Browser* browser, |
| 406 int num_downloads) { | 406 int num_downloads) { |
| 407 DownloadManager* download_manager = DownloadManagerForBrowser(browser); | 407 DownloadManager* download_manager = DownloadManagerForBrowser(browser); |
| 408 return new DownloadTestObserver( | 408 return new DownloadTestObserverInProgress( |
| 409 download_manager, num_downloads, | 409 download_manager, num_downloads); |
| 410 DownloadItem::IN_PROGRESS, // Has started | |
| 411 true, // Bail on select file | |
| 412 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL); | |
| 413 } | 410 } |
| 414 | 411 |
| 415 // Create a DownloadTestObserver that will wait for the | 412 // Create a DownloadTestObserverTerminal that will wait for the |
| 416 // specified number of downloads to finish, or for | 413 // specified number of downloads to finish, or for |
| 417 // a dangerous download warning to be shown. | 414 // a dangerous download warning to be shown. |
| 418 DownloadTestObserver* DangerousInstallWaiter( | 415 DownloadTestObserverTerminal* DangerousInstallWaiter( |
| 419 Browser* browser, | 416 Browser* browser, |
| 420 int num_downloads, | 417 int num_downloads, |
| 421 DownloadItem::DownloadState final_state, | 418 DownloadTestObserverTerminal::DangerousDownloadAction |
| 422 DownloadTestObserver::DangerousDownloadAction dangerous_download_action) { | 419 dangerous_download_action) { |
| 423 DownloadManager* download_manager = DownloadManagerForBrowser(browser); | 420 DownloadManager* download_manager = DownloadManagerForBrowser(browser); |
| 424 return new DownloadTestObserver( | 421 return new DownloadTestObserverTerminal( |
| 425 download_manager, num_downloads, | 422 download_manager, num_downloads, |
| 426 final_state, | |
| 427 true, // Bail on select file | 423 true, // Bail on select file |
| 428 dangerous_download_action); | 424 dangerous_download_action); |
| 429 } | 425 } |
| 430 | 426 |
| 431 // Download |url|, then wait for the download to finish. | 427 // Download |url|, then wait for the download to finish. |
| 432 // |disposition| indicates where the navigation occurs (current tab, new | 428 // |disposition| indicates where the navigation occurs (current tab, new |
| 433 // foreground tab, etc). | 429 // foreground tab, etc). |
| 434 // |expectation| indicates whether or not a Select File dialog should be | 430 // |expectation| indicates whether or not a Select File dialog should be |
| 435 // open when the download is finished, or if we don't care. | 431 // open when the download is finished, or if we don't care. |
| 436 // If the dialog appears, the routine exits. The only effect |expectation| | 432 // If the dialog appears, the routine exits. The only effect |expectation| |
| 437 // has is whether or not the test succeeds. | 433 // has is whether or not the test succeeds. |
| 438 // |browser_test_flags| indicate what to wait for, and is an OR of 0 or more | 434 // |browser_test_flags| indicate what to wait for, and is an OR of 0 or more |
| 439 // values in the ui_test_utils::BrowserTestWaitFlags enum. | 435 // values in the ui_test_utils::BrowserTestWaitFlags enum. |
| 440 void DownloadAndWaitWithDisposition(Browser* browser, | 436 void DownloadAndWaitWithDisposition(Browser* browser, |
| 441 const GURL& url, | 437 const GURL& url, |
| 442 WindowOpenDisposition disposition, | 438 WindowOpenDisposition disposition, |
| 443 SelectExpectation expectation, | 439 SelectExpectation expectation, |
| 444 int browser_test_flags) { | 440 int browser_test_flags) { |
| 445 // Setup notification, navigate, and block. | 441 // Setup notification, navigate, and block. |
| 446 scoped_ptr<DownloadTestObserver> observer(CreateWaiter(browser, 1)); | 442 scoped_ptr<DownloadTestObserverTerminal> observer(CreateWaiter(browser, 1)); |
| 447 // This call will block until the condition specified by | 443 // This call will block until the condition specified by |
| 448 // |browser_test_flags|, but will not wait for the download to finish. | 444 // |browser_test_flags|, but will not wait for the download to finish. |
| 449 ui_test_utils::NavigateToURLWithDisposition(browser, | 445 ui_test_utils::NavigateToURLWithDisposition(browser, |
| 450 url, | 446 url, |
| 451 disposition, | 447 disposition, |
| 452 browser_test_flags); | 448 browser_test_flags); |
| 453 // Waits for the download to complete. | 449 // Waits for the download to complete. |
| 454 observer->WaitForFinished(); | 450 observer->WaitForFinished(); |
| 455 | 451 |
| 456 // If specified, check the state of the select file dialog. | 452 // If specified, check the state of the select file dialog. |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 535 // |expected_title_finished| need to be checked. | 531 // |expected_title_finished| need to be checked. |
| 536 FilePath filename; | 532 FilePath filename; |
| 537 net::FileURLToFilePath(url, &filename); | 533 net::FileURLToFilePath(url, &filename); |
| 538 string16 expected_title_in_progress( | 534 string16 expected_title_in_progress( |
| 539 ASCIIToUTF16(partial_indication) + filename.LossyDisplayName()); | 535 ASCIIToUTF16(partial_indication) + filename.LossyDisplayName()); |
| 540 string16 expected_title_finished( | 536 string16 expected_title_finished( |
| 541 ASCIIToUTF16(total_indication) + filename.LossyDisplayName()); | 537 ASCIIToUTF16(total_indication) + filename.LossyDisplayName()); |
| 542 | 538 |
| 543 // Download a partial web page in a background tab and wait. | 539 // Download a partial web page in a background tab and wait. |
| 544 // The mock system will not complete until it gets a special URL. | 540 // The mock system will not complete until it gets a special URL. |
| 545 scoped_ptr<DownloadTestObserver> observer(CreateWaiter(browser, 1)); | 541 scoped_ptr<DownloadTestObserverTerminal> observer(CreateWaiter(browser, 1)); |
| 546 ui_test_utils::NavigateToURL(browser, url); | 542 ui_test_utils::NavigateToURL(browser, url); |
| 547 | 543 |
| 548 // TODO(ahendrickson): check download status text before downloading. | 544 // TODO(ahendrickson): check download status text before downloading. |
| 549 // Need to: | 545 // Need to: |
| 550 // - Add a member function to the |DownloadShelf| interface class, that | 546 // - Add a member function to the |DownloadShelf| interface class, that |
| 551 // indicates how many members it has. | 547 // indicates how many members it has. |
| 552 // - Add a member function to |DownloadShelf| to get the status text | 548 // - Add a member function to |DownloadShelf| to get the status text |
| 553 // of a given member (for example, via the name in |DownloadItemView|'s | 549 // of a given member (for example, via the name in |DownloadItemView|'s |
| 554 // GetAccessibleState() member function), by index. | 550 // GetAccessibleState() member function), by index. |
| 555 // - Iterate over browser->window()->GetDownloadShelf()'s members | 551 // - Iterate over browser->window()->GetDownloadShelf()'s members |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 686 std::vector<DownloadItem*> download_items; | 682 std::vector<DownloadItem*> download_items; |
| 687 GetDownloads(browser(), &download_items); | 683 GetDownloads(browser(), &download_items); |
| 688 ASSERT_TRUE(download_items.empty()); | 684 ASSERT_TRUE(download_items.empty()); |
| 689 | 685 |
| 690 std::string server_path = "files/downloads/"; | 686 std::string server_path = "files/downloads/"; |
| 691 server_path += download_info.url_name; | 687 server_path += download_info.url_name; |
| 692 GURL url = test_server()->GetURL(server_path); | 688 GURL url = test_server()->GetURL(server_path); |
| 693 ASSERT_TRUE(url.is_valid()); | 689 ASSERT_TRUE(url.is_valid()); |
| 694 | 690 |
| 695 DownloadManager* download_manager = DownloadManagerForBrowser(browser()); | 691 DownloadManager* download_manager = DownloadManagerForBrowser(browser()); |
| 696 scoped_ptr<DownloadTestObserver> observer( | 692 scoped_ptr<DownloadTestObserverTerminal> observer( |
| 697 new DownloadTestObserver( | 693 new DownloadTestObserverTerminal( |
| 698 download_manager, | 694 download_manager, |
| 699 1, | 695 1, |
|
Randy Smith (Not in Mondays)
2012/03/07 21:39:16
Shouldn't all the observers where the state has be
ahendrickson
2012/03/08 17:36:07
Done for all the non-IN_PROGRESS observers.
| |
| 700 download_info.reason == DOWNLOAD_INTERRUPT_REASON_NONE ? | |
| 701 DownloadItem::COMPLETE : // Really done | |
| 702 DownloadItem::INTERRUPTED, | |
| 703 true, // Bail on select file | 696 true, // Bail on select file |
| 704 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL)); | 697 DownloadTestObserverTerminal::ON_DANGEROUS_DOWNLOAD_FAIL)); |
| 705 | 698 |
| 706 if (download_info.download_method == DOWNLOAD_DIRECT) { | 699 if (download_info.download_method == DOWNLOAD_DIRECT) { |
| 707 // Go directly to download. | 700 // Go directly to download. |
| 708 WebContents* web_contents = browser()->GetSelectedWebContents(); | 701 WebContents* web_contents = browser()->GetSelectedWebContents(); |
| 709 ASSERT_TRUE(web_contents); | 702 ASSERT_TRUE(web_contents); |
| 710 DownloadSaveInfo save_info; | 703 DownloadSaveInfo save_info; |
| 711 save_info.prompt_for_save_location = false; | 704 save_info.prompt_for_save_location = false; |
| 712 | 705 |
| 713 DownloadManagerForBrowser(browser())->DownloadUrl( | 706 DownloadManagerForBrowser(browser())->DownloadUrl( |
| 714 url, GURL(""), "", false, -1, save_info, web_contents); | 707 url, GURL(""), "", false, -1, save_info, web_contents); |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 791 // downloads preferences settings. | 784 // downloads preferences settings. |
| 792 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadMimeTypeSelect) { | 785 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadMimeTypeSelect) { |
| 793 ASSERT_TRUE(InitialSetup(true)); | 786 ASSERT_TRUE(InitialSetup(true)); |
| 794 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); | 787 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); |
| 795 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); | 788 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); |
| 796 | 789 |
| 797 NullSelectFile(browser()); | 790 NullSelectFile(browser()); |
| 798 | 791 |
| 799 // Download the file and wait. We expect the Select File dialog to appear | 792 // Download the file and wait. We expect the Select File dialog to appear |
| 800 // due to the MIME type, but we still wait until the download completes. | 793 // due to the MIME type, but we still wait until the download completes. |
| 801 scoped_ptr<DownloadTestObserver> observer( | 794 scoped_ptr<DownloadTestObserverTerminal> observer( |
| 802 new DownloadTestObserver( | 795 new DownloadTestObserverTerminal( |
| 803 DownloadManagerForBrowser(browser()), | 796 DownloadManagerForBrowser(browser()), |
| 804 1, | 797 1, |
| 805 DownloadItem::COMPLETE, // Really done | |
| 806 false, // Continue on select file. | 798 false, // Continue on select file. |
| 807 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL)); | 799 DownloadTestObserverTerminal::ON_DANGEROUS_DOWNLOAD_FAIL)); |
| 808 ui_test_utils::NavigateToURLWithDisposition( | 800 ui_test_utils::NavigateToURLWithDisposition( |
| 809 browser(), url, CURRENT_TAB, | 801 browser(), url, CURRENT_TAB, |
| 810 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); | 802 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
| 811 observer->WaitForFinished(); | 803 observer->WaitForFinished(); |
| 812 EXPECT_TRUE(observer->select_file_dialog_seen()); | 804 EXPECT_TRUE(observer->select_file_dialog_seen()); |
| 813 | 805 |
| 814 // Check state. | 806 // Check state. |
| 815 EXPECT_EQ(1, browser()->tab_count()); | 807 EXPECT_EQ(1, browser()->tab_count()); |
| 816 CheckDownload(browser(), file, file); | 808 CheckDownload(browser(), file, file); |
| 817 CheckDownloadUI(browser(), true, true, file); | 809 CheckDownloadUI(browser(), true, true, file); |
| (...skipping 461 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1279 } | 1271 } |
| 1280 | 1272 |
| 1281 // Check that downloading multiple (in this case, 2) files does not result in | 1273 // Check that downloading multiple (in this case, 2) files does not result in |
| 1282 // corrupted files. | 1274 // corrupted files. |
| 1283 IN_PROC_BROWSER_TEST_F(DownloadTest, MultiDownload) { | 1275 IN_PROC_BROWSER_TEST_F(DownloadTest, MultiDownload) { |
| 1284 ASSERT_TRUE(InitialSetup(false)); | 1276 ASSERT_TRUE(InitialSetup(false)); |
| 1285 EXPECT_EQ(1, browser()->tab_count()); | 1277 EXPECT_EQ(1, browser()->tab_count()); |
| 1286 | 1278 |
| 1287 // Create a download, wait until it's started, and confirm | 1279 // Create a download, wait until it's started, and confirm |
| 1288 // we're in the expected state. | 1280 // we're in the expected state. |
| 1289 scoped_ptr<DownloadTestObserver> observer1( | 1281 scoped_ptr<DownloadTestObserverInProgress> observer1( |
| 1290 CreateInProgressWaiter(browser(), 1)); | 1282 CreateInProgressWaiter(browser(), 1)); |
| 1291 ui_test_utils::NavigateToURL( | 1283 ui_test_utils::NavigateToURL( |
| 1292 browser(), GURL(URLRequestSlowDownloadJob::kUnknownSizeUrl)); | 1284 browser(), GURL(URLRequestSlowDownloadJob::kUnknownSizeUrl)); |
| 1293 observer1->WaitForFinished(); | 1285 observer1->WaitForFinished(); |
| 1294 | 1286 |
| 1295 std::vector<DownloadItem*> downloads; | 1287 std::vector<DownloadItem*> downloads; |
| 1296 browser()->profile()->GetDownloadManager()->SearchDownloads( | 1288 browser()->profile()->GetDownloadManager()->SearchDownloads( |
| 1297 string16(), &downloads); | 1289 string16(), &downloads); |
| 1298 ASSERT_EQ(1u, downloads.size()); | 1290 ASSERT_EQ(1u, downloads.size()); |
| 1299 ASSERT_EQ(DownloadItem::IN_PROGRESS, downloads[0]->GetState()); | 1291 ASSERT_EQ(DownloadItem::IN_PROGRESS, downloads[0]->GetState()); |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 1314 // We don't know the order of the downloads. | 1306 // We don't know the order of the downloads. |
| 1315 DownloadItem* download2 = downloads[(download1 == downloads[0]) ? 1 : 0]; | 1307 DownloadItem* download2 = downloads[(download1 == downloads[0]) ? 1 : 0]; |
| 1316 | 1308 |
| 1317 ASSERT_EQ(DownloadItem::IN_PROGRESS, download1->GetState()); | 1309 ASSERT_EQ(DownloadItem::IN_PROGRESS, download1->GetState()); |
| 1318 ASSERT_EQ(DownloadItem::COMPLETE, download2->GetState()); | 1310 ASSERT_EQ(DownloadItem::COMPLETE, download2->GetState()); |
| 1319 // The download shelf should be open. | 1311 // The download shelf should be open. |
| 1320 CheckDownloadUI(browser(), true, true, FilePath()); | 1312 CheckDownloadUI(browser(), true, true, FilePath()); |
| 1321 | 1313 |
| 1322 // Allow the first request to finish. We do this by loading a third URL | 1314 // Allow the first request to finish. We do this by loading a third URL |
| 1323 // in a separate tab. | 1315 // in a separate tab. |
| 1324 scoped_ptr<DownloadTestObserver> observer2(CreateWaiter(browser(), 1)); | 1316 scoped_ptr<DownloadTestObserverTerminal> |
| 1317 observer2(CreateWaiter(browser(), 1)); | |
| 1325 GURL finish_url(URLRequestSlowDownloadJob::kFinishDownloadUrl); | 1318 GURL finish_url(URLRequestSlowDownloadJob::kFinishDownloadUrl); |
| 1326 ui_test_utils::NavigateToURLWithDisposition( | 1319 ui_test_utils::NavigateToURLWithDisposition( |
| 1327 browser(), | 1320 browser(), |
| 1328 finish_url, | 1321 finish_url, |
| 1329 NEW_FOREGROUND_TAB, | 1322 NEW_FOREGROUND_TAB, |
| 1330 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); | 1323 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
| 1331 observer2->WaitForFinished(); // Wait for the third request. | 1324 observer2->WaitForFinished(); // Wait for the third request. |
| 1332 | 1325 |
| 1333 // Get the important info from other threads and check it. | 1326 // Get the important info from other threads and check it. |
| 1334 scoped_refptr<CancelTestDataCollector> info(new CancelTestDataCollector()); | 1327 scoped_refptr<CancelTestDataCollector> info(new CancelTestDataCollector()); |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 1349 | 1342 |
| 1350 FilePath file2(download2->GetFullPath()); | 1343 FilePath file2(download2->GetFullPath()); |
| 1351 ASSERT_TRUE(file_util::ContentsEqual(OriginFile(file), file2)); | 1344 ASSERT_TRUE(file_util::ContentsEqual(OriginFile(file), file2)); |
| 1352 } | 1345 } |
| 1353 | 1346 |
| 1354 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadCancelled) { | 1347 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadCancelled) { |
| 1355 ASSERT_TRUE(InitialSetup(false)); | 1348 ASSERT_TRUE(InitialSetup(false)); |
| 1356 EXPECT_EQ(1, browser()->tab_count()); | 1349 EXPECT_EQ(1, browser()->tab_count()); |
| 1357 | 1350 |
| 1358 // TODO(rdsmith): Fragile code warning! The code below relies on the | 1351 // TODO(rdsmith): Fragile code warning! The code below relies on the |
| 1359 // DownloadTestObserver only finishing when the new download has reached | 1352 // DownloadTestObserverInProgress only finishing when the new download |
| 1360 // the state of being entered into the history and being user-visible | 1353 // has reached the state of being entered into the history and being |
| 1361 // (that's what's required for the Remove to be valid and for the | 1354 // user-visible (that's what's required for the Remove to be valid and |
| 1362 // download shelf to be visible). By the pure semantics of | 1355 // for the download shelf to be visible). By the pure semantics of |
| 1363 // DownloadTestObserver, that's not guaranteed; DownloadItems are created | 1356 // DownloadTestObserverInProgress, that's not guaranteed; DownloadItems |
| 1364 // in the IN_PROGRESS state and made known to the DownloadManager | 1357 // are created in the IN_PROGRESS state and made known to the DownloadManager |
| 1365 // immediately, so any ModelChanged event on the DownloadManager after | 1358 // immediately, so any ModelChanged event on the DownloadManager after |
| 1366 // navigation would allow the observer to return. However, the only | 1359 // navigation would allow the observer to return. However, the only |
| 1367 // ModelChanged() event the code will currently fire is in | 1360 // ModelChanged() event the code will currently fire is in |
| 1368 // OnCreateDownloadEntryComplete, at which point the download item will | 1361 // OnCreateDownloadEntryComplete, at which point the download item will |
| 1369 // be in the state we need. | 1362 // be in the state we need. |
| 1370 // The right way to fix this is to create finer grained states on the | 1363 // The right way to fix this is to create finer grained states on the |
| 1371 // DownloadItem, and wait for the state that indicates the item has been | 1364 // DownloadItem, and wait for the state that indicates the item has been |
| 1372 // entered in the history and made visible in the UI. | 1365 // entered in the history and made visible in the UI. |
| 1373 | 1366 |
| 1374 // Create a download, wait until it's started, and confirm | 1367 // Create a download, wait until it's started, and confirm |
| 1375 // we're in the expected state. | 1368 // we're in the expected state. |
| 1376 scoped_ptr<DownloadTestObserver> observer( | 1369 scoped_ptr<DownloadTestObserverInProgress> observer( |
| 1377 CreateInProgressWaiter(browser(), 1)); | 1370 CreateInProgressWaiter(browser(), 1)); |
| 1378 ui_test_utils::NavigateToURL( | 1371 ui_test_utils::NavigateToURL( |
| 1379 browser(), GURL(URLRequestSlowDownloadJob::kUnknownSizeUrl)); | 1372 browser(), GURL(URLRequestSlowDownloadJob::kUnknownSizeUrl)); |
| 1380 observer->WaitForFinished(); | 1373 observer->WaitForFinished(); |
| 1381 | 1374 |
| 1382 std::vector<DownloadItem*> downloads; | 1375 std::vector<DownloadItem*> downloads; |
| 1383 DownloadManagerForBrowser(browser())->SearchDownloads( | 1376 DownloadManagerForBrowser(browser())->SearchDownloads( |
| 1384 string16(), &downloads); | 1377 string16(), &downloads); |
| 1385 ASSERT_EQ(1u, downloads.size()); | 1378 ASSERT_EQ(1u, downloads.size()); |
| 1386 ASSERT_EQ(DownloadItem::IN_PROGRESS, downloads[0]->GetState()); | 1379 ASSERT_EQ(DownloadItem::IN_PROGRESS, downloads[0]->GetState()); |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1497 } | 1490 } |
| 1498 | 1491 |
| 1499 // Test to make sure the 'download' attribute in anchor tag is respected. | 1492 // Test to make sure the 'download' attribute in anchor tag is respected. |
| 1500 IN_PROC_BROWSER_TEST_F(DownloadTest, AnchorDownloadTag) { | 1493 IN_PROC_BROWSER_TEST_F(DownloadTest, AnchorDownloadTag) { |
| 1501 ASSERT_TRUE(InitialSetup(false)); | 1494 ASSERT_TRUE(InitialSetup(false)); |
| 1502 FilePath file(FILE_PATH_LITERAL("download-anchor-attrib.html")); | 1495 FilePath file(FILE_PATH_LITERAL("download-anchor-attrib.html")); |
| 1503 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); | 1496 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); |
| 1504 | 1497 |
| 1505 // Create a download, wait until it's complete, and confirm | 1498 // Create a download, wait until it's complete, and confirm |
| 1506 // we're in the expected state. | 1499 // we're in the expected state. |
| 1507 scoped_ptr<DownloadTestObserver> observer(CreateWaiter(browser(), 1)); | 1500 scoped_ptr<DownloadTestObserverTerminal> observer(CreateWaiter(browser(), 1)); |
| 1508 ui_test_utils::NavigateToURL(browser(), url); | 1501 ui_test_utils::NavigateToURL(browser(), url); |
| 1509 observer->WaitForFinished(); | 1502 observer->WaitForFinished(); |
| 1510 | 1503 |
| 1511 // Confirm the downloaded data exists. | 1504 // Confirm the downloaded data exists. |
| 1512 FilePath downloaded_file = GetDownloadDirectory(browser()); | 1505 FilePath downloaded_file = GetDownloadDirectory(browser()); |
| 1513 downloaded_file = downloaded_file.Append(FILE_PATH_LITERAL("a_red_dot.png")); | 1506 downloaded_file = downloaded_file.Append(FILE_PATH_LITERAL("a_red_dot.png")); |
| 1514 EXPECT_TRUE(file_util::PathExists(downloaded_file)); | 1507 EXPECT_TRUE(file_util::PathExists(downloaded_file)); |
| 1515 } | 1508 } |
| 1516 | 1509 |
| 1517 // Test to make sure auto-open works. | 1510 // Test to make sure auto-open works. |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 1543 // Download shelf should close. Download panel stays open on ChromeOS. | 1536 // Download shelf should close. Download panel stays open on ChromeOS. |
| 1544 CheckDownloadUI(browser(), false, true, FilePath()); | 1537 CheckDownloadUI(browser(), false, true, FilePath()); |
| 1545 } | 1538 } |
| 1546 | 1539 |
| 1547 // Download an extension. Expect a dangerous download warning. | 1540 // Download an extension. Expect a dangerous download warning. |
| 1548 // Deny the download. | 1541 // Deny the download. |
| 1549 IN_PROC_BROWSER_TEST_F(DownloadTest, CrxDenyInstall) { | 1542 IN_PROC_BROWSER_TEST_F(DownloadTest, CrxDenyInstall) { |
| 1550 ASSERT_TRUE(InitialSetup(false)); | 1543 ASSERT_TRUE(InitialSetup(false)); |
| 1551 GURL extension_url(URLRequestMockHTTPJob::GetMockUrl(kGoodCrxPath)); | 1544 GURL extension_url(URLRequestMockHTTPJob::GetMockUrl(kGoodCrxPath)); |
| 1552 | 1545 |
| 1553 scoped_ptr<DownloadTestObserver> observer( | 1546 scoped_ptr<DownloadTestObserverTerminal> observer( |
| 1554 DangerousInstallWaiter( | 1547 DangerousInstallWaiter( |
| 1555 browser(), 1, DownloadItem::CANCELLED, | 1548 browser(), 1, |
| 1556 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_DENY)); | 1549 DownloadTestObserverTerminal::ON_DANGEROUS_DOWNLOAD_DENY)); |
| 1557 ui_test_utils::NavigateToURL(browser(), extension_url); | 1550 ui_test_utils::NavigateToURL(browser(), extension_url); |
| 1558 | 1551 |
| 1559 observer->WaitForFinished(); | 1552 observer->WaitForFinished(); |
| 1560 EXPECT_EQ(1u, observer->NumDangerousDownloadsSeen()); | 1553 EXPECT_EQ(1u, observer->NumDangerousDownloadsSeen()); |
| 1561 | 1554 |
| 1562 // Download shelf should close. Download panel stays open on ChromeOS. | 1555 // Download shelf should close. Download panel stays open on ChromeOS. |
| 1563 CheckDownloadUI(browser(), false, true, FilePath()); | 1556 CheckDownloadUI(browser(), false, true, FilePath()); |
| 1564 | 1557 |
| 1565 // Check that the CRX is not installed. | 1558 // Check that the CRX is not installed. |
| 1566 ExtensionService* extension_service = | 1559 ExtensionService* extension_service = |
| 1567 browser()->profile()->GetExtensionService(); | 1560 browser()->profile()->GetExtensionService(); |
| 1568 ASSERT_FALSE(extension_service->GetExtensionById(kGoodCrxId, false)); | 1561 ASSERT_FALSE(extension_service->GetExtensionById(kGoodCrxId, false)); |
| 1569 } | 1562 } |
| 1570 | 1563 |
| 1571 // Download an extension. Expect a dangerous download warning. | 1564 // Download an extension. Expect a dangerous download warning. |
| 1572 // Allow the download, deny the install. | 1565 // Allow the download, deny the install. |
| 1573 IN_PROC_BROWSER_TEST_F(DownloadTest, CrxInstallDenysPermissions) { | 1566 IN_PROC_BROWSER_TEST_F(DownloadTest, CrxInstallDenysPermissions) { |
| 1574 ASSERT_TRUE(InitialSetup(false)); | 1567 ASSERT_TRUE(InitialSetup(false)); |
| 1575 GURL extension_url(URLRequestMockHTTPJob::GetMockUrl(kGoodCrxPath)); | 1568 GURL extension_url(URLRequestMockHTTPJob::GetMockUrl(kGoodCrxPath)); |
| 1576 | 1569 |
| 1577 // Install a mock install UI that simulates a user denying permission to | 1570 // Install a mock install UI that simulates a user denying permission to |
| 1578 // finish the install. | 1571 // finish the install. |
| 1579 download_crx_util::SetMockInstallUIForTesting( | 1572 download_crx_util::SetMockInstallUIForTesting( |
| 1580 new MockAbortExtensionInstallUI()); | 1573 new MockAbortExtensionInstallUI()); |
| 1581 | 1574 |
| 1582 scoped_ptr<DownloadTestObserver> observer( | 1575 scoped_ptr<DownloadTestObserverTerminal> observer( |
| 1583 DangerousInstallWaiter( | 1576 DangerousInstallWaiter( |
| 1584 browser(), 1, DownloadItem::COMPLETE, | 1577 browser(), 1, |
| 1585 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_ACCEPT)); | 1578 DownloadTestObserverTerminal::ON_DANGEROUS_DOWNLOAD_ACCEPT)); |
| 1586 ui_test_utils::NavigateToURL(browser(), extension_url); | 1579 ui_test_utils::NavigateToURL(browser(), extension_url); |
| 1587 | 1580 |
| 1588 observer->WaitForFinished(); | 1581 observer->WaitForFinished(); |
| 1589 EXPECT_EQ(1u, observer->NumDangerousDownloadsSeen()); | 1582 EXPECT_EQ(1u, observer->NumDangerousDownloadsSeen()); |
| 1590 | 1583 |
| 1591 // Download shelf should close. Download panel stays open on ChromeOS. | 1584 // Download shelf should close. Download panel stays open on ChromeOS. |
| 1592 CheckDownloadUI(browser(), false, true, FilePath()); | 1585 CheckDownloadUI(browser(), false, true, FilePath()); |
| 1593 | 1586 |
| 1594 // Check that the extension was not installed. | 1587 // Check that the extension was not installed. |
| 1595 ExtensionService* extension_service = | 1588 ExtensionService* extension_service = |
| 1596 browser()->profile()->GetExtensionService(); | 1589 browser()->profile()->GetExtensionService(); |
| 1597 ASSERT_FALSE(extension_service->GetExtensionById(kGoodCrxId, false)); | 1590 ASSERT_FALSE(extension_service->GetExtensionById(kGoodCrxId, false)); |
| 1598 } | 1591 } |
| 1599 | 1592 |
| 1600 // Download an extension. Expect a dangerous download warning. | 1593 // Download an extension. Expect a dangerous download warning. |
| 1601 // Allow the download, and the install. | 1594 // Allow the download, and the install. |
| 1602 IN_PROC_BROWSER_TEST_F(DownloadTest, CrxInstallAcceptPermissions) { | 1595 IN_PROC_BROWSER_TEST_F(DownloadTest, CrxInstallAcceptPermissions) { |
| 1603 ASSERT_TRUE(InitialSetup(false)); | 1596 ASSERT_TRUE(InitialSetup(false)); |
| 1604 GURL extension_url(URLRequestMockHTTPJob::GetMockUrl(kGoodCrxPath)); | 1597 GURL extension_url(URLRequestMockHTTPJob::GetMockUrl(kGoodCrxPath)); |
| 1605 | 1598 |
| 1606 // Install a mock install UI that simulates a user allowing permission to | 1599 // Install a mock install UI that simulates a user allowing permission to |
| 1607 // finish the install. | 1600 // finish the install. |
| 1608 download_crx_util::SetMockInstallUIForTesting( | 1601 download_crx_util::SetMockInstallUIForTesting( |
| 1609 new MockAutoConfirmExtensionInstallUI(browser()->profile())); | 1602 new MockAutoConfirmExtensionInstallUI(browser()->profile())); |
| 1610 | 1603 |
| 1611 scoped_ptr<DownloadTestObserver> observer( | 1604 scoped_ptr<DownloadTestObserverTerminal> observer( |
| 1612 DangerousInstallWaiter( | 1605 DangerousInstallWaiter( |
| 1613 browser(), 1, DownloadItem::COMPLETE, | 1606 browser(), 1, |
| 1614 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_ACCEPT)); | 1607 DownloadTestObserverTerminal::ON_DANGEROUS_DOWNLOAD_ACCEPT)); |
| 1615 ui_test_utils::NavigateToURL(browser(), extension_url); | 1608 ui_test_utils::NavigateToURL(browser(), extension_url); |
| 1616 | 1609 |
| 1617 observer->WaitForFinished(); | 1610 observer->WaitForFinished(); |
| 1618 EXPECT_EQ(1u, observer->NumDangerousDownloadsSeen()); | 1611 EXPECT_EQ(1u, observer->NumDangerousDownloadsSeen()); |
| 1619 | 1612 |
| 1620 // Download shelf should close. Download panel stays open on ChromeOS. | 1613 // Download shelf should close. Download panel stays open on ChromeOS. |
| 1621 CheckDownloadUI(browser(), false, true, FilePath()); | 1614 CheckDownloadUI(browser(), false, true, FilePath()); |
| 1622 | 1615 |
| 1623 // Check that the extension was installed. | 1616 // Check that the extension was installed. |
| 1624 ExtensionService* extension_service = | 1617 ExtensionService* extension_service = |
| 1625 browser()->profile()->GetExtensionService(); | 1618 browser()->profile()->GetExtensionService(); |
| 1626 ASSERT_TRUE(extension_service->GetExtensionById(kGoodCrxId, false)); | 1619 ASSERT_TRUE(extension_service->GetExtensionById(kGoodCrxId, false)); |
| 1627 } | 1620 } |
| 1628 | 1621 |
| 1629 // Test installing a CRX that fails integrity checks. | 1622 // Test installing a CRX that fails integrity checks. |
| 1630 IN_PROC_BROWSER_TEST_F(DownloadTest, CrxInvalid) { | 1623 IN_PROC_BROWSER_TEST_F(DownloadTest, CrxInvalid) { |
| 1631 ASSERT_TRUE(InitialSetup(false)); | 1624 ASSERT_TRUE(InitialSetup(false)); |
| 1632 FilePath file(FILE_PATH_LITERAL("extensions/bad_signature.crx")); | 1625 FilePath file(FILE_PATH_LITERAL("extensions/bad_signature.crx")); |
| 1633 GURL extension_url(URLRequestMockHTTPJob::GetMockUrl(file)); | 1626 GURL extension_url(URLRequestMockHTTPJob::GetMockUrl(file)); |
| 1634 | 1627 |
| 1635 // Install a mock install UI that simulates a user allowing permission to | 1628 // Install a mock install UI that simulates a user allowing permission to |
| 1636 // finish the install, and dismisses any error message. We check that the | 1629 // finish the install, and dismisses any error message. We check that the |
| 1637 // install failed below. | 1630 // install failed below. |
| 1638 download_crx_util::SetMockInstallUIForTesting( | 1631 download_crx_util::SetMockInstallUIForTesting( |
| 1639 new MockAutoConfirmExtensionInstallUI(browser()->profile())); | 1632 new MockAutoConfirmExtensionInstallUI(browser()->profile())); |
| 1640 | 1633 |
| 1641 scoped_ptr<DownloadTestObserver> observer( | 1634 scoped_ptr<DownloadTestObserverTerminal> observer( |
| 1642 DangerousInstallWaiter( | 1635 DangerousInstallWaiter( |
| 1643 browser(), 1, DownloadItem::COMPLETE, | 1636 browser(), 1, |
| 1644 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_ACCEPT)); | 1637 DownloadTestObserverTerminal::ON_DANGEROUS_DOWNLOAD_ACCEPT)); |
| 1645 ui_test_utils::NavigateToURL(browser(), extension_url); | 1638 ui_test_utils::NavigateToURL(browser(), extension_url); |
| 1646 | 1639 |
| 1647 observer->WaitForFinished(); | 1640 observer->WaitForFinished(); |
| 1648 | 1641 |
| 1649 // Check that the extension was not installed. | 1642 // Check that the extension was not installed. |
| 1650 ExtensionService* extension_service = | 1643 ExtensionService* extension_service = |
| 1651 browser()->profile()->GetExtensionService(); | 1644 browser()->profile()->GetExtensionService(); |
| 1652 ASSERT_FALSE(extension_service->GetExtensionById(kGoodCrxId, false)); | 1645 ASSERT_FALSE(extension_service->GetExtensionById(kGoodCrxId, false)); |
| 1653 } | 1646 } |
| 1654 | 1647 |
| 1655 // Install a large (100kb) theme. | 1648 // Install a large (100kb) theme. |
| 1656 IN_PROC_BROWSER_TEST_F(DownloadTest, CrxLargeTheme) { | 1649 IN_PROC_BROWSER_TEST_F(DownloadTest, CrxLargeTheme) { |
| 1657 ASSERT_TRUE(InitialSetup(false)); | 1650 ASSERT_TRUE(InitialSetup(false)); |
| 1658 GURL extension_url(URLRequestMockHTTPJob::GetMockUrl(kLargeThemePath)); | 1651 GURL extension_url(URLRequestMockHTTPJob::GetMockUrl(kLargeThemePath)); |
| 1659 | 1652 |
| 1660 // Install a mock install UI that simulates a user allowing permission to | 1653 // Install a mock install UI that simulates a user allowing permission to |
| 1661 // finish the install. | 1654 // finish the install. |
| 1662 download_crx_util::SetMockInstallUIForTesting( | 1655 download_crx_util::SetMockInstallUIForTesting( |
| 1663 new MockAutoConfirmExtensionInstallUI(browser()->profile())); | 1656 new MockAutoConfirmExtensionInstallUI(browser()->profile())); |
| 1664 | 1657 |
| 1665 scoped_ptr<DownloadTestObserver> observer( | 1658 scoped_ptr<DownloadTestObserverTerminal> observer( |
| 1666 DangerousInstallWaiter( | 1659 DangerousInstallWaiter( |
| 1667 browser(), 1, DownloadItem::COMPLETE, | 1660 browser(), 1, |
| 1668 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_ACCEPT)); | 1661 DownloadTestObserverTerminal::ON_DANGEROUS_DOWNLOAD_ACCEPT)); |
| 1669 ui_test_utils::NavigateToURL(browser(), extension_url); | 1662 ui_test_utils::NavigateToURL(browser(), extension_url); |
| 1670 | 1663 |
| 1671 observer->WaitForFinished(); | 1664 observer->WaitForFinished(); |
| 1672 EXPECT_EQ(1u, observer->NumDangerousDownloadsSeen()); | 1665 EXPECT_EQ(1u, observer->NumDangerousDownloadsSeen()); |
| 1673 | 1666 |
| 1674 // Download shelf should close. Download panel stays open on ChromeOS. | 1667 // Download shelf should close. Download panel stays open on ChromeOS. |
| 1675 CheckDownloadUI(browser(), false, true, FilePath()); | 1668 CheckDownloadUI(browser(), false, true, FilePath()); |
| 1676 | 1669 |
| 1677 // Check that the extension was installed. | 1670 // Check that the extension was installed. |
| 1678 ExtensionService* extension_service = | 1671 ExtensionService* extension_service = |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1817 ASSERT_TRUE(InitialSetup(false)); | 1810 ASSERT_TRUE(InitialSetup(false)); |
| 1818 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); | 1811 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); |
| 1819 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); | 1812 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); |
| 1820 | 1813 |
| 1821 // DownloadUrl always prompts; return acceptance of whatever it prompts. | 1814 // DownloadUrl always prompts; return acceptance of whatever it prompts. |
| 1822 NullSelectFile(browser()); | 1815 NullSelectFile(browser()); |
| 1823 | 1816 |
| 1824 WebContents* web_contents = browser()->GetSelectedWebContents(); | 1817 WebContents* web_contents = browser()->GetSelectedWebContents(); |
| 1825 ASSERT_TRUE(web_contents); | 1818 ASSERT_TRUE(web_contents); |
| 1826 | 1819 |
| 1827 DownloadTestObserver* observer( | 1820 DownloadTestObserverTerminal* observer( |
| 1828 new DownloadTestObserver( | 1821 new DownloadTestObserverTerminal( |
| 1829 DownloadManagerForBrowser(browser()), 1, | 1822 DownloadManagerForBrowser(browser()), 1, |
| 1830 DownloadItem::COMPLETE, // Really done | 1823 false, // Ignore select file. |
| 1831 false, // Ignore select file. | 1824 DownloadTestObserverTerminal::ON_DANGEROUS_DOWNLOAD_FAIL)); |
| 1832 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL)); | |
| 1833 DownloadSaveInfo save_info; | 1825 DownloadSaveInfo save_info; |
| 1834 save_info.prompt_for_save_location = true; | 1826 save_info.prompt_for_save_location = true; |
| 1835 DownloadManagerForBrowser(browser())->DownloadUrl( | 1827 DownloadManagerForBrowser(browser())->DownloadUrl( |
| 1836 url, GURL(""), "", false, -1, save_info, web_contents); | 1828 url, GURL(""), "", false, -1, save_info, web_contents); |
| 1837 observer->WaitForFinished(); | 1829 observer->WaitForFinished(); |
| 1838 EXPECT_TRUE(observer->select_file_dialog_seen()); | 1830 EXPECT_TRUE(observer->select_file_dialog_seen()); |
| 1839 | 1831 |
| 1840 // Check state. | 1832 // Check state. |
| 1841 EXPECT_EQ(1, browser()->tab_count()); | 1833 EXPECT_EQ(1, browser()->tab_count()); |
| 1842 ASSERT_TRUE(CheckDownload(browser(), file, file)); | 1834 ASSERT_TRUE(CheckDownload(browser(), file, file)); |
| 1843 CheckDownloadUI(browser(), true, true, file); | 1835 CheckDownloadUI(browser(), true, true, file); |
| 1844 } | 1836 } |
| 1845 | 1837 |
| 1846 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadUrlToPath) { | 1838 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadUrlToPath) { |
| 1847 ASSERT_TRUE(InitialSetup(false)); | 1839 ASSERT_TRUE(InitialSetup(false)); |
| 1848 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); | 1840 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); |
| 1849 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); | 1841 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); |
| 1850 | 1842 |
| 1851 WebContents* web_contents = browser()->GetSelectedWebContents(); | 1843 WebContents* web_contents = browser()->GetSelectedWebContents(); |
| 1852 ASSERT_TRUE(web_contents); | 1844 ASSERT_TRUE(web_contents); |
| 1853 | 1845 |
| 1854 ScopedTempDir other_directory; | 1846 ScopedTempDir other_directory; |
| 1855 ASSERT_TRUE(other_directory.CreateUniqueTempDir()); | 1847 ASSERT_TRUE(other_directory.CreateUniqueTempDir()); |
| 1856 FilePath target_file_full_path | 1848 FilePath target_file_full_path |
| 1857 = other_directory.path().Append(file.BaseName()); | 1849 = other_directory.path().Append(file.BaseName()); |
| 1858 DownloadSaveInfo save_info; | 1850 DownloadSaveInfo save_info; |
| 1859 save_info.file_path = target_file_full_path; | 1851 save_info.file_path = target_file_full_path; |
| 1860 | 1852 |
| 1861 DownloadTestObserver* observer(CreateWaiter(browser(), 1)); | 1853 DownloadTestObserverTerminal* observer(CreateWaiter(browser(), 1)); |
| 1862 DownloadManagerForBrowser(browser())->DownloadUrl( | 1854 DownloadManagerForBrowser(browser())->DownloadUrl( |
| 1863 url, GURL(""), "", false, -1, save_info, web_contents); | 1855 url, GURL(""), "", false, -1, save_info, web_contents); |
| 1864 observer->WaitForFinished(); | 1856 observer->WaitForFinished(); |
| 1865 | 1857 |
| 1866 // Check state. | 1858 // Check state. |
| 1867 EXPECT_EQ(1, browser()->tab_count()); | 1859 EXPECT_EQ(1, browser()->tab_count()); |
| 1868 ASSERT_TRUE(CheckDownloadFullPaths(browser(), | 1860 ASSERT_TRUE(CheckDownloadFullPaths(browser(), |
| 1869 target_file_full_path, | 1861 target_file_full_path, |
| 1870 OriginFile(file))); | 1862 OriginFile(file))); |
| 1871 | 1863 |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 1886 // Cache-Control: no-cache set, which normally requires revalidation | 1878 // Cache-Control: no-cache set, which normally requires revalidation |
| 1887 // each time. | 1879 // each time. |
| 1888 GURL url = test_server()->GetURL("files/downloads/image.jpg"); | 1880 GURL url = test_server()->GetURL("files/downloads/image.jpg"); |
| 1889 ASSERT_TRUE(url.is_valid()); | 1881 ASSERT_TRUE(url.is_valid()); |
| 1890 ui_test_utils::NavigateToURL(browser(), url); | 1882 ui_test_utils::NavigateToURL(browser(), url); |
| 1891 | 1883 |
| 1892 // Stop the test server, and then try to save the page. If cache validation | 1884 // Stop the test server, and then try to save the page. If cache validation |
| 1893 // is not bypassed then this will fail since the server is no longer | 1885 // is not bypassed then this will fail since the server is no longer |
| 1894 // reachable. | 1886 // reachable. |
| 1895 ASSERT_TRUE(test_server()->Stop()); | 1887 ASSERT_TRUE(test_server()->Stop()); |
| 1896 scoped_ptr<DownloadTestObserver> waiter( | 1888 scoped_ptr<DownloadTestObserverTerminal> waiter( |
| 1897 new DownloadTestObserver( | 1889 new DownloadTestObserverTerminal( |
| 1898 DownloadManagerForBrowser(browser()), 1, DownloadItem::COMPLETE, | 1890 DownloadManagerForBrowser(browser()), 1, |
| 1899 false, DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL)); | 1891 false, DownloadTestObserverTerminal::ON_DANGEROUS_DOWNLOAD_FAIL)); |
| 1900 browser()->SavePage(); | 1892 browser()->SavePage(); |
| 1901 waiter->WaitForFinished(); | 1893 waiter->WaitForFinished(); |
| 1902 | 1894 |
| 1903 // Validate that the correct file was downloaded. | 1895 // Validate that the correct file was downloaded. |
| 1904 GetDownloads(browser(), &download_items); | 1896 GetDownloads(browser(), &download_items); |
| 1905 EXPECT_TRUE(waiter->select_file_dialog_seen()); | 1897 EXPECT_TRUE(waiter->select_file_dialog_seen()); |
| 1906 ASSERT_EQ(1u, download_items.size()); | 1898 ASSERT_EQ(1u, download_items.size()); |
| 1907 ASSERT_EQ(url, download_items[0]->GetOriginalUrl()); | 1899 ASSERT_EQ(url, download_items[0]->GetOriginalUrl()); |
| 1900 EXPECT_EQ(DownloadItem::COMPLETE, download_items[0]->GetState()); | |
| 1908 | 1901 |
| 1909 // Try to download it via a context menu. | 1902 // Try to download it via a context menu. |
| 1910 scoped_ptr<DownloadTestObserver> waiter_context_menu( | 1903 scoped_ptr<DownloadTestObserverTerminal> waiter_context_menu( |
| 1911 new DownloadTestObserver( | 1904 new DownloadTestObserverTerminal( |
| 1912 DownloadManagerForBrowser(browser()), 1, DownloadItem::COMPLETE, | 1905 DownloadManagerForBrowser(browser()), 1, |
| 1913 false, DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL)); | 1906 false, DownloadTestObserverTerminal::ON_DANGEROUS_DOWNLOAD_FAIL)); |
| 1914 content::ContextMenuParams context_menu_params; | 1907 content::ContextMenuParams context_menu_params; |
| 1915 context_menu_params.media_type = WebKit::WebContextMenuData::MediaTypeImage; | 1908 context_menu_params.media_type = WebKit::WebContextMenuData::MediaTypeImage; |
| 1916 context_menu_params.src_url = url; | 1909 context_menu_params.src_url = url; |
| 1917 context_menu_params.page_url = url; | 1910 context_menu_params.page_url = url; |
| 1918 TestRenderViewContextMenu menu(browser()->GetSelectedWebContents(), | 1911 TestRenderViewContextMenu menu(browser()->GetSelectedWebContents(), |
| 1919 context_menu_params); | 1912 context_menu_params); |
| 1920 menu.Init(); | 1913 menu.Init(); |
| 1921 menu.ExecuteCommand(IDC_CONTENT_CONTEXT_SAVEIMAGEAS); | 1914 menu.ExecuteCommand(IDC_CONTENT_CONTEXT_SAVEIMAGEAS); |
| 1922 waiter_context_menu->WaitForFinished(); | 1915 waiter_context_menu->WaitForFinished(); |
| 1923 | 1916 |
| 1924 // Validate that the correct file was downloaded via the context menu. | 1917 // Validate that the correct file was downloaded via the context menu. |
| 1925 download_items.clear(); | 1918 download_items.clear(); |
| 1926 GetDownloads(browser(), &download_items); | 1919 GetDownloads(browser(), &download_items); |
| 1927 EXPECT_TRUE(waiter_context_menu->select_file_dialog_seen()); | 1920 EXPECT_TRUE(waiter_context_menu->select_file_dialog_seen()); |
| 1921 EXPECT_EQ(DownloadItem::COMPLETE, download_items[0]->GetState()); | |
| 1928 ASSERT_EQ(2u, download_items.size()); | 1922 ASSERT_EQ(2u, download_items.size()); |
| 1929 ASSERT_EQ(url, download_items[0]->GetOriginalUrl()); | 1923 ASSERT_EQ(url, download_items[0]->GetOriginalUrl()); |
| 1930 ASSERT_EQ(url, download_items[1]->GetOriginalUrl()); | 1924 ASSERT_EQ(url, download_items[1]->GetOriginalUrl()); |
| 1925 EXPECT_EQ(DownloadItem::COMPLETE, download_items[1]->GetState()); | |
| 1931 } | 1926 } |
| 1932 | 1927 |
| 1933 IN_PROC_BROWSER_TEST_F(DownloadTest, SavePageNonHTMLViaPost) { | 1928 IN_PROC_BROWSER_TEST_F(DownloadTest, SavePageNonHTMLViaPost) { |
| 1934 // Do initial setup. | 1929 // Do initial setup. |
| 1935 ASSERT_TRUE(InitialSetup(false)); | 1930 ASSERT_TRUE(InitialSetup(false)); |
| 1936 ASSERT_TRUE(test_server()->Start()); | 1931 ASSERT_TRUE(test_server()->Start()); |
| 1937 NullSelectFile(browser()); | 1932 NullSelectFile(browser()); |
| 1938 std::vector<DownloadItem*> download_items; | 1933 std::vector<DownloadItem*> download_items; |
| 1939 GetDownloads(browser(), &download_items); | 1934 GetDownloads(browser(), &download_items); |
| 1940 ASSERT_TRUE(download_items.empty()); | 1935 ASSERT_TRUE(download_items.empty()); |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 1961 render_view_host->ExecuteJavascriptInWebFrame( | 1956 render_view_host->ExecuteJavascriptInWebFrame( |
| 1962 string16(), ASCIIToUTF16("SubmitForm()")); | 1957 string16(), ASCIIToUTF16("SubmitForm()")); |
| 1963 observer.Wait(); | 1958 observer.Wait(); |
| 1964 EXPECT_EQ(jpeg_url, web_contents->GetURL()); | 1959 EXPECT_EQ(jpeg_url, web_contents->GetURL()); |
| 1965 | 1960 |
| 1966 // Stop the test server, and then try to save the page. If cache validation | 1961 // Stop the test server, and then try to save the page. If cache validation |
| 1967 // is not bypassed then this will fail since the server is no longer | 1962 // is not bypassed then this will fail since the server is no longer |
| 1968 // reachable. This will also fail if it tries to be retrieved via "GET" | 1963 // reachable. This will also fail if it tries to be retrieved via "GET" |
| 1969 // rather than "POST". | 1964 // rather than "POST". |
| 1970 ASSERT_TRUE(test_server()->Stop()); | 1965 ASSERT_TRUE(test_server()->Stop()); |
| 1971 scoped_ptr<DownloadTestObserver> waiter( | 1966 scoped_ptr<DownloadTestObserverTerminal> waiter( |
| 1972 new DownloadTestObserver( | 1967 new DownloadTestObserverTerminal( |
| 1973 DownloadManagerForBrowser(browser()), 1, DownloadItem::COMPLETE, | 1968 DownloadManagerForBrowser(browser()), 1, |
| 1974 false, DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL)); | 1969 false, DownloadTestObserverTerminal::ON_DANGEROUS_DOWNLOAD_FAIL)); |
| 1975 browser()->SavePage(); | 1970 browser()->SavePage(); |
| 1976 waiter->WaitForFinished(); | 1971 waiter->WaitForFinished(); |
| 1977 | 1972 |
| 1978 // Validate that the correct file was downloaded. | 1973 // Validate that the correct file was downloaded. |
| 1979 GetDownloads(browser(), &download_items); | 1974 GetDownloads(browser(), &download_items); |
| 1980 EXPECT_TRUE(waiter->select_file_dialog_seen()); | 1975 EXPECT_TRUE(waiter->select_file_dialog_seen()); |
| 1981 ASSERT_EQ(1u, download_items.size()); | 1976 ASSERT_EQ(1u, download_items.size()); |
| 1982 ASSERT_EQ(jpeg_url, download_items[0]->GetOriginalUrl()); | 1977 ASSERT_EQ(jpeg_url, download_items[0]->GetOriginalUrl()); |
| 1983 | 1978 |
| 1984 // Try to download it via a context menu. | 1979 // Try to download it via a context menu. |
| 1985 scoped_ptr<DownloadTestObserver> waiter_context_menu( | 1980 scoped_ptr<DownloadTestObserverTerminal> waiter_context_menu( |
| 1986 new DownloadTestObserver( | 1981 new DownloadTestObserverTerminal( |
| 1987 DownloadManagerForBrowser(browser()), 1, DownloadItem::COMPLETE, | 1982 DownloadManagerForBrowser(browser()), 1, |
| 1988 false, DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL)); | 1983 false, DownloadTestObserverTerminal::ON_DANGEROUS_DOWNLOAD_FAIL)); |
| 1989 content::ContextMenuParams context_menu_params; | 1984 content::ContextMenuParams context_menu_params; |
| 1990 context_menu_params.media_type = WebKit::WebContextMenuData::MediaTypeImage; | 1985 context_menu_params.media_type = WebKit::WebContextMenuData::MediaTypeImage; |
| 1991 context_menu_params.src_url = jpeg_url; | 1986 context_menu_params.src_url = jpeg_url; |
| 1992 context_menu_params.page_url = jpeg_url; | 1987 context_menu_params.page_url = jpeg_url; |
| 1993 TestRenderViewContextMenu menu(web_contents, context_menu_params); | 1988 TestRenderViewContextMenu menu(web_contents, context_menu_params); |
| 1994 menu.Init(); | 1989 menu.Init(); |
| 1995 menu.ExecuteCommand(IDC_CONTENT_CONTEXT_SAVEIMAGEAS); | 1990 menu.ExecuteCommand(IDC_CONTENT_CONTEXT_SAVEIMAGEAS); |
| 1996 waiter_context_menu->WaitForFinished(); | 1991 waiter_context_menu->WaitForFinished(); |
| 1997 | 1992 |
| 1998 // Validate that the correct file was downloaded via the context menu. | 1993 // Validate that the correct file was downloaded via the context menu. |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2074 "zip_file_not_found.zip", | 2069 "zip_file_not_found.zip", |
| 2075 DOWNLOAD_NAVIGATE, | 2070 DOWNLOAD_NAVIGATE, |
| 2076 DOWNLOAD_INTERRUPT_REASON_SERVER_FAILED, | 2071 DOWNLOAD_INTERRUPT_REASON_SERVER_FAILED, |
| 2077 false | 2072 false |
| 2078 }; | 2073 }; |
| 2079 | 2074 |
| 2080 // Do initial setup. | 2075 // Do initial setup. |
| 2081 ASSERT_TRUE(InitialSetup(false)); | 2076 ASSERT_TRUE(InitialSetup(false)); |
| 2082 DownloadFileCheckErrors(download_info); | 2077 DownloadFileCheckErrors(download_info); |
| 2083 } | 2078 } |
| OLD | NEW |