Index: chrome/browser/download/save_page_browsertest.cc |
diff --git a/chrome/browser/download/save_page_browsertest.cc b/chrome/browser/download/save_page_browsertest.cc |
index c2420ba5eb08c07de08f4fedb52d396cbf998351..809e0b60cf353f21b1fc13bacd23e667ebc52740 100644 |
--- a/chrome/browser/download/save_page_browsertest.cc |
+++ b/chrome/browser/download/save_page_browsertest.cc |
@@ -4,8 +4,10 @@ |
#include "base/file_path.h" |
#include "base/file_util.h" |
+#include "base/i18n/file_util_icu.h" |
#include "base/path_service.h" |
#include "base/scoped_temp_dir.h" |
+#include "base/string_util.h" |
#include "chrome/app/chrome_command_ids.h" |
#include "chrome/browser/net/url_request_mock_http_job.h" |
#include "chrome/browser/ui/browser.h" |
@@ -141,6 +143,153 @@ IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, SaveCompleteHTML) { |
dir.AppendASCII("1.css"))); |
} |
+// Checks if an HTML page is saved to the default folder for saving HTML |
+// in the following situation: |
+// The default folder for saving HTML exists. |
+// The default folder for downloaded files exists. |
+// The user's "Downloads" folder exists. |
+IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, SaveToFolderForHTMLPage) { |
+ FilePath file_name(FILE_PATH_LITERAL("a.htm")); |
+ GURL url = URLRequestMockHTTPJob::GetMockUrl( |
+ FilePath(kTestDir).Append(file_name)); |
+ ui_test_utils::NavigateToURL(browser(), url); |
+ |
+ TabContentsWrapper* current_tab = browser()->GetSelectedTabContentsWrapper(); |
+ ASSERT_TRUE(current_tab); |
+ |
+ ScopedTempDir website_save_dir, download_save_dir, default_downloads_dir; |
+ // Prepare the default folder for saving HTML. |
+ ASSERT_TRUE(website_save_dir.CreateUniqueTempDir()); |
+ // Prepare the default folder for downloaded files. |
+ ASSERT_TRUE(download_save_dir.CreateUniqueTempDir()); |
+ // Prepare the user's "Downloads" folder. |
+ ASSERT_TRUE(default_downloads_dir.CreateUniqueTempDir()); |
+ |
+ // Changes the default prefs. |
+ current_tab->download_tab_helper()->ChangeSaveDirectoryPrefs( |
+ website_save_dir.path(), |
+ download_save_dir.path(), |
+ default_downloads_dir.path(), |
+ SavePackage::SAVE_AS_ONLY_HTML); |
+ |
+ std::string title = UTF16ToASCII( |
+ current_tab->download_tab_helper()->SavePageWithoutDialog()); |
+ file_util::ReplaceIllegalCharactersInPath(&title, ' '); |
+ FilePath full_file_name = |
+ website_save_dir.path().Append(FilePath(title + ".html")); |
+ |
+ EXPECT_EQ(url, WaitForSavePackageToFinish()); |
+ |
+ if (browser()->SupportsWindowFeature(Browser::FEATURE_DOWNLOADSHELF)) |
+ EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); |
+ |
+ // Is the file downloaded to the default folder for saving HTML? |
+ EXPECT_TRUE(file_util::PathExists(full_file_name)); |
+ EXPECT_TRUE(file_util::ContentsEqual( |
+ test_dir_.Append(FilePath(kTestDir)).Append(file_name), |
+ full_file_name)); |
+ |
+ current_tab->download_tab_helper()->RestoreSaveDirectoryPrefs(); |
+} |
+ |
+// Checks if an HTML page is saved to the default folder for downloaded files |
+// in the following situation: |
+// The default folder for saving HTML does not exist. |
+// The default folder for downloaded files exists. |
+// The user's "Downloads" folder exists. |
+IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, SaveToFolderForDownloadedFiles) { |
+ FilePath file_name(FILE_PATH_LITERAL("a.htm")); |
+ GURL url = URLRequestMockHTTPJob::GetMockUrl( |
+ FilePath(kTestDir).Append(file_name)); |
+ ui_test_utils::NavigateToURL(browser(), url); |
+ |
+ TabContentsWrapper* current_tab = browser()->GetSelectedTabContentsWrapper(); |
+ ASSERT_TRUE(current_tab); |
+ |
+ ScopedTempDir download_save_dir, default_downloads_dir; |
+ // Prepare the default folder for saving downloaded files. |
+ ASSERT_TRUE(download_save_dir.CreateUniqueTempDir()); |
+ // Prepare the user's "Downloads" folder. |
+ ASSERT_TRUE(default_downloads_dir.CreateUniqueTempDir()); |
+ // Prepare non-existent folder. |
+ FilePath nonexistent_path("/koakuma/mikity/moemoe/nyannyan"); |
+ ASSERT_FALSE(file_util::PathExists(nonexistent_path)); |
+ |
+ // Changes the default prefs. |
+ current_tab->download_tab_helper()->ChangeSaveDirectoryPrefs( |
+ nonexistent_path, |
+ download_save_dir.path(), |
+ default_downloads_dir.path(), |
+ SavePackage::SAVE_AS_ONLY_HTML); |
+ |
+ std::string title = UTF16ToASCII( |
+ current_tab->download_tab_helper()->SavePageWithoutDialog()); |
+ file_util::ReplaceIllegalCharactersInPath(&title, ' '); |
+ FilePath full_file_name = |
+ download_save_dir.path().Append(FilePath(title + ".html")); |
+ |
+ EXPECT_EQ(url, WaitForSavePackageToFinish()); |
+ |
+ if (browser()->SupportsWindowFeature(Browser::FEATURE_DOWNLOADSHELF)) |
+ EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); |
+ |
+ // Is the file downloaded to the default folder for downloaded files? |
+ EXPECT_TRUE(file_util::PathExists(full_file_name)); |
+ EXPECT_TRUE(file_util::ContentsEqual( |
+ test_dir_.Append(FilePath(kTestDir)).Append(file_name), |
+ full_file_name)); |
+ |
+ current_tab->download_tab_helper()->RestoreSaveDirectoryPrefs(); |
+} |
+ |
+// Checks if an HTML page is saved to the user's "Downloads" directory |
+// in the following situation: |
+// The default folder for saving HTML does not exist. |
+// The default folder for downloaded files does not exist. |
+// The user's "Downloads" folder exists. |
Randy Smith (Not in Mondays)
2011/06/02 19:13:57
Should we also test the fourth case where none of
haraken1
2011/06/03 06:50:27
I added a new test, SavePageBrowserTest.SavedFolde
|
+IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, SaveToUsersDownloadsFolder) { |
+ FilePath file_name(FILE_PATH_LITERAL("a.htm")); |
+ GURL url = URLRequestMockHTTPJob::GetMockUrl( |
+ FilePath(kTestDir).Append(file_name)); |
+ ui_test_utils::NavigateToURL(browser(), url); |
+ |
+ TabContentsWrapper* current_tab = browser()->GetSelectedTabContentsWrapper(); |
+ ASSERT_TRUE(current_tab); |
+ |
+ ScopedTempDir default_downloads_dir; |
+ // Prepare the user's "Downloads" folder. |
+ ASSERT_TRUE(default_downloads_dir.CreateUniqueTempDir()); |
+ // Prepare non-existent folder. |
+ FilePath nonexistent_path("/koakuma/mikity/moemoe/nyannyan"); |
+ ASSERT_FALSE(file_util::PathExists(nonexistent_path)); |
+ |
+ // Changes the default prefs. |
+ current_tab->download_tab_helper()->ChangeSaveDirectoryPrefs( |
+ nonexistent_path, |
+ nonexistent_path, |
+ default_downloads_dir.path(), |
+ SavePackage::SAVE_AS_ONLY_HTML); |
+ |
+ std::string title = UTF16ToASCII( |
+ current_tab->download_tab_helper()->SavePageWithoutDialog()); |
+ file_util::ReplaceIllegalCharactersInPath(&title, ' '); |
+ FilePath full_file_name = |
+ default_downloads_dir.path().Append(FilePath(title + ".html")); |
+ |
+ EXPECT_EQ(url, WaitForSavePackageToFinish()); |
+ |
+ if (browser()->SupportsWindowFeature(Browser::FEATURE_DOWNLOADSHELF)) |
+ EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); |
+ |
+ // Is the file downloaded to the user's "Downloads" directory? |
+ EXPECT_TRUE(file_util::PathExists(full_file_name)); |
+ EXPECT_TRUE(file_util::ContentsEqual( |
+ test_dir_.Append(FilePath(kTestDir)).Append(file_name), |
+ full_file_name)); |
+ |
+ current_tab->download_tab_helper()->RestoreSaveDirectoryPrefs(); |
+} |
+ |
IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, NoSave) { |
ui_test_utils::NavigateToURL(browser(), GURL(chrome::kAboutBlankURL)); |
ASSERT_TRUE(browser()->command_updater()->SupportsCommand(IDC_SAVE_PAGE)); |