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 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
319 int64 num_files_; | 319 int64 num_files_; |
320 DownloadItem::DownloadState state_; | 320 DownloadItem::DownloadState state_; |
321 }; | 321 }; |
322 | 322 |
323 void CheckDownloadHistory(const GURL& url, | 323 void CheckDownloadHistory(const GURL& url, |
324 const FilePath& path, | 324 const FilePath& path, |
325 int64 num_files, | 325 int64 num_files, |
326 DownloadItem::DownloadState state) { | 326 DownloadItem::DownloadState state) { |
327 // Make sure the relevant download item made it into the history. | 327 // Make sure the relevant download item made it into the history. |
328 std::vector<DownloadItem*> downloads; | 328 std::vector<DownloadItem*> downloads; |
329 GetDownloadManager()->SearchDownloads(string16(), &downloads); | 329 GetDownloadManager()->GetAllDownloads(&downloads); |
330 ASSERT_EQ(1u, downloads.size()); | 330 ASSERT_EQ(1u, downloads.size()); |
331 | 331 |
332 QueryDownloadHistory(); | 332 QueryDownloadHistory(); |
333 | 333 |
334 std::vector<DownloadPersistentStoreInfo>::iterator found = | 334 std::vector<DownloadPersistentStoreInfo>::iterator found = |
335 std::find_if(history_entries_.begin(), history_entries_.end(), | 335 std::find_if(history_entries_.begin(), history_entries_.end(), |
336 DownloadPersistentStoreInfoMatch(url, path, num_files, | 336 DownloadPersistentStoreInfoMatch(url, path, num_files, |
337 state)); | 337 state)); |
338 | 338 |
339 if (found == history_entries_.end()) { | 339 if (found == history_entries_.end()) { |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
389 EXPECT_FALSE(file_util::PathExists(dir)); | 389 EXPECT_FALSE(file_util::PathExists(dir)); |
390 EXPECT_TRUE(file_util::ContentsEqual( | 390 EXPECT_TRUE(file_util::ContentsEqual( |
391 test_dir_.Append(FilePath(kTestDir)).Append(FILE_PATH_LITERAL("a.htm")), | 391 test_dir_.Append(FilePath(kTestDir)).Append(FILE_PATH_LITERAL("a.htm")), |
392 full_file_name)); | 392 full_file_name)); |
393 } | 393 } |
394 | 394 |
395 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, SaveHTMLOnlyCancel) { | 395 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, SaveHTMLOnlyCancel) { |
396 GURL url = NavigateToMockURL("a"); | 396 GURL url = NavigateToMockURL("a"); |
397 DownloadManager* manager(GetDownloadManager()); | 397 DownloadManager* manager(GetDownloadManager()); |
398 std::vector<DownloadItem*> downloads; | 398 std::vector<DownloadItem*> downloads; |
399 manager->SearchDownloads(string16(), &downloads); | 399 manager->GetAllDownloads(&downloads); |
400 ASSERT_EQ(0u, downloads.size()); | 400 ASSERT_EQ(0u, downloads.size()); |
401 | 401 |
402 FilePath full_file_name, dir; | 402 FilePath full_file_name, dir; |
403 GetDestinationPaths("a", &full_file_name, &dir); | 403 GetDestinationPaths("a", &full_file_name, &dir); |
404 DownloadItemCreatedObserver creation_observer(manager); | 404 DownloadItemCreatedObserver creation_observer(manager); |
405 ASSERT_TRUE(GetCurrentTab()->SavePage(full_file_name, dir, | 405 ASSERT_TRUE(GetCurrentTab()->SavePage(full_file_name, dir, |
406 content::SAVE_PAGE_TYPE_AS_ONLY_HTML)); | 406 content::SAVE_PAGE_TYPE_AS_ONLY_HTML)); |
407 std::vector<DownloadItem*> items; | 407 std::vector<DownloadItem*> items; |
408 creation_observer.WaitForDownloadItem(&items); | 408 creation_observer.WaitForDownloadItem(&items); |
409 ASSERT_TRUE(items.size() == 1); | 409 ASSERT_TRUE(items.size() == 1); |
(...skipping 18 matching lines...) Expand all Loading... |
428 test_dir_.Append(FilePath(kTestDir)).Append(FILE_PATH_LITERAL("a.htm")), | 428 test_dir_.Append(FilePath(kTestDir)).Append(FILE_PATH_LITERAL("a.htm")), |
429 full_file_name)); | 429 full_file_name)); |
430 } | 430 } |
431 | 431 |
432 // SavePageBrowserTest.SaveHTMLOnlyTabDestroy is flaky. | 432 // SavePageBrowserTest.SaveHTMLOnlyTabDestroy is flaky. |
433 // See http://crbug.com/144751. | 433 // See http://crbug.com/144751. |
434 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, DISABLED_SaveHTMLOnlyTabDestroy) { | 434 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, DISABLED_SaveHTMLOnlyTabDestroy) { |
435 GURL url = NavigateToMockURL("a"); | 435 GURL url = NavigateToMockURL("a"); |
436 DownloadManager* manager(GetDownloadManager()); | 436 DownloadManager* manager(GetDownloadManager()); |
437 std::vector<DownloadItem*> downloads; | 437 std::vector<DownloadItem*> downloads; |
438 manager->SearchDownloads(string16(), &downloads); | 438 manager->GetAllDownloads(&downloads); |
439 ASSERT_EQ(0u, downloads.size()); | 439 ASSERT_EQ(0u, downloads.size()); |
440 | 440 |
441 FilePath full_file_name, dir; | 441 FilePath full_file_name, dir; |
442 GetDestinationPaths("a", &full_file_name, &dir); | 442 GetDestinationPaths("a", &full_file_name, &dir); |
443 DownloadItemCreatedObserver creation_observer(manager); | 443 DownloadItemCreatedObserver creation_observer(manager); |
444 ASSERT_TRUE(GetCurrentTab()->SavePage(full_file_name, dir, | 444 ASSERT_TRUE(GetCurrentTab()->SavePage(full_file_name, dir, |
445 content::SAVE_PAGE_TYPE_AS_ONLY_HTML)); | 445 content::SAVE_PAGE_TYPE_AS_ONLY_HTML)); |
446 std::vector<DownloadItem*> items; | 446 std::vector<DownloadItem*> items; |
447 creation_observer.WaitForDownloadItem(&items); | 447 creation_observer.WaitForDownloadItem(&items); |
448 ASSERT_TRUE(items.size() == 1); | 448 ASSERT_TRUE(items.size() == 1); |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
645 content::NotificationService::AllSources()); | 645 content::NotificationService::AllSources()); |
646 chrome::SavePage(browser()); | 646 chrome::SavePage(browser()); |
647 observer.Wait(); | 647 observer.Wait(); |
648 CheckDownloadHistory(url, full_file_name, -1, DownloadItem::COMPLETE); | 648 CheckDownloadHistory(url, full_file_name, -1, DownloadItem::COMPLETE); |
649 | 649 |
650 EXPECT_TRUE(file_util::PathExists(full_file_name)); | 650 EXPECT_TRUE(file_util::PathExists(full_file_name)); |
651 int64 actual_file_size = -1; | 651 int64 actual_file_size = -1; |
652 EXPECT_TRUE(file_util::GetFileSize(full_file_name, &actual_file_size)); | 652 EXPECT_TRUE(file_util::GetFileSize(full_file_name, &actual_file_size)); |
653 EXPECT_LE(kFileSizeMin, actual_file_size); | 653 EXPECT_LE(kFileSizeMin, actual_file_size); |
654 } | 654 } |
OLD | NEW |