| 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" |
| (...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 284 std::vector<DownloadPersistentStoreInfo>* entries) { | 284 std::vector<DownloadPersistentStoreInfo>* entries) { |
| 285 history_entries_ = *entries; | 285 history_entries_ = *entries; |
| 286 | 286 |
| 287 // Indicate thet we have received the history and can continue. | 287 // Indicate thet we have received the history and can continue. |
| 288 MessageLoopForUI::current()->Quit(); | 288 MessageLoopForUI::current()->Quit(); |
| 289 } | 289 } |
| 290 | 290 |
| 291 struct DownloadPersistentStoreInfoMatch | 291 struct DownloadPersistentStoreInfoMatch |
| 292 : public std::unary_function<DownloadPersistentStoreInfo, bool> { | 292 : public std::unary_function<DownloadPersistentStoreInfo, bool> { |
| 293 | 293 |
| 294 DownloadPersistentStoreInfoMatch(const GURL& url, | 294 DownloadPersistentStoreInfoMatch(const std::vector<GURL>& url_chain, |
| 295 const FilePath& path, | 295 const FilePath& target_path, |
| 296 int64 num_files, | 296 int64 num_files, |
| 297 DownloadItem::DownloadState state) | 297 DownloadItem::DownloadState state) |
| 298 : url_(url), | 298 : url_chain_(url_chain), |
| 299 path_(path), | 299 target_path_(target_path), |
| 300 num_files_(num_files), | 300 num_files_(num_files), |
| 301 state_(state) {} | 301 state_(state) {} |
| 302 | 302 |
| 303 bool operator() (const DownloadPersistentStoreInfo& info) const { | 303 bool operator() (const DownloadPersistentStoreInfo& info) const { |
| 304 return info.url == url_ && | 304 return info.url_chain == url_chain_ && |
| 305 info.path == path_ && | 305 info.target_path == target_path_ && |
| 306 // For non-MHTML save packages, received_bytes is actually the | 306 // For non-MHTML save packages, received_bytes is actually the |
| 307 // number of files. | 307 // number of files. |
| 308 ((num_files_ < 0) || | 308 ((num_files_ < 0) || |
| 309 (info.received_bytes == num_files_)) && | 309 (info.received_bytes == num_files_)) && |
| 310 info.total_bytes == 0 && | 310 info.total_bytes == 0 && |
| 311 info.state == state_; | 311 info.state == state_; |
| 312 } | 312 } |
| 313 | 313 |
| 314 GURL url_; | 314 std::vector<GURL> url_chain_; |
| 315 FilePath path_; | 315 FilePath target_path_; |
| 316 int64 num_files_; | 316 int64 num_files_; |
| 317 DownloadItem::DownloadState state_; | 317 DownloadItem::DownloadState state_; |
| 318 }; | 318 }; |
| 319 | 319 |
| 320 void CheckDownloadHistory(const GURL& url, | 320 void CheckDownloadHistory(const GURL& url, |
| 321 const FilePath& path, | 321 const FilePath& target_path, |
| 322 int64 num_files, | 322 int64 num_files, |
| 323 DownloadItem::DownloadState state) { | 323 DownloadItem::DownloadState state) { |
| 324 // Make sure the relevant download item made it into the history. | 324 // Make sure the relevant download item made it into the history. |
| 325 std::vector<DownloadItem*> downloads; | 325 std::vector<DownloadItem*> downloads; |
| 326 GetDownloadManager()->GetAllDownloads(&downloads); | 326 GetDownloadManager()->GetAllDownloads(&downloads); |
| 327 ASSERT_EQ(1u, downloads.size()); | 327 ASSERT_EQ(1u, downloads.size()); |
| 328 | 328 |
| 329 QueryDownloadHistory(); | 329 QueryDownloadHistory(); |
| 330 | 330 |
| 331 std::vector<GURL> url_chain; |
| 332 url_chain.push_back(url); |
| 331 std::vector<DownloadPersistentStoreInfo>::iterator found = | 333 std::vector<DownloadPersistentStoreInfo>::iterator found = |
| 332 std::find_if(history_entries_.begin(), history_entries_.end(), | 334 std::find_if(history_entries_.begin(), history_entries_.end(), |
| 333 DownloadPersistentStoreInfoMatch(url, path, num_files, | 335 DownloadPersistentStoreInfoMatch( |
| 334 state)); | 336 url_chain, target_path, num_files, state)); |
| 335 | 337 |
| 336 if (found == history_entries_.end()) { | 338 if (found == history_entries_.end()) { |
| 337 LOG(ERROR) << "Missing url=" << url.spec() | 339 LOG(ERROR) << "Missing target_path=" << target_path.value() |
| 338 << " path=" << path.value() | |
| 339 << " received=" << num_files | 340 << " received=" << num_files |
| 340 << " state=" << state; | 341 << " state=" << state; |
| 341 for (size_t index = 0; index < history_entries_.size(); ++index) { | 342 for (size_t index = 0; index < history_entries_.size(); ++index) { |
| 342 LOG(ERROR) << "History@" << index << ": url=" | 343 LOG(ERROR) << "History@" << index << ": url=" |
| 343 << history_entries_[index].url.spec() | 344 << "<url chain>" |
| 344 << " path=" << history_entries_[index].path.value() | 345 << " target_path=" |
| 346 << history_entries_[index].target_path.value() |
| 345 << " received=" << history_entries_[index].received_bytes | 347 << " received=" << history_entries_[index].received_bytes |
| 346 << " total=" << history_entries_[index].total_bytes | 348 << " total=" << history_entries_[index].total_bytes |
| 347 << " state=" << history_entries_[index].state; | 349 << " state=" << history_entries_[index].state; |
| 348 } | 350 } |
| 349 EXPECT_TRUE(false); | 351 EXPECT_TRUE(false); |
| 350 } | 352 } |
| 351 } | 353 } |
| 352 | 354 |
| 353 std::vector<DownloadPersistentStoreInfo> history_entries_; | 355 std::vector<DownloadPersistentStoreInfo> history_entries_; |
| 354 | 356 |
| (...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 594 EXPECT_EQ(url, output_url); | 596 EXPECT_EQ(url, output_url); |
| 595 | 597 |
| 596 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); | 598 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); |
| 597 // a.htm is 1 file. | 599 // a.htm is 1 file. |
| 598 CheckDownloadHistory(url, full_file_name, 1, DownloadItem::COMPLETE); | 600 CheckDownloadHistory(url, full_file_name, 1, DownloadItem::COMPLETE); |
| 599 | 601 |
| 600 EXPECT_EQ(GetDownloadManager()->RemoveAllDownloads(), 1); | 602 EXPECT_EQ(GetDownloadManager()->RemoveAllDownloads(), 1); |
| 601 | 603 |
| 602 // Should not be in history. | 604 // Should not be in history. |
| 603 QueryDownloadHistory(); | 605 QueryDownloadHistory(); |
| 606 std::vector<GURL> url_chain; |
| 607 url_chain.push_back(url); |
| 604 EXPECT_EQ(std::find_if(history_entries_.begin(), history_entries_.end(), | 608 EXPECT_EQ(std::find_if(history_entries_.begin(), history_entries_.end(), |
| 605 DownloadPersistentStoreInfoMatch( | 609 DownloadPersistentStoreInfoMatch( |
| 606 url, full_file_name, 1, DownloadItem::COMPLETE)), | 610 url_chain, full_file_name, 1, |
| 611 DownloadItem::COMPLETE)), |
| 607 history_entries_.end()); | 612 history_entries_.end()); |
| 608 | 613 |
| 609 EXPECT_TRUE(file_util::PathExists(full_file_name)); | 614 EXPECT_TRUE(file_util::PathExists(full_file_name)); |
| 610 EXPECT_FALSE(file_util::PathExists(dir)); | 615 EXPECT_FALSE(file_util::PathExists(dir)); |
| 611 EXPECT_TRUE(file_util::ContentsEqual( | 616 EXPECT_TRUE(file_util::ContentsEqual( |
| 612 test_dir_.Append(FilePath(kTestDir)).Append(FILE_PATH_LITERAL("a.htm")), | 617 test_dir_.Append(FilePath(kTestDir)).Append(FILE_PATH_LITERAL("a.htm")), |
| 613 full_file_name)); | 618 full_file_name)); |
| 614 } | 619 } |
| 615 | 620 |
| 616 // This tests that a webpage with the title "test.exe" is saved as | 621 // This tests that a webpage with the title "test.exe" is saved as |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 677 ASSERT_TRUE(WaitForSavePackageToFinish(browser(), &output_url)); | 682 ASSERT_TRUE(WaitForSavePackageToFinish(browser(), &output_url)); |
| 678 EXPECT_EQ(url, output_url); | 683 EXPECT_EQ(url, output_url); |
| 679 CheckDownloadHistory(url, full_file_name, -1, DownloadItem::COMPLETE); | 684 CheckDownloadHistory(url, full_file_name, -1, DownloadItem::COMPLETE); |
| 680 | 685 |
| 681 EXPECT_TRUE(file_util::PathExists(full_file_name)); | 686 EXPECT_TRUE(file_util::PathExists(full_file_name)); |
| 682 int64 actual_file_size = -1; | 687 int64 actual_file_size = -1; |
| 683 EXPECT_TRUE(file_util::GetFileSize(full_file_name, &actual_file_size)); | 688 EXPECT_TRUE(file_util::GetFileSize(full_file_name, &actual_file_size)); |
| 684 EXPECT_LE(kFileSizeMin, actual_file_size); | 689 EXPECT_LE(kFileSizeMin, actual_file_size); |
| 685 } | 690 } |
| 686 | 691 |
| OLD | NEW |