Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/file_path.h" | 5 #include "base/file_path.h" |
| 6 #include "base/file_util.h" | 6 #include "base/file_util.h" |
| 7 #include "base/i18n/file_util_icu.h" | |
| 7 #include "base/path_service.h" | 8 #include "base/path_service.h" |
| 8 #include "base/scoped_temp_dir.h" | 9 #include "base/scoped_temp_dir.h" |
| 10 #include "base/string_util.h" | |
| 9 #include "chrome/app/chrome_command_ids.h" | 11 #include "chrome/app/chrome_command_ids.h" |
| 10 #include "chrome/browser/net/url_request_mock_http_job.h" | 12 #include "chrome/browser/net/url_request_mock_http_job.h" |
| 11 #include "chrome/browser/ui/browser.h" | 13 #include "chrome/browser/ui/browser.h" |
| 12 #include "chrome/browser/ui/browser_window.h" | 14 #include "chrome/browser/ui/browser_window.h" |
| 13 #include "chrome/browser/ui/download/download_tab_helper.h" | 15 #include "chrome/browser/ui/download/download_tab_helper.h" |
| 14 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 16 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
| 15 #include "chrome/common/chrome_paths.h" | 17 #include "chrome/common/chrome_paths.h" |
| 16 #include "chrome/common/url_constants.h" | 18 #include "chrome/common/url_constants.h" |
| 17 #include "chrome/test/in_process_browser_test.h" | 19 #include "chrome/test/in_process_browser_test.h" |
| 18 #include "chrome/test/ui_test_utils.h" | 20 #include "chrome/test/ui_test_utils.h" |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 134 test_dir_.Append(FilePath(kTestDir)).AppendASCII("b.saved1.htm"), | 136 test_dir_.Append(FilePath(kTestDir)).AppendASCII("b.saved1.htm"), |
| 135 full_file_name)); | 137 full_file_name)); |
| 136 EXPECT_TRUE(file_util::ContentsEqual( | 138 EXPECT_TRUE(file_util::ContentsEqual( |
| 137 test_dir_.Append(FilePath(kTestDir)).AppendASCII("1.png"), | 139 test_dir_.Append(FilePath(kTestDir)).AppendASCII("1.png"), |
| 138 dir.AppendASCII("1.png"))); | 140 dir.AppendASCII("1.png"))); |
| 139 EXPECT_TRUE(file_util::ContentsEqual( | 141 EXPECT_TRUE(file_util::ContentsEqual( |
| 140 test_dir_.Append(FilePath(kTestDir)).AppendASCII("1.css"), | 142 test_dir_.Append(FilePath(kTestDir)).AppendASCII("1.css"), |
| 141 dir.AppendASCII("1.css"))); | 143 dir.AppendASCII("1.css"))); |
| 142 } | 144 } |
| 143 | 145 |
| 146 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, SavedDirectory) { | |
|
Randy Smith (Not in Mondays)
2011/05/31 23:03:10
I know it's not consistent with the rest of the fi
haraken1
2011/06/02 09:13:22
I added a detailed comment for the test. Also, for
| |
| 147 FilePath file_name(FILE_PATH_LITERAL("a.htm")); | |
| 148 GURL url = URLRequestMockHTTPJob::GetMockUrl( | |
| 149 FilePath(kTestDir).Append(file_name)); | |
| 150 ui_test_utils::NavigateToURL(browser(), url); | |
| 151 | |
| 152 TabContentsWrapper* current_tab = browser()->GetSelectedTabContentsWrapper(); | |
| 153 ASSERT_TRUE(current_tab); | |
| 154 | |
| 155 ScopedTempDir website_save_temp_dir, download_save_temp_dir; | |
| 156 // The default folder for saving HTML. | |
| 157 ASSERT_TRUE(website_save_temp_dir.CreateUniqueTempDir()); | |
| 158 // The default folder for saving downloaded files. | |
| 159 ASSERT_TRUE(download_save_temp_dir.CreateUniqueTempDir()); | |
| 160 FilePath website_save_dir = website_save_temp_dir.path(); | |
| 161 FilePath download_save_dir = download_save_temp_dir.path(); | |
| 162 FilePath default_save_dir; | |
| 163 PathService::Get(chrome::DIR_DEFAULT_DOWNLOADS, &default_save_dir); | |
|
Paweł Hajdan Jr.
2011/05/31 17:15:53
Check the return value.
haraken1
2011/06/02 09:13:22
Done.
| |
| 164 ASSERT_TRUE(file_util::PathExists(default_save_dir)); | |
| 165 FilePath full_file_name; | |
| 166 std::string title; | |
| 167 | |
| 168 title = UTF16ToASCII( | |
|
Paweł Hajdan Jr.
2011/05/31 17:15:53
nit: Why not initialize title when declaring it th
haraken1
2011/06/02 09:13:22
Done.
| |
| 169 current_tab->download_tab_helper()->SavePageToProperDirectory( | |
| 170 website_save_dir, download_save_dir, SavePackage::SAVE_AS_ONLY_HTML)); | |
| 171 file_util::ReplaceIllegalCharactersInPath(&title, ' '); | |
| 172 full_file_name = website_save_dir.Append(FilePath(title + ".html")); | |
| 173 | |
| 174 EXPECT_EQ(url, WaitForSavePackageToFinish()); | |
| 175 | |
| 176 if (browser()->SupportsWindowFeature(Browser::FEATURE_DOWNLOADSHELF)) | |
| 177 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); | |
| 178 | |
| 179 EXPECT_TRUE(file_util::PathExists(full_file_name)); | |
| 180 EXPECT_TRUE(file_util::ContentsEqual( | |
| 181 test_dir_.Append(FilePath(kTestDir)).Append(file_name), | |
| 182 full_file_name)); | |
| 183 | |
| 184 // Delete the default folder for saving HTML. | |
|
Paweł Hajdan Jr.
2011/05/31 17:15:53
This is weird. Why don't we just pass a nonexisten
Randy Smith (Not in Mondays)
2011/05/31 23:03:10
Is there a way to create a unique temp dir that do
Paweł Hajdan Jr.
2011/06/01 07:08:09
I'd say just pass some dir name like /this/dir/doe
haraken1
2011/06/02 09:13:22
Done.
| |
| 185 ASSERT_TRUE(website_save_temp_dir.Delete()); | |
| 186 | |
| 187 title = UTF16ToASCII( | |
| 188 current_tab->download_tab_helper()->SavePageToProperDirectory( | |
| 189 website_save_dir, download_save_dir, SavePackage::SAVE_AS_ONLY_HTML)); | |
| 190 file_util::ReplaceIllegalCharactersInPath(&title, ' '); | |
| 191 full_file_name = download_save_dir.Append(FilePath(title + ".html")); | |
| 192 | |
| 193 EXPECT_EQ(url, WaitForSavePackageToFinish()); | |
| 194 | |
| 195 if (browser()->SupportsWindowFeature(Browser::FEATURE_DOWNLOADSHELF)) | |
| 196 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); | |
| 197 | |
| 198 EXPECT_TRUE(file_util::PathExists(full_file_name)); | |
| 199 EXPECT_TRUE(file_util::ContentsEqual( | |
| 200 test_dir_.Append(FilePath(kTestDir)).Append(file_name), | |
| 201 full_file_name)); | |
| 202 | |
| 203 // Delete the default folder for downloaded files. | |
| 204 ASSERT_TRUE(download_save_temp_dir.Delete()); | |
|
Paweł Hajdan Jr.
2011/05/31 17:15:53
Why do we explicitly do that here?
haraken1
2011/06/02 09:13:22
I removed it.
| |
| 205 | |
| 206 title = UTF16ToASCII( | |
| 207 current_tab->download_tab_helper()->SavePageToProperDirectory( | |
| 208 website_save_dir, download_save_dir, SavePackage::SAVE_AS_ONLY_HTML)); | |
| 209 file_util::ReplaceIllegalCharactersInPath(&title, ' '); | |
| 210 full_file_name = default_save_dir.Append(FilePath(title + ".html")); | |
| 211 | |
| 212 EXPECT_EQ(url, WaitForSavePackageToFinish()); | |
| 213 | |
| 214 if (browser()->SupportsWindowFeature(Browser::FEATURE_DOWNLOADSHELF)) | |
| 215 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); | |
| 216 | |
| 217 EXPECT_TRUE(file_util::PathExists(full_file_name)); | |
| 218 EXPECT_TRUE(file_util::ContentsEqual( | |
| 219 test_dir_.Append(FilePath(kTestDir)).Append(file_name), | |
| 220 full_file_name)); | |
| 221 | |
| 222 // Delete the file that we created in a user's "Downloads" directory. | |
| 223 ASSERT_TRUE(file_util::Delete(full_file_name, false)); | |
|
Paweł Hajdan Jr.
2011/05/31 17:15:53
Why do we explicitly do that here?
haraken1
2011/06/02 09:13:22
Done.
| |
| 224 } | |
| 225 | |
| 144 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, NoSave) { | 226 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, NoSave) { |
| 145 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kAboutBlankURL)); | 227 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kAboutBlankURL)); |
| 146 ASSERT_TRUE(browser()->command_updater()->SupportsCommand(IDC_SAVE_PAGE)); | 228 ASSERT_TRUE(browser()->command_updater()->SupportsCommand(IDC_SAVE_PAGE)); |
| 147 EXPECT_FALSE(browser()->command_updater()->IsCommandEnabled(IDC_SAVE_PAGE)); | 229 EXPECT_FALSE(browser()->command_updater()->IsCommandEnabled(IDC_SAVE_PAGE)); |
| 148 } | 230 } |
| 149 | 231 |
| 150 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, FileNameFromPageTitle) { | 232 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, FileNameFromPageTitle) { |
| 151 FilePath file_name(FILE_PATH_LITERAL("b.htm")); | 233 FilePath file_name(FILE_PATH_LITERAL("b.htm")); |
| 152 | 234 |
| 153 GURL url = URLRequestMockHTTPJob::GetMockUrl( | 235 GURL url = URLRequestMockHTTPJob::GetMockUrl( |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 177 full_file_name)); | 259 full_file_name)); |
| 178 EXPECT_TRUE(file_util::ContentsEqual( | 260 EXPECT_TRUE(file_util::ContentsEqual( |
| 179 test_dir_.Append(FilePath(kTestDir)).AppendASCII("1.png"), | 261 test_dir_.Append(FilePath(kTestDir)).AppendASCII("1.png"), |
| 180 dir.AppendASCII("1.png"))); | 262 dir.AppendASCII("1.png"))); |
| 181 EXPECT_TRUE(file_util::ContentsEqual( | 263 EXPECT_TRUE(file_util::ContentsEqual( |
| 182 test_dir_.Append(FilePath(kTestDir)).AppendASCII("1.css"), | 264 test_dir_.Append(FilePath(kTestDir)).AppendASCII("1.css"), |
| 183 dir.AppendASCII("1.css"))); | 265 dir.AppendASCII("1.css"))); |
| 184 } | 266 } |
| 185 | 267 |
| 186 } // namespace | 268 } // namespace |
| OLD | NEW |