| 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 "base/bind.h" | 5 #include "base/bind.h" |
| 6 #include "base/bind_helpers.h" | 6 #include "base/bind_helpers.h" |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/file_path.h" | 8 #include "base/file_path.h" |
| 9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
| 10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
| 11 #include "base/scoped_temp_dir.h" | 11 #include "base/scoped_temp_dir.h" |
| 12 #include "base/test/test_file_util.h" | 12 #include "base/test/test_file_util.h" |
| 13 #include "chrome/app/chrome_command_ids.h" | 13 #include "chrome/app/chrome_command_ids.h" |
| 14 #include "chrome/browser/download/chrome_download_manager_delegate.h" | 14 #include "chrome/browser/download/chrome_download_manager_delegate.h" |
| 15 #include "chrome/browser/download/download_history.h" | 15 #include "chrome/browser/download/download_history.h" |
| 16 #include "chrome/browser/download/download_persistent_store_info.h" |
| 16 #include "chrome/browser/download/download_prefs.h" | 17 #include "chrome/browser/download/download_prefs.h" |
| 17 #include "chrome/browser/download/download_service.h" | 18 #include "chrome/browser/download/download_service.h" |
| 18 #include "chrome/browser/download/download_service_factory.h" | 19 #include "chrome/browser/download/download_service_factory.h" |
| 20 #include "chrome/browser/history/history_service_factory.h" |
| 19 #include "chrome/browser/net/url_request_mock_util.h" | 21 #include "chrome/browser/net/url_request_mock_util.h" |
| 20 #include "chrome/browser/prefs/pref_member.h" | 22 #include "chrome/browser/prefs/pref_member.h" |
| 21 #include "chrome/browser/prefs/pref_service.h" | 23 #include "chrome/browser/prefs/pref_service.h" |
| 22 #include "chrome/browser/profiles/profile.h" | 24 #include "chrome/browser/profiles/profile.h" |
| 23 #include "chrome/browser/ui/browser.h" | 25 #include "chrome/browser/ui/browser.h" |
| 24 #include "chrome/browser/ui/browser_commands.h" | 26 #include "chrome/browser/ui/browser_commands.h" |
| 25 #include "chrome/browser/ui/browser_tabstrip.h" | 27 #include "chrome/browser/ui/browser_tabstrip.h" |
| 26 #include "chrome/browser/ui/browser_window.h" | 28 #include "chrome/browser/ui/browser_window.h" |
| 27 #include "chrome/common/chrome_paths.h" | 29 #include "chrome/common/chrome_paths.h" |
| 28 #include "chrome/common/chrome_switches.h" | 30 #include "chrome/common/chrome_switches.h" |
| 29 #include "chrome/common/pref_names.h" | 31 #include "chrome/common/pref_names.h" |
| 30 #include "chrome/common/url_constants.h" | 32 #include "chrome/common/url_constants.h" |
| 31 #include "chrome/test/base/in_process_browser_test.h" | 33 #include "chrome/test/base/in_process_browser_test.h" |
| 32 #include "chrome/test/base/ui_test_utils.h" | 34 #include "chrome/test/base/ui_test_utils.h" |
| 33 #include "content/public/browser/download_item.h" | 35 #include "content/public/browser/download_item.h" |
| 34 #include "content/public/browser/download_manager.h" | 36 #include "content/public/browser/download_manager.h" |
| 35 #include "content/public/browser/download_persistent_store_info.h" | |
| 36 #include "content/public/browser/notification_service.h" | 37 #include "content/public/browser/notification_service.h" |
| 37 #include "content/public/browser/notification_types.h" | 38 #include "content/public/browser/notification_types.h" |
| 38 #include "content/public/browser/web_contents.h" | 39 #include "content/public/browser/web_contents.h" |
| 39 #include "content/test/net/url_request_mock_http_job.h" | 40 #include "content/test/net/url_request_mock_http_job.h" |
| 40 #include "testing/gtest/include/gtest/gtest.h" | 41 #include "testing/gtest/include/gtest/gtest.h" |
| 41 | 42 |
| 42 #if defined(OS_CHROMEOS) | 43 #if defined(OS_CHROMEOS) |
| 43 #include "chrome/browser/download/save_package_file_picker_chromeos.h" | 44 #include "chrome/browser/download/save_package_file_picker_chromeos.h" |
| 44 #else | 45 #else |
| 45 #include "chrome/browser/download/save_package_file_picker.h" | 46 #include "chrome/browser/download/save_package_file_picker.h" |
| 46 #endif | 47 #endif |
| 47 | 48 |
| 48 using content::BrowserContext; | 49 using content::BrowserContext; |
| 49 using content::BrowserThread; | 50 using content::BrowserThread; |
| 50 using content::DownloadItem; | 51 using content::DownloadItem; |
| 51 using content::DownloadManager; | 52 using content::DownloadManager; |
| 52 using content::DownloadPersistentStoreInfo; | |
| 53 using content::WebContents; | 53 using content::WebContents; |
| 54 | 54 |
| 55 namespace { | 55 namespace { |
| 56 | 56 |
| 57 static const FilePath::CharType* kTestDir = FILE_PATH_LITERAL("save_page"); | 57 static const FilePath::CharType* kTestDir = FILE_PATH_LITERAL("save_page"); |
| 58 | 58 |
| 59 static const char* kAppendedExtension = | 59 static const char* kAppendedExtension = |
| 60 #if defined(OS_WIN) | 60 #if defined(OS_WIN) |
| 61 ".htm"; | 61 ".htm"; |
| 62 #else | 62 #else |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 } | 117 } |
| 118 | 118 |
| 119 DownloadManager* GetDownloadManager() const { | 119 DownloadManager* GetDownloadManager() const { |
| 120 DownloadManager* download_manager = | 120 DownloadManager* download_manager = |
| 121 BrowserContext::GetDownloadManager(browser()->profile()); | 121 BrowserContext::GetDownloadManager(browser()->profile()); |
| 122 EXPECT_TRUE(download_manager); | 122 EXPECT_TRUE(download_manager); |
| 123 return download_manager; | 123 return download_manager; |
| 124 } | 124 } |
| 125 | 125 |
| 126 void QueryDownloadHistory() { | 126 void QueryDownloadHistory() { |
| 127 content::RunAllPendingInMessageLoop(content::BrowserThread::DB); |
| 128 content::RunAllPendingInMessageLoop(content::BrowserThread::UI); |
| 129 |
| 127 // Query the history system. | 130 // Query the history system. |
| 128 ChromeDownloadManagerDelegate* delegate = | 131 HistoryService* hs = HistoryServiceFactory::GetForProfile( |
| 129 static_cast<ChromeDownloadManagerDelegate*>( | 132 browser()->profile(), Profile::EXPLICIT_ACCESS); |
| 130 GetDownloadManager()->GetDelegate()); | 133 hs->QueryDownloads(&history_consumer_, base::Bind( |
| 131 delegate->download_history()->Load( | 134 &SavePageBrowserTest::OnQueryDownloadEntriesComplete, |
| 132 base::Bind(&SavePageBrowserTest::OnQueryDownloadEntriesComplete, | 135 base::Unretained(this))); |
| 133 base::Unretained(this))); | |
| 134 | 136 |
| 135 // Run message loop until a quit message is sent from | 137 // Run message loop until a quit message is sent from |
| 136 // OnQueryDownloadEntriesComplete(). | 138 // OnQueryDownloadEntriesComplete(). |
| 137 content::RunMessageLoop(); | 139 content::RunMessageLoop(); |
| 138 } | 140 } |
| 139 | 141 |
| 140 void OnQueryDownloadEntriesComplete( | 142 void OnQueryDownloadEntriesComplete( |
| 141 std::vector<DownloadPersistentStoreInfo>* entries) { | 143 std::vector<DownloadPersistentStoreInfo>* entries) { |
| 142 history_entries_ = *entries; | 144 history_entries_ = *entries; |
| 143 | 145 |
| 144 // Indicate thet we have received the history and can continue. | 146 // Indicate thet we have received the history and can continue. |
| 145 MessageLoopForUI::current()->Quit(); | 147 MessageLoopForUI::current()->Quit(); |
| 146 } | 148 } |
| 147 | 149 |
| 148 struct DownloadPersistentStoreInfoMatch | |
| 149 : public std::unary_function<DownloadPersistentStoreInfo, bool> { | |
| 150 | |
| 151 DownloadPersistentStoreInfoMatch(const GURL& url, | |
| 152 const FilePath& path, | |
| 153 int64 num_files) | |
| 154 : url_(url), | |
| 155 path_(path), | |
| 156 num_files_(num_files) { | |
| 157 } | |
| 158 | |
| 159 bool operator() (const DownloadPersistentStoreInfo& info) const { | |
| 160 return info.url == url_ && | |
| 161 info.path == path_ && | |
| 162 // For non-MHTML save packages, received_bytes is actually the | |
| 163 // number of files. | |
| 164 ((num_files_ < 0) || | |
| 165 (info.received_bytes == num_files_)) && | |
| 166 info.total_bytes == 0 && | |
| 167 info.state == DownloadItem::COMPLETE; | |
| 168 } | |
| 169 | |
| 170 GURL url_; | |
| 171 FilePath path_; | |
| 172 int64 num_files_; | |
| 173 }; | |
| 174 | |
| 175 void CheckDownloadHistory(const GURL& url, | 150 void CheckDownloadHistory(const GURL& url, |
| 176 const FilePath& path, | 151 const FilePath& path, |
| 177 int64 num_files) { | 152 int64 num_files, |
| 153 bool expect_found) { |
| 178 QueryDownloadHistory(); | 154 QueryDownloadHistory(); |
| 179 | 155 bool found = false; |
| 180 std::vector<DownloadPersistentStoreInfo>::iterator found = | 156 for (std::vector<DownloadPersistentStoreInfo>::iterator it = |
| 181 std::find_if(history_entries_.begin(), history_entries_.end(), | 157 history_entries_.begin(); |
| 182 DownloadPersistentStoreInfoMatch(url, path, num_files)); | 158 it != history_entries_.end(); ++it) { |
| 183 | 159 if (it->url != url) { |
| 184 if (found == history_entries_.end()) { | 160 LOG(WARNING) << it->url.spec() << " != " << url.spec(); |
| 185 LOG(ERROR) << "Missing url=" << url.spec() | 161 } else if (it->path != path) { |
| 186 << " path=" << path.value() | 162 LOG(WARNING) << it->path.value() << " != " << path.value(); |
| 187 << " received=" << num_files; | 163 } else if ((num_files >= 0) && |
| 188 for (size_t index = 0; index < history_entries_.size(); ++index) { | 164 (it->received_bytes != num_files)) { |
| 189 LOG(ERROR) << "History@" << index << ": url=" | 165 LOG(WARNING) << it->received_bytes << " != " << num_files; |
| 190 << history_entries_[index].url.spec() | 166 } else if ((num_files >= 0) && |
| 191 << " path=" << history_entries_[index].path.value() | 167 (it->total_bytes != num_files)) { |
| 192 << " received=" << history_entries_[index].received_bytes | 168 LOG(WARNING) << it->total_bytes << " != " << num_files; |
| 193 << " total=" << history_entries_[index].total_bytes | 169 } else if (it->state != DownloadItem::COMPLETE) { |
| 194 << " state=" << history_entries_[index].state; | 170 LOG(WARNING) << it->state << " != " << DownloadItem::COMPLETE; |
| 171 } else { |
| 172 found = true; |
| 173 break; |
| 195 } | 174 } |
| 196 EXPECT_TRUE(false); | |
| 197 } | 175 } |
| 176 EXPECT_EQ(found, expect_found); |
| 198 } | 177 } |
| 199 | 178 |
| 200 std::vector<DownloadPersistentStoreInfo> history_entries_; | 179 std::vector<DownloadPersistentStoreInfo> history_entries_; |
| 201 | 180 |
| 202 // Path to directory containing test data. | 181 // Path to directory containing test data. |
| 203 FilePath test_dir_; | 182 FilePath test_dir_; |
| 204 | 183 |
| 205 // Temporary directory we will save pages to. | 184 // Temporary directory we will save pages to. |
| 206 ScopedTempDir save_dir_; | 185 ScopedTempDir save_dir_; |
| 207 | 186 |
| 208 private: | 187 private: |
| 188 CancelableRequestConsumer history_consumer_; |
| 209 DISALLOW_COPY_AND_ASSIGN(SavePageBrowserTest); | 189 DISALLOW_COPY_AND_ASSIGN(SavePageBrowserTest); |
| 210 }; | 190 }; |
| 211 | 191 |
| 212 SavePageBrowserTest::~SavePageBrowserTest() { | 192 SavePageBrowserTest::~SavePageBrowserTest() { |
| 213 } | 193 } |
| 214 | 194 |
| 215 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, SaveHTMLOnly) { | 195 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, SaveHTMLOnly) { |
| 216 GURL url = NavigateToMockURL("a"); | 196 GURL url = NavigateToMockURL("a"); |
| 217 | 197 |
| 218 FilePath full_file_name, dir; | 198 FilePath full_file_name, dir; |
| 219 GetDestinationPaths("a", &full_file_name, &dir); | 199 GetDestinationPaths("a", &full_file_name, &dir); |
| 220 ASSERT_TRUE(GetCurrentTab()->SavePage(full_file_name, dir, | 200 ASSERT_TRUE(GetCurrentTab()->SavePage(full_file_name, dir, |
| 221 content::SAVE_PAGE_TYPE_AS_ONLY_HTML)); | 201 content::SAVE_PAGE_TYPE_AS_ONLY_HTML)); |
| 222 | 202 |
| 223 EXPECT_EQ(url, WaitForSavePackageToFinish()); | 203 EXPECT_EQ(url, WaitForSavePackageToFinish()); |
| 224 | 204 |
| 225 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); | 205 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); |
| 226 CheckDownloadHistory(url, full_file_name, 1); // a.htm is 1 file. | 206 CheckDownloadHistory(url, full_file_name, 1, true); // a.htm is 1 file. |
| 227 | 207 |
| 228 EXPECT_TRUE(file_util::PathExists(full_file_name)); | 208 EXPECT_TRUE(file_util::PathExists(full_file_name)); |
| 229 EXPECT_FALSE(file_util::PathExists(dir)); | 209 EXPECT_FALSE(file_util::PathExists(dir)); |
| 230 EXPECT_TRUE(file_util::ContentsEqual( | 210 EXPECT_TRUE(file_util::ContentsEqual( |
| 231 test_dir_.Append(FilePath(kTestDir)).Append(FILE_PATH_LITERAL("a.htm")), | 211 test_dir_.Append(FilePath(kTestDir)).Append(FILE_PATH_LITERAL("a.htm")), |
| 232 full_file_name)); | 212 full_file_name)); |
| 233 } | 213 } |
| 234 | 214 |
| 235 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, SaveViewSourceHTMLOnly) { | 215 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, SaveViewSourceHTMLOnly) { |
| 236 FilePath file_name(FILE_PATH_LITERAL("a.htm")); | 216 FilePath file_name(FILE_PATH_LITERAL("a.htm")); |
| 237 GURL view_source_url = URLRequestMockHTTPJob::GetMockViewSourceUrl( | 217 GURL view_source_url = URLRequestMockHTTPJob::GetMockViewSourceUrl( |
| 238 FilePath(kTestDir).Append(file_name)); | 218 FilePath(kTestDir).Append(file_name)); |
| 239 GURL actual_page_url = URLRequestMockHTTPJob::GetMockUrl( | 219 GURL actual_page_url = URLRequestMockHTTPJob::GetMockUrl( |
| 240 FilePath(kTestDir).Append(file_name)); | 220 FilePath(kTestDir).Append(file_name)); |
| 241 ui_test_utils::NavigateToURL(browser(), view_source_url); | 221 ui_test_utils::NavigateToURL(browser(), view_source_url); |
| 242 | 222 |
| 243 FilePath full_file_name, dir; | 223 FilePath full_file_name, dir; |
| 244 GetDestinationPaths("a", &full_file_name, &dir); | 224 GetDestinationPaths("a", &full_file_name, &dir); |
| 245 ASSERT_TRUE(GetCurrentTab()->SavePage(full_file_name, dir, | 225 ASSERT_TRUE(GetCurrentTab()->SavePage(full_file_name, dir, |
| 246 content::SAVE_PAGE_TYPE_AS_ONLY_HTML)); | 226 content::SAVE_PAGE_TYPE_AS_ONLY_HTML)); |
| 247 | 227 |
| 248 EXPECT_EQ(actual_page_url, WaitForSavePackageToFinish()); | 228 EXPECT_EQ(actual_page_url, WaitForSavePackageToFinish()); |
| 249 | 229 |
| 250 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); | 230 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); |
| 251 CheckDownloadHistory(actual_page_url, full_file_name, 1); // a.htm is 1 file. | 231 CheckDownloadHistory(actual_page_url, full_file_name, 1, true); |
| 252 | 232 |
| 253 EXPECT_TRUE(file_util::PathExists(full_file_name)); | 233 EXPECT_TRUE(file_util::PathExists(full_file_name)); |
| 254 EXPECT_FALSE(file_util::PathExists(dir)); | 234 EXPECT_FALSE(file_util::PathExists(dir)); |
| 255 EXPECT_TRUE(file_util::ContentsEqual( | 235 EXPECT_TRUE(file_util::ContentsEqual( |
| 256 test_dir_.Append(FilePath(kTestDir)).Append(file_name), | 236 test_dir_.Append(FilePath(kTestDir)).Append(file_name), |
| 257 full_file_name)); | 237 full_file_name)); |
| 258 } | 238 } |
| 259 | 239 |
| 260 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, SaveCompleteHTML) { | 240 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, SaveCompleteHTML) { |
| 261 GURL url = NavigateToMockURL("b"); | 241 GURL url = NavigateToMockURL("b"); |
| 262 | 242 |
| 263 FilePath full_file_name, dir; | 243 FilePath full_file_name, dir; |
| 264 GetDestinationPaths("b", &full_file_name, &dir); | 244 GetDestinationPaths("b", &full_file_name, &dir); |
| 265 ASSERT_TRUE(GetCurrentTab()->SavePage( | 245 ASSERT_TRUE(GetCurrentTab()->SavePage( |
| 266 full_file_name, dir, content::SAVE_PAGE_TYPE_AS_COMPLETE_HTML)); | 246 full_file_name, dir, content::SAVE_PAGE_TYPE_AS_COMPLETE_HTML)); |
| 267 | 247 |
| 268 EXPECT_EQ(url, WaitForSavePackageToFinish()); | 248 EXPECT_EQ(url, WaitForSavePackageToFinish()); |
| 269 | 249 |
| 270 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); | 250 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); |
| 271 CheckDownloadHistory(url, full_file_name, 3); // b.htm is 3 files. | 251 CheckDownloadHistory(url, full_file_name, 3, true); // b.htm is 3 files. |
| 272 | 252 |
| 273 EXPECT_TRUE(file_util::PathExists(full_file_name)); | 253 EXPECT_TRUE(file_util::PathExists(full_file_name)); |
| 274 EXPECT_TRUE(file_util::PathExists(dir)); | 254 EXPECT_TRUE(file_util::PathExists(dir)); |
| 275 EXPECT_TRUE(file_util::TextContentsEqual( | 255 EXPECT_TRUE(file_util::TextContentsEqual( |
| 276 test_dir_.Append(FilePath(kTestDir)).AppendASCII("b.saved1.htm"), | 256 test_dir_.Append(FilePath(kTestDir)).AppendASCII("b.saved1.htm"), |
| 277 full_file_name)); | 257 full_file_name)); |
| 278 EXPECT_TRUE(file_util::ContentsEqual( | 258 EXPECT_TRUE(file_util::ContentsEqual( |
| 279 test_dir_.Append(FilePath(kTestDir)).AppendASCII("1.png"), | 259 test_dir_.Append(FilePath(kTestDir)).AppendASCII("1.png"), |
| 280 dir.AppendASCII("1.png"))); | 260 dir.AppendASCII("1.png"))); |
| 281 EXPECT_TRUE(file_util::ContentsEqual( | 261 EXPECT_TRUE(file_util::ContentsEqual( |
| (...skipping 12 matching lines...) Expand all Loading... |
| 294 FilePath full_file_name = save_dir_.path().AppendASCII( | 274 FilePath full_file_name = save_dir_.path().AppendASCII( |
| 295 std::string("Test page for saving page feature") + kAppendedExtension); | 275 std::string("Test page for saving page feature") + kAppendedExtension); |
| 296 FilePath dir = save_dir_.path().AppendASCII( | 276 FilePath dir = save_dir_.path().AppendASCII( |
| 297 "Test page for saving page feature_files"); | 277 "Test page for saving page feature_files"); |
| 298 ASSERT_TRUE(GetCurrentTab()->SavePage( | 278 ASSERT_TRUE(GetCurrentTab()->SavePage( |
| 299 full_file_name, dir, content::SAVE_PAGE_TYPE_AS_COMPLETE_HTML)); | 279 full_file_name, dir, content::SAVE_PAGE_TYPE_AS_COMPLETE_HTML)); |
| 300 | 280 |
| 301 EXPECT_EQ(url, WaitForSavePackageToFinish()); | 281 EXPECT_EQ(url, WaitForSavePackageToFinish()); |
| 302 | 282 |
| 303 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); | 283 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); |
| 304 CheckDownloadHistory(url, full_file_name, 3); // b.htm is 3 files. | 284 CheckDownloadHistory(url, full_file_name, 3, true); // b.htm is 3 files. |
| 305 | 285 |
| 306 EXPECT_TRUE(file_util::PathExists(full_file_name)); | 286 EXPECT_TRUE(file_util::PathExists(full_file_name)); |
| 307 EXPECT_TRUE(file_util::PathExists(dir)); | 287 EXPECT_TRUE(file_util::PathExists(dir)); |
| 308 EXPECT_TRUE(file_util::TextContentsEqual( | 288 EXPECT_TRUE(file_util::TextContentsEqual( |
| 309 test_dir_.Append(FilePath(kTestDir)).AppendASCII("b.saved2.htm"), | 289 test_dir_.Append(FilePath(kTestDir)).AppendASCII("b.saved2.htm"), |
| 310 full_file_name)); | 290 full_file_name)); |
| 311 EXPECT_TRUE(file_util::ContentsEqual( | 291 EXPECT_TRUE(file_util::ContentsEqual( |
| 312 test_dir_.Append(FilePath(kTestDir)).AppendASCII("1.png"), | 292 test_dir_.Append(FilePath(kTestDir)).AppendASCII("1.png"), |
| 313 dir.AppendASCII("1.png"))); | 293 dir.AppendASCII("1.png"))); |
| 314 EXPECT_TRUE(file_util::ContentsEqual( | 294 EXPECT_TRUE(file_util::ContentsEqual( |
| 315 test_dir_.Append(FilePath(kTestDir)).AppendASCII("1.css"), | 295 test_dir_.Append(FilePath(kTestDir)).AppendASCII("1.css"), |
| 316 dir.AppendASCII("1.css"))); | 296 dir.AppendASCII("1.css"))); |
| 317 } | 297 } |
| 318 | 298 |
| 319 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, RemoveFromList) { | 299 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, RemoveFromList) { |
| 320 GURL url = NavigateToMockURL("a"); | 300 GURL url = NavigateToMockURL("a"); |
| 321 | 301 |
| 322 FilePath full_file_name, dir; | 302 FilePath full_file_name, dir; |
| 323 GetDestinationPaths("a", &full_file_name, &dir); | 303 GetDestinationPaths("a", &full_file_name, &dir); |
| 324 ASSERT_TRUE(GetCurrentTab()->SavePage(full_file_name, dir, | 304 ASSERT_TRUE(GetCurrentTab()->SavePage(full_file_name, dir, |
| 325 content::SAVE_PAGE_TYPE_AS_ONLY_HTML)); | 305 content::SAVE_PAGE_TYPE_AS_ONLY_HTML)); |
| 326 | 306 |
| 327 EXPECT_EQ(url, WaitForSavePackageToFinish()); | 307 EXPECT_EQ(url, WaitForSavePackageToFinish()); |
| 328 | 308 |
| 329 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); | 309 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); |
| 330 CheckDownloadHistory(url, full_file_name, 1); // a.htm is 1 file. | 310 CheckDownloadHistory(url, full_file_name, 1, true); // a.htm is 1 file. |
| 331 | 311 |
| 332 EXPECT_EQ(GetDownloadManager()->RemoveAllDownloads(), 1); | 312 EXPECT_EQ(GetDownloadManager()->RemoveAllDownloads(), 1); |
| 333 | 313 |
| 334 // Should not be in history. | 314 // Should not be in history. |
| 335 QueryDownloadHistory(); | 315 QueryDownloadHistory(); |
| 336 EXPECT_EQ(std::find_if(history_entries_.begin(), history_entries_.end(), | 316 CheckDownloadHistory(url, full_file_name, 1, false); |
| 337 DownloadPersistentStoreInfoMatch(url, full_file_name, 1)), | |
| 338 history_entries_.end()); | |
| 339 | 317 |
| 340 EXPECT_TRUE(file_util::PathExists(full_file_name)); | 318 EXPECT_TRUE(file_util::PathExists(full_file_name)); |
| 341 EXPECT_FALSE(file_util::PathExists(dir)); | 319 EXPECT_FALSE(file_util::PathExists(dir)); |
| 342 EXPECT_TRUE(file_util::ContentsEqual( | 320 EXPECT_TRUE(file_util::ContentsEqual( |
| 343 test_dir_.Append(FilePath(kTestDir)).Append(FILE_PATH_LITERAL("a.htm")), | 321 test_dir_.Append(FilePath(kTestDir)).Append(FILE_PATH_LITERAL("a.htm")), |
| 344 full_file_name)); | 322 full_file_name)); |
| 345 } | 323 } |
| 346 | 324 |
| 347 // This tests that a webpage with the title "test.exe" is saved as | 325 // This tests that a webpage with the title "test.exe" is saved as |
| 348 // "test.exe.htm". | 326 // "test.exe.htm". |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 401 #if defined(OS_CHROMEOS) | 379 #if defined(OS_CHROMEOS) |
| 402 SavePackageFilePickerChromeOS::SetShouldPromptUser(false); | 380 SavePackageFilePickerChromeOS::SetShouldPromptUser(false); |
| 403 #else | 381 #else |
| 404 SavePackageFilePicker::SetShouldPromptUser(false); | 382 SavePackageFilePicker::SetShouldPromptUser(false); |
| 405 #endif | 383 #endif |
| 406 content::WindowedNotificationObserver observer( | 384 content::WindowedNotificationObserver observer( |
| 407 content::NOTIFICATION_SAVE_PACKAGE_SUCCESSFULLY_FINISHED, | 385 content::NOTIFICATION_SAVE_PACKAGE_SUCCESSFULLY_FINISHED, |
| 408 content::NotificationService::AllSources()); | 386 content::NotificationService::AllSources()); |
| 409 chrome::SavePage(browser()); | 387 chrome::SavePage(browser()); |
| 410 observer.Wait(); | 388 observer.Wait(); |
| 411 CheckDownloadHistory(url, full_file_name, -1); | 389 CheckDownloadHistory(url, full_file_name, -1, true); |
| 412 | 390 |
| 413 EXPECT_TRUE(file_util::PathExists(full_file_name)); | 391 EXPECT_TRUE(file_util::PathExists(full_file_name)); |
| 414 int64 actual_file_size = -1; | 392 int64 actual_file_size = -1; |
| 415 EXPECT_TRUE(file_util::GetFileSize(full_file_name, &actual_file_size)); | 393 EXPECT_TRUE(file_util::GetFileSize(full_file_name, &actual_file_size)); |
| 416 EXPECT_LE(kFileSizeMin, actual_file_size); | 394 EXPECT_LE(kFileSizeMin, actual_file_size); |
| 417 } | 395 } |
| OLD | NEW |