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" |
(...skipping 1389 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1400 ExpectWindowCountAfterDownload(1); | 1400 ExpectWindowCountAfterDownload(1); |
1401 #endif | 1401 #endif |
1402 | 1402 |
1403 EXPECT_EQ(1, browser()->tab_count()); | 1403 EXPECT_EQ(1, browser()->tab_count()); |
1404 // Download shelf should close. Download panel stays open on ChromeOS. | 1404 // Download shelf should close. Download panel stays open on ChromeOS. |
1405 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); | 1405 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); |
1406 | 1406 |
1407 CheckDownload(browser(), file, file); | 1407 CheckDownload(browser(), file, file); |
1408 } | 1408 } |
1409 | 1409 |
1410 // Check that downloading multiple (in this case, 2) files does not result in | |
1411 // corrupted files. | |
1412 IN_PROC_BROWSER_TEST_F(DownloadTest, MultiDownload) { | |
1413 EXPECT_EQ(1, browser()->tab_count()); | |
1414 | |
1415 // Create a download, wait until it's started, and confirm | |
1416 // we're in the expected state. | |
1417 scoped_ptr<content::DownloadTestObserver> observer1( | |
1418 CreateInProgressWaiter(browser(), 1)); | |
1419 ui_test_utils::NavigateToURL( | |
1420 browser(), GURL(URLRequestSlowDownloadJob::kUnknownSizeUrl)); | |
1421 observer1->WaitForFinished(); | |
1422 | |
1423 std::vector<DownloadItem*> downloads; | |
1424 DownloadManagerForBrowser(browser())->SearchDownloads( | |
1425 string16(), &downloads); | |
1426 ASSERT_EQ(1u, downloads.size()); | |
1427 ASSERT_EQ(DownloadItem::IN_PROGRESS, downloads[0]->GetState()); | |
1428 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); | |
1429 DownloadItem* download1 = downloads[0]; // The only download. | |
1430 | |
1431 // Start the second download and wait until it's done. | |
1432 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); | |
1433 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); | |
1434 // Download the file and wait. We do not expect the Select File dialog. | |
1435 DownloadAndWait(browser(), url); | |
1436 | |
1437 // Should now have 2 items on the download shelf. | |
1438 downloads.clear(); | |
1439 DownloadManagerForBrowser(browser())->SearchDownloads( | |
1440 string16(), &downloads); | |
1441 ASSERT_EQ(2u, downloads.size()); | |
1442 // We don't know the order of the downloads. | |
1443 DownloadItem* download2 = downloads[(download1 == downloads[0]) ? 1 : 0]; | |
1444 | |
1445 ASSERT_EQ(DownloadItem::IN_PROGRESS, download1->GetState()); | |
1446 ASSERT_EQ(DownloadItem::COMPLETE, download2->GetState()); | |
1447 // The download shelf should be open. | |
1448 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); | |
1449 | |
1450 // Allow the first request to finish. We do this by loading a third URL | |
1451 // in a separate tab. | |
1452 scoped_ptr<content::DownloadTestObserver> observer2( | |
1453 CreateWaiter(browser(), 1)); | |
1454 GURL finish_url(URLRequestSlowDownloadJob::kFinishDownloadUrl); | |
1455 ui_test_utils::NavigateToURLWithDisposition( | |
1456 browser(), | |
1457 finish_url, | |
1458 NEW_FOREGROUND_TAB, | |
1459 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); | |
1460 observer2->WaitForFinished(); // Wait for the third request. | |
1461 EXPECT_EQ(1u, observer2->NumDownloadsSeenInState(DownloadItem::COMPLETE)); | |
1462 | |
1463 // Get the important info from other threads and check it. | |
1464 EXPECT_TRUE(EnsureNoPendingDownloads()); | |
1465 | |
1466 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); | |
1467 | |
1468 // The |DownloadItem|s should now be done and have the final file names. | |
1469 // Verify that the files have the expected data and size. | |
1470 // |file1| should be full of '*'s, and |file2| should be the same as the | |
1471 // source file. | |
1472 FilePath file1(download1->GetFullPath()); | |
1473 size_t file_size1 = URLRequestSlowDownloadJob::kFirstDownloadSize + | |
1474 URLRequestSlowDownloadJob::kSecondDownloadSize; | |
1475 std::string expected_contents(file_size1, '*'); | |
1476 ASSERT_TRUE(VerifyFile(file1, expected_contents, file_size1)); | |
1477 | |
1478 FilePath file2(download2->GetFullPath()); | |
1479 ASSERT_TRUE(file_util::ContentsEqual(OriginFile(file), file2)); | |
1480 } | |
1481 | |
1482 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadCancelled) { | |
1483 EXPECT_EQ(1, browser()->tab_count()); | |
1484 | |
1485 // TODO(rdsmith): Fragile code warning! The code below relies on the | |
1486 // DownloadTestObserverInProgress only finishing when the new download | |
1487 // has reached the state of being entered into the history and being | |
1488 // user-visible (that's what's required for the Remove to be valid and | |
1489 // for the download shelf to be visible). By the pure semantics of | |
1490 // DownloadTestObserverInProgress, that's not guaranteed; DownloadItems | |
1491 // are created in the IN_PROGRESS state and made known to the DownloadManager | |
1492 // immediately, so any ModelChanged event on the DownloadManager after | |
1493 // navigation would allow the observer to return. However, the only | |
1494 // ModelChanged() event the code will currently fire is in | |
1495 // OnCreateDownloadEntryComplete, at which point the download item will | |
1496 // be in the state we need. | |
1497 // The right way to fix this is to create finer grained states on the | |
1498 // DownloadItem, and wait for the state that indicates the item has been | |
1499 // entered in the history and made visible in the UI. | |
1500 | |
1501 // Create a download, wait until it's started, and confirm | |
1502 // we're in the expected state. | |
1503 scoped_ptr<content::DownloadTestObserver> observer( | |
1504 CreateInProgressWaiter(browser(), 1)); | |
1505 ui_test_utils::NavigateToURL( | |
1506 browser(), GURL(URLRequestSlowDownloadJob::kUnknownSizeUrl)); | |
1507 observer->WaitForFinished(); | |
1508 | |
1509 std::vector<DownloadItem*> downloads; | |
1510 DownloadManagerForBrowser(browser())->SearchDownloads( | |
1511 string16(), &downloads); | |
1512 ASSERT_EQ(1u, downloads.size()); | |
1513 ASSERT_EQ(DownloadItem::IN_PROGRESS, downloads[0]->GetState()); | |
1514 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); | |
1515 | |
1516 // Cancel the download and wait for download system quiesce. | |
1517 downloads[0]->Delete(DownloadItem::DELETE_DUE_TO_USER_DISCARD); | |
1518 scoped_refptr<content::DownloadTestFlushObserver> flush_observer( | |
1519 new content::DownloadTestFlushObserver( | |
1520 DownloadManagerForBrowser(browser()))); | |
1521 flush_observer->WaitForFlush(); | |
1522 | |
1523 // Get the important info from other threads and check it. | |
1524 EXPECT_TRUE(EnsureNoPendingDownloads()); | |
1525 | |
1526 // Using "DownloadItem::Remove" follows the discard dangerous download path, | |
1527 // which completely removes the browser from the shelf and closes the shelf | |
1528 // if it was there. Download panel stays open on ChromeOS. | |
1529 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); | |
1530 } | |
1531 | |
1532 // Confirm a download makes it into the history properly. | 1410 // Confirm a download makes it into the history properly. |
1533 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadHistoryCheck) { | 1411 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadHistoryCheck) { |
1534 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); | 1412 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); |
1535 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); | 1413 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); |
1536 FilePath origin_file(OriginFile(file)); | 1414 FilePath origin_file(OriginFile(file)); |
1537 int64 origin_size; | 1415 int64 origin_size; |
1538 file_util::GetFileSize(origin_file, &origin_size); | 1416 file_util::GetFileSize(origin_file, &origin_size); |
1539 | 1417 |
1540 // Download the file and wait. We do not expect the Select File dialog. | 1418 // Download the file and wait. We do not expect the Select File dialog. |
1541 DownloadAndWait(browser(), url); | 1419 DownloadAndWait(browser(), url); |
(...skipping 927 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2469 GetDownloads(browser(), &download_items); | 2347 GetDownloads(browser(), &download_items); |
2470 ASSERT_EQ(1u, download_items.size()); | 2348 ASSERT_EQ(1u, download_items.size()); |
2471 ASSERT_EQ(test_server()->GetURL("echoheader?Referer"), | 2349 ASSERT_EQ(test_server()->GetURL("echoheader?Referer"), |
2472 download_items[0]->GetOriginalUrl()); | 2350 download_items[0]->GetOriginalUrl()); |
2473 | 2351 |
2474 // Check that the file contains the expected referrer. | 2352 // Check that the file contains the expected referrer. |
2475 FilePath file(download_items[0]->GetFullPath()); | 2353 FilePath file(download_items[0]->GetFullPath()); |
2476 std::string expected_contents = test_server()->GetURL("").spec(); | 2354 std::string expected_contents = test_server()->GetURL("").spec(); |
2477 ASSERT_TRUE(VerifyFile(file, expected_contents, expected_contents.length())); | 2355 ASSERT_TRUE(VerifyFile(file, expected_contents, expected_contents.length())); |
2478 } | 2356 } |
OLD | NEW |