diff options
author | estade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-04-09 18:56:16 +0000 |
---|---|---|
committer | estade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-04-09 18:56:16 +0000 |
commit | 72eb68c9482f4dcdd397e5744bcb046b514e224c (patch) | |
tree | 083c57b51daa703772ada68ed65a19e616a59e4a /chrome/browser/download | |
parent | f5b3bda9fea3606111ed4e1b7cb36df44e8448b7 (diff) | |
download | chromium_src-72eb68c9482f4dcdd397e5744bcb046b514e224c.zip chromium_src-72eb68c9482f4dcdd397e5744bcb046b514e224c.tar.gz chromium_src-72eb68c9482f4dcdd397e5744bcb046b514e224c.tar.bz2 |
back out r13442
TBR=pinkerton
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@13443 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/download')
-rw-r--r-- | chrome/browser/download/download_uitest.cc | 84 | ||||
-rw-r--r-- | chrome/browser/download/save_page_uitest.cc | 112 |
2 files changed, 85 insertions, 111 deletions
diff --git a/chrome/browser/download/download_uitest.cc b/chrome/browser/download/download_uitest.cc index 656774b..941910a 100644 --- a/chrome/browser/download/download_uitest.cc +++ b/chrome/browser/download/download_uitest.cc @@ -2,9 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#if defined(OS_WIN) #include <shlwapi.h> -#endif #include <sstream> #include <string> @@ -21,17 +19,14 @@ #include "chrome/test/ui/ui_test.h" #include "chrome/test/automation/tab_proxy.h" #include "chrome/test/automation/browser_proxy.h" -#include "net/base/net_util.h" #include "net/url_request/url_request_unittest.h" -using std::string; using std::wstring; namespace { const wchar_t kDocRoot[] = L"chrome/test/data"; -#if defined(OS_WIN) // Checks if the volume supports Alternate Data Streams. This is required for // the Zone Identifier implementation. bool VolumeSupportsADS(const std::wstring path) { @@ -69,57 +64,56 @@ void CheckZoneIdentifier(const std::wstring full_path) { ASSERT_EQ(0, strcmp(kIdentifier, buffer)); } -#endif class DownloadTest : public UITest { protected: DownloadTest() : UITest() {} - void CleanUpDownload(const FilePath& client_filename, - const FilePath& server_filename) { + void CleanUpDownload(const std::wstring& client_filename, + const std::wstring& server_filename) { // Find the path on the client. - FilePath file_on_client(download_prefix_); - file_on_client = file_on_client.Append(client_filename); + std::wstring file_on_client(download_prefix_); + file_on_client.append(client_filename); EXPECT_TRUE(file_util::PathExists(file_on_client)); // Find the path on the server. - FilePath file_on_server; + std::wstring file_on_server; ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &file_on_server)); - file_on_server = file_on_server.Append(server_filename); + file_on_server.append(L"\\"); + file_on_server.append(server_filename); ASSERT_TRUE(file_util::PathExists(file_on_server)); // Check that we downloaded the file correctly. EXPECT_TRUE(file_util::ContentsEqual(file_on_server, file_on_client)); -#if defined(OS_WIN) // Check if the Zone Identifier is correclty set. - if (VolumeSupportsADS(file_on_client.value())) - CheckZoneIdentifier(file_on_client.value()); -#endif + if (VolumeSupportsADS(file_on_client)) + CheckZoneIdentifier(file_on_client); // Delete the client copy of the file. EXPECT_TRUE(file_util::Delete(file_on_client, false)); } - void CleanUpDownload(const FilePath& file) { + void CleanUpDownload(const std::wstring& file) { CleanUpDownload(file, file); } virtual void SetUp() { UITest::SetUp(); - download_prefix_ = FilePath::FromWStringHack(GetDownloadDirectory()); + download_prefix_ = GetDownloadDirectory(); + download_prefix_ += FilePath::kSeparators[0]; } protected: - void RunSizeTest(const GURL& url, + void RunSizeTest(const wstring& url, const wstring& expected_title_in_progress, const wstring& expected_title_finished) { { EXPECT_EQ(1, GetTabCount()); - NavigateToURL(url); + NavigateToURL(GURL(url)); // Downloads appear in the shelf WaitUntilTabCount(1); // TODO(tc): check download status text @@ -138,22 +132,19 @@ class DownloadTest : public UITest { EXPECT_TRUE(WaitForDownloadShelfVisible(dl_tab.get())); } - FilePath filename; - net::FileURLToFilePath(url, &filename); - filename = filename.BaseName(); - FilePath download_path = download_prefix_.Append(filename); - EXPECT_TRUE(file_util::PathExists(download_path)); + std::wstring filename = file_util::GetFilenameFromPath(url); + EXPECT_TRUE(file_util::PathExists(download_prefix_ + filename)); // Delete the file we just downloaded. for (int i = 0; i < 10; ++i) { - if (file_util::Delete(download_path, false)) + if (file_util::Delete(download_prefix_ + filename, false)) break; PlatformThread::Sleep(action_max_timeout_ms() / 10); } - EXPECT_FALSE(file_util::PathExists(download_path)); + EXPECT_FALSE(file_util::PathExists(download_prefix_ + filename)); } - FilePath download_prefix_; + wstring download_prefix_; }; } // namespace @@ -161,11 +152,12 @@ class DownloadTest : public UITest { // Download a file with non-viewable content, verify that the // download tab opened and the file exists. TEST_F(DownloadTest, DownloadMimeType) { - FilePath file(FILE_PATH_LITERAL("download-test1.lib")); + wstring file = L"download-test1.lib"; + wstring expected_title = L"100% - " + file; EXPECT_EQ(1, GetTabCount()); - NavigateToURL(URLRequestMockHTTPJob::GetMockUrl(file.ToWStringHack())); + NavigateToURL(URLRequestMockHTTPJob::GetMockUrl(file)); // No new tabs created, downloads appear in the current tab's download shelf. WaitUntilTabCount(1); @@ -182,15 +174,16 @@ TEST_F(DownloadTest, DownloadMimeType) { // Access a file with a viewable mime-type, verify that a download // did not initiate. TEST_F(DownloadTest, NoDownload) { - FilePath file(FILE_PATH_LITERAL("download-test2.html")); - FilePath file_path = download_prefix_.Append(file); + wstring file = L"download-test2.html"; + wstring file_path = download_prefix_; + file_util::AppendToPath(&file_path, file); if (file_util::PathExists(file_path)) ASSERT_TRUE(file_util::Delete(file_path, false)); EXPECT_EQ(1, GetTabCount()); - NavigateToURL(URLRequestMockHTTPJob::GetMockUrl(file.ToWStringHack())); + NavigateToURL(URLRequestMockHTTPJob::GetMockUrl(file)); WaitUntilTabCount(1); // Wait to see if the file will be downloaded. @@ -209,12 +202,13 @@ TEST_F(DownloadTest, NoDownload) { // download tab opened and the file exists as the filename specified in the // header. This also ensures we properly handle empty file downloads. TEST_F(DownloadTest, ContentDisposition) { - FilePath file(FILE_PATH_LITERAL("download-test3.gif")); - FilePath download_file(FILE_PATH_LITERAL("download-test3-attachment.gif")); + wstring file = L"download-test3.gif"; + wstring download_file = L"download-test3-attachment.gif"; + wstring expected_title = L"100% - " + download_file; EXPECT_EQ(1, GetTabCount()); - NavigateToURL(URLRequestMockHTTPJob::GetMockUrl(file.ToWStringHack())); + NavigateToURL(URLRequestMockHTTPJob::GetMockUrl(file)); WaitUntilTabCount(1); // Wait until the file is downloaded. @@ -235,20 +229,14 @@ TEST_F(DownloadTest, ContentDisposition) { // in the middle until the server receives a second request for // "download-finish. At that time, the download will finish. TEST_F(DownloadTest, UnknownSize) { - GURL url(URLRequestSlowDownloadJob::kUnknownSizeUrl); - FilePath filename; - net::FileURLToFilePath(url, &filename); - filename = filename.BaseName(); - RunSizeTest(url, L"32.0 KB - " + filename.ToWStringHack(), - L"100% - " + filename.ToWStringHack()); + std::wstring url(URLRequestSlowDownloadJob::kUnknownSizeUrl); + std::wstring filename = file_util::GetFilenameFromPath(url); + RunSizeTest(url, L"32.0 KB - " + filename, L"100% - " + filename); } // http://b/1158253 TEST_F(DownloadTest, DISABLED_KnownSize) { - GURL url(URLRequestSlowDownloadJob::kKnownSizeUrl); - FilePath filename; - net::FileURLToFilePath(url, &filename); - filename = filename.BaseName(); - RunSizeTest(url, L"71% - " + filename.ToWStringHack(), - L"100% - " + filename.ToWStringHack()); + std::wstring url(URLRequestSlowDownloadJob::kKnownSizeUrl); + std::wstring filename = file_util::GetFilenameFromPath(url); + RunSizeTest(url, L"71% - " + filename, L"100% - " + filename); } diff --git a/chrome/browser/download/save_page_uitest.cc b/chrome/browser/download/save_page_uitest.cc index f9a2036..78e3759 100644 --- a/chrome/browser/download/save_page_uitest.cc +++ b/chrome/browser/download/save_page_uitest.cc @@ -4,7 +4,6 @@ #include "base/file_util.h" #include "base/path_service.h" -#include "base/platform_thread.h" #include "base/string_util.h" #include "chrome/app/chrome_dll_resource.h" #include "chrome/browser/automation/url_request_mock_http_job.h" @@ -15,14 +14,14 @@ #include "chrome/test/ui/ui_test.h" #include "net/url_request/url_request_unittest.h" -const std::string kTestDir = "save_page"; +const std::wstring kTestDir = L"save_page"; class SavePageTest : public UITest { protected: SavePageTest() : UITest() {} - void CheckFile(const FilePath& client_file, - const FilePath& server_file, + void CheckFile(const std::wstring& client_file, + const std::wstring& server_file, bool check_equal) { bool exist = false; for (int i = 0; i < 20; ++i) { @@ -30,16 +29,15 @@ class SavePageTest : public UITest { exist = true; break; } - PlatformThread::Sleep(sleep_timeout_ms()); + Sleep(sleep_timeout_ms()); } EXPECT_TRUE(exist); if (check_equal) { - FilePath server_file_name; + std::wstring server_file_name; ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &server_file_name)); - server_file_name = server_file_name.AppendASCII(kTestDir) - .Append(server_file); + server_file_name += L"\\" + kTestDir + L"\\" + server_file; ASSERT_TRUE(file_util::PathExists(server_file_name)); int64 client_file_size = 0; @@ -55,10 +53,11 @@ class SavePageTest : public UITest { virtual void SetUp() { UITest::SetUp(); - EXPECT_TRUE(file_util::CreateNewTempDirectory(FILE_PATH_LITERAL(""), - &save_dir_)); + EXPECT_TRUE(file_util::CreateNewTempDirectory(L"", &save_dir_)); + save_dir_ += FilePath::kSeparators[0]; - download_dir_ = FilePath::FromWStringHack(GetDownloadDirectory()); + download_dir_ = GetDownloadDirectory(); + download_dir_ += FilePath::kSeparators[0]; } virtual void TearDown() { @@ -66,78 +65,70 @@ class SavePageTest : public UITest { DieFileDie(save_dir_, true); } - FilePath save_dir_; - FilePath download_dir_; + std::wstring save_dir_; + std::wstring download_dir_; }; TEST_F(SavePageTest, SaveHTMLOnly) { - std::string file_name("a.htm"); - FilePath full_file_name = save_dir_.AppendASCII(file_name); - FilePath dir = save_dir_.AppendASCII("a_files"); + std::wstring file_name = L"a.htm"; + std::wstring full_file_name = save_dir_ + file_name; + std::wstring dir = save_dir_ + L"a_files"; - GURL url = URLRequestMockHTTPJob::GetMockUrl( - UTF8ToWide(kTestDir + "/" + file_name)); + GURL url = URLRequestMockHTTPJob::GetMockUrl(kTestDir + L"/" + file_name); scoped_ptr<TabProxy> tab(GetActiveTab()); ASSERT_TRUE(tab->NavigateToURL(url)); WaitUntilTabCount(1); - EXPECT_TRUE(tab->SavePage(full_file_name.ToWStringHack(), dir.ToWStringHack(), - SavePackage::SAVE_AS_ONLY_HTML)); + EXPECT_TRUE(tab->SavePage(full_file_name, dir, + SavePackage::SAVE_AS_ONLY_HTML)); EXPECT_TRUE(WaitForDownloadShelfVisible(tab.get())); - CheckFile(full_file_name, FilePath::FromWStringHack(UTF8ToWide(file_name)), - true); + CheckFile(full_file_name, file_name, true); EXPECT_FALSE(file_util::PathExists(dir)); } TEST_F(SavePageTest, SaveCompleteHTML) { - std::string file_name = "b.htm"; - FilePath full_file_name = save_dir_.AppendASCII(file_name); - FilePath dir = save_dir_.AppendASCII("b_files"); + std::wstring file_name = L"b.htm"; + std::wstring full_file_name = save_dir_ + file_name; + std::wstring dir = save_dir_ + L"b_files"; - GURL url = URLRequestMockHTTPJob::GetMockUrl(UTF8ToWide(kTestDir + "/" + - file_name)); + GURL url = URLRequestMockHTTPJob::GetMockUrl(kTestDir + L"/" + file_name); scoped_ptr<TabProxy> tab(GetActiveTab()); ASSERT_TRUE(tab->NavigateToURL(url)); WaitUntilTabCount(1); - EXPECT_TRUE(tab->SavePage(full_file_name.ToWStringHack(), dir.ToWStringHack(), - SavePackage::SAVE_AS_COMPLETE_HTML)); + EXPECT_TRUE(tab->SavePage(full_file_name, dir, + SavePackage::SAVE_AS_COMPLETE_HTML)); EXPECT_TRUE(WaitForDownloadShelfVisible(tab.get())); - CheckFile(dir.AppendASCII("1.png"), FilePath(FILE_PATH_LITERAL("1.png")), - true); - CheckFile(dir.AppendASCII("1.css"), FilePath(FILE_PATH_LITERAL("1.css")), - true); - CheckFile(full_file_name, FilePath::FromWStringHack(UTF8ToWide(file_name)), - false); + CheckFile(dir + L"\\1.png", L"1.png", true); + CheckFile(dir + L"\\1.css", L"1.css", true); + CheckFile(full_file_name, file_name, false); EXPECT_TRUE(DieFileDie(dir, true)); } TEST_F(SavePageTest, NoSave) { - std::string file_name = "c.htm"; - FilePath full_file_name = save_dir_.AppendASCII(file_name); - FilePath dir = save_dir_.AppendASCII("c_files"); + std::wstring file_name = L"c.htm"; + std::wstring full_file_name = save_dir_ + file_name; + std::wstring dir = save_dir_ + L"c_files"; scoped_ptr<TabProxy> tab(GetActiveTab()); - ASSERT_TRUE(tab->NavigateToURL(GURL("about:blank"))); + ASSERT_TRUE(tab->NavigateToURL(GURL(L"about:blank"))); WaitUntilTabCount(1); - EXPECT_FALSE(tab->SavePage(full_file_name.ToWStringHack(), - dir.ToWStringHack(), - SavePackage::SAVE_AS_ONLY_HTML)); + EXPECT_FALSE(tab->SavePage(full_file_name, dir, + SavePackage::SAVE_AS_ONLY_HTML)); EXPECT_FALSE(WaitForDownloadShelfVisible(tab.get())); } TEST_F(SavePageTest, FilenameFromPageTitle) { - std::string file_name = "b.htm"; - FilePath full_file_name = download_dir_.AppendASCII( - "Test page for saving page feature.htm"); - FilePath dir = download_dir_.AppendASCII( - "Test page for saving page feature_files"); - - GURL url = URLRequestMockHTTPJob::GetMockUrl(UTF8ToWide(kTestDir + "/" + - file_name)); + std::wstring file_name = L"b.htm"; + std::wstring full_file_name = download_dir_ + + L"Test page for saving page feature.htm"; + std::wstring dir = download_dir_ + + L"Test page for saving page feature_files"; + + GURL url = URLRequestMockHTTPJob::GetMockUrl(kTestDir + L"/" + file_name); scoped_ptr<TabProxy> tab(GetActiveTab()); ASSERT_TRUE(tab->NavigateToURL(url)); WaitUntilTabCount(1); @@ -148,23 +139,19 @@ TEST_F(SavePageTest, FilenameFromPageTitle) { EXPECT_TRUE(WaitForDownloadShelfVisible(tab.get())); automation()->SavePackageShouldPromptUser(true); - CheckFile(dir.AppendASCII("1.png"), FilePath(FILE_PATH_LITERAL("1.png")), - true); - CheckFile(dir.AppendASCII("1.css"), FilePath(FILE_PATH_LITERAL("1.css")), - true); - CheckFile(full_file_name, FilePath::FromWStringHack(UTF8ToWide(file_name)), - false); + CheckFile(dir + L"\\1.png", L"1.png", true); + CheckFile(dir + L"\\1.css", L"1.css", true); + CheckFile(full_file_name, file_name, false); EXPECT_TRUE(DieFileDie(full_file_name, false)); EXPECT_TRUE(DieFileDie(dir, true)); } TEST_F(SavePageTest, CleanFilenameFromPageTitle) { - std::string file_name = "c.htm"; - FilePath full_file_name = download_dir_.AppendASCII("test.htm"); - FilePath dir = download_dir_.AppendASCII("test_files"); + std::wstring file_name = L"c.htm"; + std::wstring full_file_name = download_dir_ + L"test.htm"; + std::wstring dir = download_dir_ + L"test_files"; - GURL url = URLRequestMockHTTPJob::GetMockUrl(UTF8ToWide(kTestDir + "/" + - file_name)); + GURL url = URLRequestMockHTTPJob::GetMockUrl(kTestDir + L"/" + file_name); scoped_ptr<TabProxy> tab(GetActiveTab()); ASSERT_TRUE(tab->NavigateToURL(url)); WaitUntilTabCount(1); @@ -175,8 +162,7 @@ TEST_F(SavePageTest, CleanFilenameFromPageTitle) { EXPECT_TRUE(WaitForDownloadShelfVisible(tab.get())); automation()->SavePackageShouldPromptUser(true); - CheckFile(full_file_name, FilePath::FromWStringHack(UTF8ToWide(file_name)), - false); + CheckFile(full_file_name, file_name, false); EXPECT_TRUE(DieFileDie(full_file_name, false)); EXPECT_TRUE(DieFileDie(dir, true)); } |