diff options
author | benjhayden@chromium.org <benjhayden@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-03-16 17:52:25 +0000 |
---|---|---|
committer | benjhayden@chromium.org <benjhayden@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-03-16 17:52:25 +0000 |
commit | d8d25796f9a56b974343cd2f1f5a12aa3ca0a450 (patch) | |
tree | 656058aef9664aa50b86b06f8f67b7e57440a037 | |
parent | dd18a1fea6a7cfb5da8e7fb4d62fa26f1edfb3f4 (diff) | |
download | chromium_src-d8d25796f9a56b974343cd2f1f5a12aa3ca0a450.zip chromium_src-d8d25796f9a56b974343cd2f1f5a12aa3ca0a450.tar.gz chromium_src-d8d25796f9a56b974343cd2f1f5a12aa3ca0a450.tar.bz2 |
Rewrite downloads pyauto functional tests as browser_tests.
PS1@r177226
Review URL: https://codereview.chromium.org/11969022
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@188603 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/download/download_browsertest.cc | 462 | ||||
-rw-r--r-- | chrome/test/data/downloads/dangerous/dangerous.crx | 1 | ||||
-rw-r--r-- | chrome/test/functional/PYAUTO_TESTS | 9 | ||||
-rwxr-xr-x | chrome/test/functional/downloads.py | 516 | ||||
-rw-r--r-- | chrome/test/functional/test_utils.py | 19 |
5 files changed, 458 insertions, 549 deletions
diff --git a/chrome/browser/download/download_browsertest.cc b/chrome/browser/download/download_browsertest.cc index 8b6c90d..325130e 100644 --- a/chrome/browser/download/download_browsertest.cc +++ b/chrome/browser/download/download_browsertest.cc @@ -14,6 +14,8 @@ #include "base/prefs/pref_service.h" #include "base/stl_util.h" #include "base/stringprintf.h" +#include "base/strings/string_split.h" +#include "base/sys_info.h" #include "base/test/test_file_util.h" #include "base/utf_string_conversions.h" #include "chrome/app/chrome_command_ids.h" @@ -44,6 +46,7 @@ #include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/browser_commands.h" #include "chrome/browser/ui/browser_finder.h" +#include "chrome/browser/ui/browser_list.h" #include "chrome/browser/ui/browser_tabstrip.h" #include "chrome/browser/ui/browser_window.h" #include "chrome/browser/ui/chrome_pages.h" @@ -93,6 +96,95 @@ using extensions::FeatureSwitch; namespace { +class CreatedObserver : public content::DownloadManager::Observer { + public: + explicit CreatedObserver(content::DownloadManager* manager) + : manager_(manager), + waiting_(false) { + manager->AddObserver(this); + } + virtual ~CreatedObserver() { + if (manager_) + manager_->RemoveObserver(this); + } + + void Wait() { + std::vector<DownloadItem*> downloads; + manager_->GetAllDownloads(&downloads); + if (!downloads.empty()) + return; + waiting_ = true; + content::RunMessageLoop(); + waiting_ = false; + } + + private: + virtual void OnDownloadCreated( + content::DownloadManager* manager, content::DownloadItem* item) { + DCHECK_EQ(manager_, manager); + if (waiting_) + MessageLoopForUI::current()->Quit(); + } + + content::DownloadManager* manager_; + bool waiting_; + + DISALLOW_COPY_AND_ASSIGN(CreatedObserver); +}; + +class PercentWaiter : public content::DownloadItem::Observer { + public: + explicit PercentWaiter(DownloadItem* item) + : item_(item), + waiting_(false), + error_(false), + prev_percent_(0) { + item_->AddObserver(this); + } + virtual ~PercentWaiter() { + if (item_) + item_->RemoveObserver(this); + } + + bool WaitForFinished() { + if (item_->IsComplete()) { + return item_->PercentComplete() == 100; + } + waiting_ = true; + content::RunMessageLoop(); + waiting_ = false; + return !error_; + } + + private: + virtual void OnDownloadUpdated(content::DownloadItem* item) OVERRIDE { + DCHECK_EQ(item_, item); + if (!error_ && + ((prev_percent_ > item_->PercentComplete()) || + (item_->IsComplete() && + (item_->PercentComplete() != 100)))) { + error_ = true; + if (waiting_) + MessageLoopForUI::current()->Quit(); + } + if (item_->IsComplete() && waiting_) + MessageLoopForUI::current()->Quit(); + } + + virtual void OnDownloadDestroyed(content::DownloadItem* item) OVERRIDE { + DCHECK_EQ(item_, item); + item_->RemoveObserver(this); + item_ = NULL; + } + + content::DownloadItem* item_; + bool waiting_; + bool error_; + int prev_percent_; + + DISALLOW_COPY_AND_ASSIGN(PercentWaiter); +}; + // IDs and paths of CRX files used in tests. const char kGoodCrxId[] = "ldnnhddmnhbkjipkidpdiheffobcpfmf"; const base::FilePath kGoodCrxPath(FILE_PATH_LITERAL("extensions/good.crx")); @@ -354,12 +446,15 @@ class DownloadTest : public InProcessBrowserTest { } protected: - enum SizeTestType { SIZE_TEST_TYPE_KNOWN, SIZE_TEST_TYPE_UNKNOWN, }; + base::FilePath GetDownloadsDirectory() { + return downloads_directory_.path(); + } + // Location of the file source (the place from which it is downloaded). base::FilePath OriginFile(base::FilePath file) { return test_dir_.Append(file); @@ -503,13 +598,13 @@ class DownloadTest : public InProcessBrowserTest { const base::FilePath& downloaded_file, const base::FilePath& origin_file) { bool origin_file_exists = file_util::PathExists(origin_file); - EXPECT_TRUE(origin_file_exists); + EXPECT_TRUE(origin_file_exists) << origin_file.value(); if (!origin_file_exists) return false; // Confirm the downloaded data file exists. bool downloaded_file_exists = file_util::PathExists(downloaded_file); - EXPECT_TRUE(downloaded_file_exists); + EXPECT_TRUE(downloaded_file_exists) << downloaded_file.value(); if (!downloaded_file_exists) return false; @@ -528,6 +623,45 @@ class DownloadTest : public InProcessBrowserTest { return downloaded_file_deleted; } + content::DownloadTestObserver* CreateInProgressDownloadObserver( + size_t download_count) { + DownloadManager* manager = DownloadManagerForBrowser(browser()); + return new content::DownloadTestObserverInProgress( + manager, download_count); + } + + DownloadItem* CreateSlowTestDownload() { + scoped_ptr<content::DownloadTestObserver> observer( + CreateInProgressDownloadObserver(1)); + GURL slow_download_url(URLRequestSlowDownloadJob::kUnknownSizeUrl); + DownloadManager* manager = DownloadManagerForBrowser(browser()); + + EXPECT_EQ(0, manager->InProgressCount()); + if (manager->InProgressCount() != 0) + return NULL; + + ui_test_utils::NavigateToURLWithDisposition( + browser(), slow_download_url, CURRENT_TAB, + ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); + + observer->WaitForFinished(); + EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::IN_PROGRESS)); + + DownloadManager::DownloadVector items; + manager->GetAllDownloads(&items); + + DownloadItem* new_item = NULL; + for (DownloadManager::DownloadVector::iterator iter = items.begin(); + iter != items.end(); ++iter) { + if ((*iter)->GetState() == DownloadItem::IN_PROGRESS) { + // There should be only one IN_PROGRESS item. + EXPECT_EQ(NULL, new_item); + new_item = *iter; + } + } + return new_item; + } + bool RunSizeTest(Browser* browser, SizeTestType type, const std::string& partial_indication, @@ -1171,8 +1305,7 @@ IN_PROC_BROWSER_TEST_F(DownloadTest, KnownSize) { // Also check that the download shelf is not visible after closing the // Incognito window. IN_PROC_BROWSER_TEST_F(DownloadTest, IncognitoDownload) { - // Open an Incognito window. - Browser* incognito = CreateIncognitoBrowser(); // Waits. + Browser* incognito = CreateIncognitoBrowser(); ASSERT_TRUE(incognito); int window_count = chrome::GetTotalBrowserCount(); EXPECT_EQ(2, window_count); @@ -1217,6 +1350,73 @@ IN_PROC_BROWSER_TEST_F(DownloadTest, IncognitoDownload) { CheckDownload(browser(), file, file); } +// Download one file on-record, then download the same file off-record, and test +// that the filename is deduplicated. The previous test tests for a specific +// bug; this next test tests that filename deduplication happens independently +// of DownloadManager/CDMD. +IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadTest_IncognitoRegular) { + ASSERT_TRUE(test_server()->Start()); + GURL url(test_server()->GetURL("files/downloads/a_zip_file.zip")); + + // Read the origin file now so that we can compare the downloaded files to it + // later. + base::FilePath origin(OriginFile(base::FilePath(FILE_PATH_LITERAL( + "downloads/a_zip_file.zip")))); + ASSERT_TRUE(file_util::PathExists(origin)); + int64 origin_file_size = 0; + EXPECT_TRUE(file_util::GetFileSize(origin, &origin_file_size)); + std::string original_contents; + EXPECT_TRUE(file_util::ReadFileToString(origin, &original_contents)); + + std::vector<DownloadItem*> download_items; + GetDownloads(browser(), &download_items); + ASSERT_TRUE(download_items.empty()); + + // Download a file in the on-record browser and check that it was downloaded + // correctly. + DownloadAndWaitWithDisposition(browser(), + url, + CURRENT_TAB, + ui_test_utils::BROWSER_TEST_NONE); + EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); + GetDownloads(browser(), &download_items); + ASSERT_EQ(1UL, download_items.size()); + ASSERT_EQ(base::FilePath(FILE_PATH_LITERAL("a_zip_file.zip")), + download_items[0]->GetFullPath().BaseName()); + ASSERT_TRUE(file_util::PathExists(download_items[0]->GetFullPath())); + EXPECT_TRUE(VerifyFile(download_items[0]->GetFullPath(), + original_contents, origin_file_size)); + + // Setup an incognito window. + Browser* incognito = CreateIncognitoBrowser(); + ASSERT_TRUE(incognito); + int window_count = BrowserList::GetInstance( + browser()->host_desktop_type())->size(); + EXPECT_EQ(2, window_count); + incognito->profile()->GetPrefs()->SetFilePath( + prefs::kDownloadDefaultDirectory, + GetDownloadsDirectory()); + + download_items.clear(); + GetDownloads(incognito, &download_items); + ASSERT_TRUE(download_items.empty()); + + // Download a file in the incognito browser and check that it was downloaded + // correctly. + DownloadAndWaitWithDisposition(incognito, + url, + CURRENT_TAB, + ui_test_utils::BROWSER_TEST_NONE); + EXPECT_TRUE(incognito->window()->IsDownloadShelfVisible()); + GetDownloads(incognito, &download_items); + ASSERT_EQ(1UL, download_items.size()); + ASSERT_EQ(base::FilePath(FILE_PATH_LITERAL("a_zip_file (1).zip")), + download_items[0]->GetFullPath().BaseName()); + ASSERT_TRUE(file_util::PathExists(download_items[0]->GetFullPath())); + EXPECT_TRUE(VerifyFile(download_items[0]->GetFullPath(), + original_contents, origin_file_size)); +} + // Navigate to a new background page, but don't download. Confirm that the // download shelf is not visible and that we have two tabs. IN_PROC_BROWSER_TEST_F(DownloadTest, DontCloseNewTab1) { @@ -1598,6 +1798,34 @@ IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadHistoryDangerCheck) { // there are CRLF transformations for those files. } +IN_PROC_BROWSER_TEST_F(DownloadTest, PRE_DownloadTest_History) { + // Download a file and wait for it to be stored. + base::FilePath file(FILE_PATH_LITERAL("download-test1.lib")); + GURL download_url(URLRequestMockHTTPJob::GetMockUrl(file)); + HistoryObserver observer(browser()->profile()); + DownloadAndWait(browser(), download_url); + observer.WaitForStored(); +} + +IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadTest_History) { + // This starts up right after PRE_DownloadTest_History and shares the same + // profile directory. + base::FilePath file(FILE_PATH_LITERAL("download-test1.lib")); + GURL download_url(URLRequestMockHTTPJob::GetMockUrl(file)); + std::vector<DownloadItem*> downloads; + content::DownloadManager* manager = DownloadManagerForBrowser(browser()); + + // Wait for the history to be loaded with a single DownloadItem. Check that + // it's the file that was downloaded in PRE_DownloadTest_History. + CreatedObserver created_observer(manager); + created_observer.Wait(); + manager->GetAllDownloads(&downloads); + ASSERT_EQ(1UL, downloads.size()); + DownloadItem* item = downloads[0]; + ASSERT_EQ(file.value(), item->GetFullPath().BaseName().value()); + ASSERT_EQ(download_url, item->GetURL()); +} + // Test for crbug.com/14505. This tests that chrome:// urls are still functional // after download of a file while viewing another chrome://. IN_PROC_BROWSER_TEST_F(DownloadTest, ChromeURLAfterDownload) { @@ -2472,3 +2700,227 @@ IN_PROC_BROWSER_TEST_F(DownloadTest, TestMultipleDownloadsInfobar) { DownloadItem::COMPLETE)); } +IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadTest_Renaming) { + ASSERT_TRUE(test_server()->Start()); + GURL url(test_server()->GetURL("files/downloads/a_zip_file.zip")); + content::DownloadManager* manager = DownloadManagerForBrowser(browser()); + base::FilePath origin_file(OriginFile(base::FilePath(FILE_PATH_LITERAL( + "downloads/a_zip_file.zip")))); + ASSERT_TRUE(file_util::PathExists(origin_file)); + std::string origin_contents; + ASSERT_TRUE(file_util::ReadFileToString(origin_file, &origin_contents)); + + // Download the same url several times and expect that all downloaded files + // after the zero-th contain a deduplication counter. + for (int index = 0; index < 5; ++index) { + DownloadAndWait(browser(), url); + EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); + content::DownloadItem* item = manager->GetDownload(index); + ASSERT_TRUE(item); + ASSERT_TRUE(item->IsComplete()); + base::FilePath full_path(item->GetFullPath()); + EXPECT_EQ(std::string("a_zip_file") + (index == 0 ? std::string(".zip") : + StringPrintf(" (%d).zip", index)), + full_path.BaseName().AsUTF8Unsafe()); + ASSERT_TRUE(file_util::PathExists(full_path)); + ASSERT_TRUE(VerifyFile(full_path, origin_contents, origin_contents.size())); + } +} + +// Test that the entire download pipeline handles unicode correctly. +IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadTest_CrazyFilenames) { + const wchar_t* kCrazyFilenames[] = { + L"a_file_name.zip", + L"\u89c6\u9891\u76f4\u64ad\u56fe\u7247.zip", // chinese chars + L"\u0412\u043e \u0424\u043b\u043e\u0440\u0438\u0434\u0435\u043e\u0431\u044a" + L"\u044f\u0432\u043b\u0435\u043d\u0440\u0435\u0436\u0438\u043c \u0427" + L"\u041f \u0438\u0437-\u0437\u0430 \u0443\u0442\u0435\u0447\u043a\u0438 " + L"\u043d\u0435\u0444\u0442\u0438.zip", // russian + L"Desocupa\xe7\xe3o est\xe1vel.zip", + // arabic: + L"\u0638\u2026\u0638\u02c6\u0637\xa7\u0638\u201a\u0637\xb9 \u0638\u201e" + L"\u0638\u201e\u0637\xb2\u0638\u0679\u0637\xa7\u0637\xb1\u0637\xa9.zip", + L"\u05d4\u05e2\u05d3\u05e4\u05d5\u05ea.zip", // hebrew + L"\u092d\u093e\u0930\u0924.zip", // hindi + L"d\xe9stabilis\xe9.zip", // french + // korean + L"\u97d3-\u4e2d \uc815\uc0c1, \ucc9c\uc548\ud568 \uc758\uacac.zip", + L"jiho....tiho...miho.zip", + L"jiho!@#$tiho$%^&-()_+=miho copy.zip", // special chars + L"Wohoo-to hoo+I.zip", + L"Picture 1.zip", + L"This is a very very long english sentence with spaces and , and +.zip", + }; + + std::vector<DownloadItem*> download_items; + static const int kFlags = (base::PLATFORM_FILE_CREATE | + base::PLATFORM_FILE_WRITE); + base::FilePath origin(FILE_PATH_LITERAL("origin")); + ASSERT_TRUE(file_util::CreateDirectory(DestinationFile(browser(), origin))); + + for (size_t index = 0; index < arraysize(kCrazyFilenames); ++index) { + string16 crazy16; + std::string crazy8; + const wchar_t* crazy_w = kCrazyFilenames[index]; + ASSERT_TRUE(WideToUTF8(crazy_w, wcslen(crazy_w), &crazy8)); + ASSERT_TRUE(WideToUTF16(crazy_w, wcslen(crazy_w), &crazy16)); + base::FilePath file_path(DestinationFile(browser(), origin.Append( +#if defined(OS_WIN) + crazy16 +#elif defined(OS_POSIX) + crazy8 +#endif + ))); + + // Create the file. + bool created = false; + base::PlatformFileError error = base::PLATFORM_FILE_ERROR_MAX; + base::PlatformFile fd = base::CreatePlatformFile( + file_path, kFlags, &created, &error); + EXPECT_EQ(static_cast<int>(crazy8.size()), + base::WritePlatformFileAtCurrentPos( + fd, crazy8.c_str(), crazy8.size())); + EXPECT_TRUE(base::ClosePlatformFile(fd)); + fd = base::kInvalidPlatformFileValue; + GURL file_url(net::FilePathToFileURL(file_path)); + + // Download the file and check that the filename is correct. + DownloadAndWait(browser(), file_url); + EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); + GetDownloads(browser(), &download_items); + ASSERT_EQ(1UL, download_items.size()); + base::FilePath downloaded(download_items[0]->GetFullPath()); + download_items[0]->Remove(); + download_items.clear(); + ASSERT_TRUE(CheckDownloadFullPaths( + browser(), + downloaded, + file_path)); + } +} + +IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadTest_Remove) { + ASSERT_TRUE(test_server()->Start()); + GURL url(test_server()->GetURL("files/downloads/a_zip_file.zip")); + std::vector<DownloadItem*> download_items; + GetDownloads(browser(), &download_items); + ASSERT_TRUE(download_items.empty()); + + // Download a file. + DownloadAndWaitWithDisposition(browser(), + url, + CURRENT_TAB, + ui_test_utils::BROWSER_TEST_NONE); + EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); + GetDownloads(browser(), &download_items); + ASSERT_EQ(1UL, download_items.size()); + base::FilePath downloaded(download_items[0]->GetFullPath()); + + // Remove the DownloadItem but not the file, then check that the file still + // exists. + download_items[0]->Remove(); + download_items.clear(); + GetDownloads(browser(), &download_items); + ASSERT_EQ(0UL, download_items.size()); + ASSERT_TRUE(CheckDownloadFullPaths( + browser(), downloaded, OriginFile(base::FilePath( + FILE_PATH_LITERAL("downloads/a_zip_file.zip"))))); + +} + +IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadTest_PauseResumeCancel) { + DownloadItem* download_item = CreateSlowTestDownload(); + ASSERT_TRUE(download_item); + ASSERT_FALSE(download_item->GetTargetFilePath().empty()); + EXPECT_FALSE(download_item->IsPaused()); + EXPECT_FALSE(download_item->IsCancelled()); + download_item->Pause(); + EXPECT_TRUE(download_item->IsPaused()); + download_item->Resume(); + EXPECT_FALSE(download_item->IsPaused()); + EXPECT_FALSE(download_item->IsCancelled()); + download_item->Cancel(true); + EXPECT_TRUE(download_item->IsCancelled()); +} + +// The Mac downloaded files quarantine feature is implemented by the +// Contents/Info.plist file in cocoa apps. browser_tests cannot test +// quarantining files on Mac because it is not a cocoa app. +// TODO(benjhayden) test the equivalents on other platforms. + +// Test downloading a huge file and that PercentComplete is monotonic. +IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadTest_PercentComplete) { + // Write a huge file. + base::FilePath file_path(DestinationFile( + browser(), base::FilePath(FILE_PATH_LITERAL("DownloadTest_BigZip.zip")))); + int flags = (base::PLATFORM_FILE_CREATE | + base::PLATFORM_FILE_WRITE); + bool created = false; + base::PlatformFileError error = base::PLATFORM_FILE_ERROR_MAX; + base::PlatformFile fd = base::CreatePlatformFile( + file_path, flags, &created, &error); + int64 size = 1 << 29; + EXPECT_EQ(size, base::SeekPlatformFile( + fd, base::PLATFORM_FILE_FROM_BEGIN, size)); + EXPECT_EQ(1, base::WritePlatformFileAtCurrentPos(fd, "a", 1)); + EXPECT_TRUE(base::ClosePlatformFile(fd)); + fd = base::kInvalidPlatformFileValue; +#if defined(OS_POSIX) + // Make it readable by chronos on chromeos + file_util::SetPosixFilePermissions(file_path, 0755); +#endif + + // Ensure that we have enough disk space. + int64 free_space = base::SysInfo::AmountOfFreeDiskSpace( + GetDownloadDirectory(browser())); + ASSERT_LE(size, free_space) << "Not enough disk space to download. Got " + << free_space; + GURL file_url(net::FilePathToFileURL(file_path)); + scoped_ptr<content::DownloadTestObserver> progress_waiter( + CreateInProgressWaiter(browser(), 1)); + + // Start downloading a file, wait for it to be created. + ui_test_utils::NavigateToURLWithDisposition( + browser(), file_url, CURRENT_TAB, ui_test_utils::BROWSER_TEST_NONE); + progress_waiter->WaitForFinished(); + EXPECT_EQ(1u, progress_waiter->NumDownloadsSeenInState( + DownloadItem::IN_PROGRESS)); + std::vector<DownloadItem*> download_items; + GetDownloads(browser(), &download_items); + ASSERT_EQ(1UL, download_items.size()); + + // Wait for the download to complete, checking along the way that the + // PercentComplete() never regresses. + PercentWaiter waiter(download_items[0]); + EXPECT_TRUE(waiter.WaitForFinished()); + EXPECT_EQ(DownloadItem::COMPLETE, download_items[0]->GetState()); + ASSERT_EQ(100, download_items[0]->PercentComplete()); + EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); + + // Check that the file downloaded correctly. + ASSERT_TRUE(file_util::PathExists(download_items[0]->GetFullPath())); + int64 downloaded_size = 0; + ASSERT_TRUE(file_util::GetFileSize( + download_items[0]->GetFullPath(), &downloaded_size)); +#if defined(OS_WIN) + ASSERT_EQ(1, downloaded_size); +#else + ASSERT_EQ(size + 1, downloaded_size); +#endif + ASSERT_TRUE(file_util::DieFileDie(file_path, false)); + ASSERT_TRUE(file_util::DieFileDie(download_items[0]->GetFullPath(), false)); +} + +IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadTest_DenyDanger) { + ASSERT_TRUE(test_server()->Start()); + GURL url(test_server()->GetURL("files/downloads/dangerous/dangerous.crx")); + scoped_ptr<content::DownloadTestObserver> observer( + DangerousDownloadWaiter( + browser(), 1, + content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_DENY)); + ui_test_utils::NavigateToURL(browser(), url); + observer->WaitForFinished(); + EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::CANCELLED)); + EXPECT_EQ(1u, observer->NumDangerousDownloadsSeen()); + EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); +} diff --git a/chrome/test/data/downloads/dangerous/dangerous.crx b/chrome/test/data/downloads/dangerous/dangerous.crx new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/chrome/test/data/downloads/dangerous/dangerous.crx @@ -0,0 +1 @@ + diff --git a/chrome/test/functional/PYAUTO_TESTS b/chrome/test/functional/PYAUTO_TESTS index 0db6556..980282e 100644 --- a/chrome/test/functional/PYAUTO_TESTS +++ b/chrome/test/functional/PYAUTO_TESTS @@ -37,7 +37,6 @@ 'autofill', 'codesign', 'crash_reporter', - 'downloads', 'execute_javascript', 'extensions', 'fullscreen_mouselock', @@ -70,8 +69,6 @@ '-autofill.AutofillTest.testDisplayLineItemForEntriesWithNoCCNum', # crbug.com/171828 '-autofill.AutofillTest.testNoDuplicatePhoneNumsInPrefs', - # crbug.com/124280 - '-downloads.DownloadsTest.testPauseAndResume', # The source is behind. Waiting for dev to automate the update. # crbug.com/109160 '-execute_javascript.ExecuteJavascriptTest.testExecuteJavascriptInExtension', @@ -152,8 +149,6 @@ # ================================================== # crbug.com/105948 '-autofill.AutofillTest.testPostalCodeAndStateLabelsBasedOnCountry', - # crbug.com/169512 - '-downloads.DownloadsTest.testDownloadsPersistence', # crbug.com/111289 '-extensions.ExtensionsTest.testAllowAccessFileURLs', # crbug.com/113090 @@ -269,9 +264,6 @@ # ================================================== # crbug.com/132337 '-autofill.AutofillTest.testTabOrderForEditAddress', - # Downloads panel stays even after declining a download. - # crosbug.com/14728 - '-downloads.DownloadsTest.testDeclineDangerousDownload', # crosbug.com/19556 '-extensions.ExtensionsTest.testAllowAccessFileURLs', '-extensions.ExtensionsTest.testAllowIncognitoExtension', @@ -298,7 +290,6 @@ '-prefs.PrefsTest.testSessionRestoreURLs', '-prefs.PrefsTest.testSessionRestore', # Deal with i18n chars. crosbug.com/12639 - '-downloads.DownloadsTest.testCrazyFilenames', '-omnibox.OmniboxTest.testCrazyFilenames', # crosbug.com/16977 '-chromeos_wifi_sanity.ChromeosWifiSanity.testConnectToHiddenWiFiNonExistent', diff --git a/chrome/test/functional/downloads.py b/chrome/test/functional/downloads.py deleted file mode 100755 index e94c1c6..0000000 --- a/chrome/test/functional/downloads.py +++ /dev/null @@ -1,516 +0,0 @@ -#!/usr/bin/env python -# Copyright (c) 2012 The Chromium Authors. All rights reserved. -# Use of this source code is governed by a BSD-style license that can be -# found in the LICENSE file. - -import commands -import filecmp -import logging -import os -import shutil -import sys -import tempfile -import urllib - -import pyauto_functional # Must be imported before pyauto -import pyauto -import pyauto_utils -import test_utils - - -class DownloadsTest(pyauto.PyUITest): - """TestCase for Downloads.""" - - def setUp(self): - pyauto.PyUITest.setUp(self) - # Record all entries in the download dir - download_dir = self.GetDownloadDirectory().value() - self._existing_downloads = [] - if os.path.isdir(download_dir): - self._existing_downloads += os.listdir(download_dir) - self._files_to_remove = [] # Files to remove after browser shutdown - - def tearDown(self): - # Cleanup all files we created in the download dir - download_dir = self.GetDownloadDirectory().value() - if os.path.isdir(download_dir): - for name in os.listdir(download_dir): - if name not in self._existing_downloads: - self._files_to_remove.append(os.path.join(download_dir, name)) - pyauto.PyUITest.tearDown(self) - # Delete all paths marked for deletion after browser shutdown. - for item in self._files_to_remove: - pyauto_utils.RemovePath(item) - - def _DeleteAfterShutdown(self, path): - """Delete |path| after browser has been shut down. - - This is so that all handles to the path would have been gone by then. - Silently Ignores errors, when the path does not exist, or if the path - could not be deleted. - """ - self._files_to_remove.append(path) - - def _ClearLocalDownloadState(self, path): - """Prepare for downloading the given path. - - Clears the given path and the corresponding .crdownload, to prepare it to - be downloaded. - """ - os.path.exists(path) and os.remove(path) - crdownload = path + '.crdownload' - os.path.exists(crdownload) and os.remove(crdownload) - - def _GetDangerousDownload(self): - """Returns the file path for a dangerous download for this OS.""" - sub_path = os.path.join(self.DataDir(), 'downloads', 'dangerous') - if self.IsWin(): - return os.path.join(sub_path, 'dangerous.com') - return os.path.join(sub_path, 'dangerous.jar') - - def _EqualFileContents(self, file1, file2): - """Determine if 2 given files have the same contents.""" - if not (os.path.exists(file1) and os.path.exists(file2)): - return False - return filecmp.cmp(file1, file2, shallow=False) - - def _GetDownloadId(self, download_index=0): - """Return the download id for the download at the given index. - - Args: - download_index: The index of the download in the list of downloads. - Default is 0. - """ - return self.GetDownloadsInfo().Downloads()[download_index]['id'] - - def _MakeFile(self, size): - """Make a file on-the-fly with the given size. - - Note that it's really a 1byte file even though ls -lh will report it as - of file |size| (du reports the correct usage on disk), but it's good - enough for downloads tests because chrome will treat it as a file of size - |size| when downloading. - - Returns: - the path to the created file. - """ - fd, file_path = tempfile.mkstemp(suffix='.zip', prefix='file-downloads-') - os.lseek(fd, size, 0) - os.write(fd, 'a') - os.close(fd) - # Make it readable by chronos on chromeos - os.chmod(file_path, 0755) - logging.debug('Created temporary file %s of size %d' % (file_path, size)) - self._DeleteAfterShutdown(file_path) - return file_path - - def _GetAllDownloadIDs(self): - """Return a list of all download ids.""" - return [download['id'] for download in self.GetDownloadsInfo().Downloads()] - - def testNoDownloadWaitingNeeded(self): - """Make sure "wait for downloads" returns quickly if we have none.""" - self.WaitForAllDownloadsToComplete() - - def testZip(self): - """Download a zip and verify that it downloaded correctly. - Also verify that the download shelf showed up. - """ - test_dir = os.path.join(os.path.abspath(self.DataDir()), 'downloads') - file_path = os.path.join(test_dir, 'a_zip_file.zip') - file_url = self.GetFileURLForPath(file_path) - downloaded_pkg = os.path.join(self.GetDownloadDirectory().value(), - 'a_zip_file.zip') - self._ClearLocalDownloadState(downloaded_pkg) - - self.DownloadAndWaitForStart(file_url) - - # Wait for the download to finish. - self.WaitForAllDownloadsToComplete() - - # Verify that the download shelf is visible - self.assertTrue(self.IsDownloadShelfVisible()) - - # Verify that the file was correctly downloaded - self.assertTrue(os.path.exists(downloaded_pkg)) - self.assertTrue(self._EqualFileContents(file_path, downloaded_pkg)) - - def testZipInIncognito(self): - """Download and verify a zip in incognito window.""" - test_dir = os.path.join(os.path.abspath(self.DataDir()), 'downloads') - file_path = os.path.join(test_dir, 'a_zip_file.zip') - file_url = self.GetFileURLForPath(file_path) - downloaded_pkg = os.path.join(self.GetDownloadDirectory().value(), - 'a_zip_file.zip') - self._ClearLocalDownloadState(downloaded_pkg) - self.RunCommand(pyauto.IDC_NEW_INCOGNITO_WINDOW) - - # Trigger download and wait in new incognito window. - self.DownloadAndWaitForStart(file_url, windex=1) - self.WaitForAllDownloadsToComplete(windex=1) - incognito_downloads = self.GetDownloadsInfo(1).Downloads() - - # Verify that download info exists in the correct profile. - self.assertEqual(len(incognito_downloads), 1) - self.assertTrue(self._EqualFileContents(file_path, downloaded_pkg), - msg='%s (size %d) and %s (size %d) do not match' % ( - file_path, os.path.getsize(file_path), - downloaded_pkg, os.path.getsize(downloaded_pkg))) - self.assertTrue(self.IsDownloadShelfVisible(1)) - - def testSaveDangerousFile(self): - """Verify that we can download and save a dangerous file.""" - file_path = self._GetDangerousDownload() - downloaded_pkg = os.path.join(self.GetDownloadDirectory().value(), - os.path.basename(file_path)) - self._ClearLocalDownloadState(downloaded_pkg) - self._TriggerUnsafeDownload(os.path.basename(file_path)) - self.PerformActionOnDownload(self._GetDownloadId(), - 'save_dangerous_download') - self.WaitForAllDownloadsToComplete() - - # Verify that the file was downloaded. - self.assertTrue(os.path.exists(downloaded_pkg)) - self.assertTrue(self._EqualFileContents(file_path, downloaded_pkg)) - self._DeleteAfterShutdown(downloaded_pkg) - - def testDeclineDangerousDownload(self): - """Verify that we can decline dangerous downloads""" - file_path = self._GetDangerousDownload() - downloaded_pkg = os.path.join(self.GetDownloadDirectory().value(), - os.path.basename(file_path)) - self._ClearLocalDownloadState(downloaded_pkg) - self._TriggerUnsafeDownload(os.path.basename(file_path)) - self.PerformActionOnDownload(self._GetDownloadId(), - 'decline_dangerous_download') - self.assertFalse(os.path.exists(downloaded_pkg)) - self.assertFalse(self.GetDownloadsInfo().Downloads()) - self.assertFalse(self.IsDownloadShelfVisible()) - - def testRemoveDownload(self): - """Verify that we can remove a download.""" - file_url = self.GetFileURLForDataPath('downloads', 'a_zip_file.zip') - downloaded_pkg = os.path.join(self.GetDownloadDirectory().value(), - 'a_zip_file.zip') - self._ClearLocalDownloadState(downloaded_pkg) - - self.DownloadAndWaitForStart(file_url) - self.WaitForAllDownloadsToComplete() - self.PerformActionOnDownload(self._GetDownloadId(), 'remove') - - # The download is removed from downloads, but not from the disk. - self.assertFalse(self.GetDownloadsInfo().Downloads()) - self.assertTrue(os.path.exists(downloaded_pkg)) - self._DeleteAfterShutdown(downloaded_pkg) - - def testBigZip(self): - """Verify that we can download a 1GB file. - - This test needs 2 GB of free space, 1 GB for the original zip file and - another for the downloaded one. - - Note: This test increases automation timeout to 4 min. Things might seem - to hang. - """ - # Create a 1 GB file on the fly - file_path = self._MakeFile(2**30) - # Ensure there's sufficient space remaining to download file. - free_space = test_utils.GetFreeSpace(self.GetDownloadDirectory().value()) - assert free_space >= 2**30, \ - 'Not enough disk space to download. Got %d free' % free_space - file_url = self.GetFileURLForPath(file_path) - downloaded_pkg = os.path.join(self.GetDownloadDirectory().value(), - os.path.basename(file_path)) - self._ClearLocalDownloadState(downloaded_pkg) - self.DownloadAndWaitForStart(file_url) - self._DeleteAfterShutdown(downloaded_pkg) - self.WaitForAllDownloadsToComplete(timeout=10 * 60 * 1000); - # Verify that the file was correctly downloaded - self.assertTrue(os.path.exists(downloaded_pkg), - 'Downloaded file %s missing.' % downloaded_pkg) - self.assertTrue(self._EqualFileContents(file_path, downloaded_pkg), - 'Downloaded file %s does not match original' % - downloaded_pkg) - - def testFileRenaming(self): - """Test file renaming when downloading a already-existing filename.""" - test_dir = os.path.join(os.path.abspath(self.DataDir()), 'downloads') - file_url = 'file://%s' % os.path.join(test_dir, 'a_zip_file.zip') - download_dir = self.GetDownloadDirectory().value() - - num_times = 5 - assert num_times > 1, 'needs to be > 1 to work' - renamed_files = [] - for i in range(num_times): - expected_filename = os.path.join(download_dir, 'a_zip_file.zip') - if i > 0: # Files after first download are renamed. - expected_filename = os.path.join(download_dir, - 'a_zip_file (%d).zip' % i) - renamed_files.append(expected_filename) - self._ClearLocalDownloadState(expected_filename) - self.DownloadAndWaitForStart(file_url) - - self.WaitForAllDownloadsToComplete() - - # Verify that all files exist and have the right name - for filename in renamed_files: - self.assertTrue(os.path.exists(filename)) - self._DeleteAfterShutdown(filename) - - def testCrazyFilenames(self): - """Test downloading with filenames containing special chars. - - The files are created on the fly and cleaned after use. - """ - download_dir = self.GetDownloadDirectory().value() - filename = os.path.join(self.DataDir(), 'downloads', 'crazy_filenames.txt') - crazy_filenames = self.EvalDataFrom(filename) - logging.info('Testing with %d crazy filenames' % len(crazy_filenames)) - - def _CreateFile(name): - """Create and fill the given file with some junk.""" - fp = open(name, 'w') # name could be unicode - print >>fp, 'This is a junk file named %s. ' % repr(name) * 100 - fp.close() - - # Temp dir for hosting crazy filenames. - temp_dir = tempfile.mkdtemp(prefix='download') - self._DeleteAfterShutdown(unicode(temp_dir)) - # Windows has a dual nature dealing with unicode filenames. - # While the files are internally saved as unicode, there's a non-unicode - # aware API that returns a locale-dependent coding on the true unicode - # filenames. This messes up things. - # Filesystem-interfacing functions like os.listdir() need to - # be given unicode strings to "do the right thing" on win. - # Ref: http://boodebr.org/main/python/all-about-python-and-unicode - for filename in crazy_filenames: # filename is unicode. - utf8_filename = filename.encode('utf-8') - file_path = os.path.join(temp_dir, utf8_filename) - _CreateFile(os.path.join(temp_dir, filename)) # unicode file. - file_url = self.GetFileURLForPath(file_path) - downloaded_file = os.path.join(download_dir, filename) - self._ClearLocalDownloadState(downloaded_file) - self.DownloadAndWaitForStart(file_url) - self.WaitForAllDownloadsToComplete() - - # Verify downloads. - downloads = self.GetDownloadsInfo().Downloads() - self.assertEqual(len(downloads), len(crazy_filenames)) - - for filename in crazy_filenames: - downloaded_file = os.path.join(download_dir, filename) - self.assertTrue(os.path.exists(downloaded_file)) - self.assertTrue( # Verify file contents. - self._EqualFileContents(downloaded_file, - os.path.join(temp_dir, filename))) - os.path.exists(downloaded_file) and os.remove(downloaded_file) - - def _TriggerUnsafeDownload(self, filename, tab_index=0, windex=0): - """Trigger download of an unsafe/dangerous filetype. - - Files explictly requested by the user (like navigating to a package, or - clicking on a link) aren't marked unsafe. - Only the ones where the user didn't directly initiate a download are - marked unsafe. - - Navigates to download-dangerous.html which triggers the download. - Waits until the download starts. - - Args: - filename: the name of the file to trigger the download. - This should exist in the 'dangerous' directory. - tab_index: tab index. Default 0. - windex: window index. Default 0. - """ - dangerous_dir = os.path.join( - self.DataDir(), 'downloads', 'dangerous') - assert os.path.isfile(os.path.join(dangerous_dir, filename)) - file_url = self.GetFileURLForPath(os.path.join( - dangerous_dir, 'download-dangerous.html')) + '?' + filename - num_downloads = len(self.GetDownloadsInfo().Downloads()) - self.NavigateToURL(file_url, windex, tab_index) - # It might take a while for the download to kick in, hold on until then. - self.assertTrue(self.WaitUntil( - lambda: len(self.GetDownloadsInfo().Downloads()) == num_downloads + 1)) - # Wait for Download Shelf to appear to reduce flakiness. - self.assertTrue(self.WaitUntil(self.IsDownloadShelfVisible)) - - def testPauseAndResume(self): - """Verify that pause and resume work while downloading a file. - - Note: This test increases automation timeout to 2 min. Things might seem - to hang. - """ - # Create a 250 MB file on the fly - file_path = self._MakeFile(2**28) - # Ensure there's sufficient space remaining to download file. - free_space = test_utils.GetFreeSpace(self.GetDownloadDirectory().value()) - assert free_space >= 2**28, \ - 'Not enough disk space to download. Got %d free' % free_space - - file_url = self.GetFileURLForPath(file_path) - downloaded_pkg = os.path.join(self.GetDownloadDirectory().value(), - os.path.basename(file_path)) - self._ClearLocalDownloadState(downloaded_pkg) - self.DownloadAndWaitForStart(file_url) - - self._DeleteAfterShutdown(downloaded_pkg) - self._DeleteAfterShutdown(file_path) - - # Pause the download and assert that it is paused. - pause_dict = self.PerformActionOnDownload(self._GetDownloadId(), 'pause') - if pause_dict['state'] == 'COMPLETE': - logging.info('The download completed before pause. Stopping test.') - return - - self.assertTrue(pause_dict['is_paused']) - self.assertTrue(pause_dict['state'] == 'IN_PROGRESS') - - # Resume the download and assert it is not paused. - resume_dict = self.PerformActionOnDownload(self._GetDownloadId(), 'resume') - self.assertFalse(resume_dict['is_paused']) - self.WaitForAllDownloadsToComplete(timeout=10 * 60 * 1000); - - # Verify that the file was correctly downloaded after pause and resume. - self.assertTrue(os.path.exists(downloaded_pkg), - 'Downloaded file %s missing.' % downloaded_pkg) - self.assertTrue(self._EqualFileContents(file_path, downloaded_pkg), - 'Downloaded file %s does not match original' % - downloaded_pkg) - - def testCancelDownload(self): - """Verify that we can cancel a download.""" - # Create a big file (250 MB) on the fly, so that the download won't finish - # before being cancelled. - file_path = self._MakeFile(2**28) - # Ensure there's sufficient space remaining to download file. - free_space = test_utils.GetFreeSpace(self.GetDownloadDirectory().value()) - assert free_space >= 2**28, \ - 'Not enough disk space to download. Got %d free' % free_space - file_url = self.GetFileURLForPath(file_path) - downloaded_pkg = os.path.join(self.GetDownloadDirectory().value(), - os.path.basename(file_path)) - self._ClearLocalDownloadState(downloaded_pkg) - self.DownloadAndWaitForStart(file_url) - self.PerformActionOnDownload(self._GetDownloadId(), 'cancel') - self._DeleteAfterShutdown(file_path) - - state = self.GetDownloadsInfo().Downloads()[0]['state'] - if state == 'COMPLETE': - logging.info('The download completed before cancel. Test stopped.') - return - - # Verify the download has been cancelled. - self.assertEqual('CANCELLED', - self.GetDownloadsInfo().Downloads()[0]['state']) - self.assertFalse(os.path.exists(downloaded_pkg)) - - def testDownloadsPersistence(self): - """Verify that download history persists on session restart.""" - test_dir = os.path.join(os.path.abspath(self.DataDir()), 'downloads') - file_url = self.GetFileURLForPath(os.path.join(test_dir, 'a_zip_file.zip')) - downloaded_pkg = os.path.join(self.GetDownloadDirectory().value(), - 'a_zip_file.zip') - self._ClearLocalDownloadState(downloaded_pkg) - self.DownloadAndWaitForStart(file_url) - self.WaitForAllDownloadsToComplete() - downloads = self.GetDownloadsInfo().Downloads() - self.assertEqual(1, len(downloads)) - self.assertEqual('a_zip_file.zip', downloads[0]['file_name']) - file_url = downloads[0]['url'] - self.RestartBrowser(clear_profile=False) - # Trigger the download service to get loaded after restart. - self.NavigateToURL('chrome://downloads/') - # Verify that there's no download shelf anymore. - self.assertFalse(self.IsDownloadShelfVisible(), - 'Download shelf persisted browser restart.') - # Verify that the download history persists. - downloads = self.GetDownloadsInfo().Downloads() - self.assertEqual(1, len(downloads)) - self.assertEqual('a_zip_file.zip', downloads[0]['file_name']) - self.assertEqual(file_url, downloads[0]['url']) - self._DeleteAfterShutdown(downloaded_pkg) - - def testExtendedAttributesOnMac(self): - """Verify that Chrome sets the extended attributes on a file. - This test is for mac only. - """ - if not self.IsMac(): - logging.info('Skipping testExtendedAttributesOnMac on non-Mac') - return - downloaded_pkg = os.path.join(self.GetDownloadDirectory().value(), - 'a_zip_file.zip') - self._ClearLocalDownloadState(downloaded_pkg) - file_url = 'http://src.chromium.org/viewvc/chrome/trunk/src/chrome/'\ - 'test/data/downloads/a_zip_file.zip' - self.DownloadAndWaitForStart(file_url) - self.WaitForAllDownloadsToComplete() - import xattr - self.assertTrue('com.apple.quarantine' in xattr.listxattr(downloaded_pkg)) - - def testDownloadPercentage(self): - """Verify that during downloading, % values increases, - and once download is over, % value is 100""" - file_path = self._MakeFile(2**24) - # Ensure there's sufficient space remaining to download file. - free_space = test_utils.GetFreeSpace(self.GetDownloadDirectory().value()) - assert free_space >= 2**24, \ - 'Not enough disk space to download. Got %d free' % free_space - file_url = self.GetFileURLForPath(file_path) - downloaded_pkg = os.path.join(self.GetDownloadDirectory().value(), - os.path.basename(file_path)) - os.path.exists(downloaded_pkg) and os.remove(downloaded_pkg) - self.DownloadAndWaitForStart(file_url) - downloaded_pkg = os.path.join(self.GetDownloadDirectory().value(), - os.path.basename(file_path)) - downloads = self.GetDownloadsInfo().Downloads() - old_percentage = downloads[0]['PercentComplete'] - def _PercentInc(): - percent = self.GetDownloadsInfo().Downloads()[0]['PercentComplete'] - return old_percentage == 100 or percent > old_percentage, - self.assertTrue(self.WaitUntil(_PercentInc), - msg='Download percentage value is not increasing') - # Once download is completed, percentage is 100. - self.WaitForAllDownloadsToComplete() - downloads = self.GetDownloadsInfo().Downloads() - self.assertEqual(downloads[0]['PercentComplete'], 100, - 'Download percentage should be 100 after download completed') - os.path.exists(file_path) and os.remove(file_path) - os.path.exists(downloaded_pkg) and os.remove(downloaded_pkg) - - def testDownloadIncognitoAndRegular(self): - """Download the same zip file in regular and incognito window and - verify that it downloaded correctly with same file name appended with - counter for the second download in regular window. - """ - test_dir = os.path.join(os.path.abspath(self.DataDir()), 'downloads') - file_path = os.path.join(test_dir, 'a_zip_file.zip') - file_url = self.GetFileURLForPath(file_path) - downloaded_pkg_regul = os.path.join(self.GetDownloadDirectory().value(), - 'a_zip_file.zip') - downloaded_pkg_incog = os.path.join(self.GetDownloadDirectory().value(), - 'a_zip_file (1).zip') - self._ClearLocalDownloadState(downloaded_pkg_regul) - self._ClearLocalDownloadState(downloaded_pkg_incog) - - self.DownloadAndWaitForStart(file_url, 0) - self.WaitForAllDownloadsToComplete(windex=0) - - self.RunCommand(pyauto.IDC_NEW_INCOGNITO_WINDOW) - self.DownloadAndWaitForStart(file_url, 1) - self.WaitForAllDownloadsToComplete(windex=1) - - # Verify download in regular window. - self.assertTrue(os.path.exists(downloaded_pkg_regul)) - self.assertTrue(self._EqualFileContents(file_path, downloaded_pkg_regul)) - - # Verify download in incognito window. - # bug 69738 WaitForAllDownloadsToComplete is flaky for this test case. - # Using extra WaitUntil until this is resolved. - self.assertTrue(self.WaitUntil( - lambda: os.path.exists(downloaded_pkg_incog))) - self.assertTrue(self._EqualFileContents(file_path, downloaded_pkg_incog)) - - -if __name__ == '__main__': - pyauto_functional.Main() diff --git a/chrome/test/functional/test_utils.py b/chrome/test/functional/test_utils.py index 1d525b6..55d97c8 100644 --- a/chrome/test/functional/test_utils.py +++ b/chrome/test/functional/test_utils.py @@ -7,7 +7,6 @@ import ctypes import email import logging import os -import platform import shutil import smtplib import subprocess @@ -57,24 +56,6 @@ def CopyFileFromContentDataDirToDownloadDir(test, file_path): shutil.copy(data_file, download_dir) -def DownloadFileFromDownloadsDataDir(test, file_name): - """Download a file from downloads data directory, in first tab, first window. - - Args: - test: derived from pyauto.PyUITest - base class for UI test cases. - file_name: name of file to download. - """ - file_url = test.GetFileURLForDataPath(os.path.join('downloads', file_name)) - downloaded_pkg = os.path.join(test.GetDownloadDirectory().value(), - file_name) - # Check if file already exists. If so then delete it. - if os.path.exists(downloaded_pkg): - RemoveDownloadedTestFile(test, file_name) - pre_download_ids = [x['id'] for x in test.GetDownloadsInfo().Downloads()] - test.DownloadAndWaitForStart(file_url) - test.WaitForAllDownloadsToComplete(pre_download_ids) - - def RemoveDownloadedTestFile(test, file_name): """Delete a file from the downloads directory. |