Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(109)

Side by Side Diff: chrome/browser/download/save_page_browsertest.cc

Issue 833033002: Remove dependency on //content from history DownloadDatabase (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add missing conversion Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/files/file_path.h" 8 #include "base/files/file_path.h"
9 #include "base/files/file_util.h" 9 #include "base/files/file_util.h"
10 #include "base/files/scoped_temp_dir.h" 10 #include "base/files/scoped_temp_dir.h"
11 #include "base/path_service.h" 11 #include "base/path_service.h"
12 #include "base/prefs/pref_member.h" 12 #include "base/prefs/pref_member.h"
13 #include "base/prefs/pref_service.h" 13 #include "base/prefs/pref_service.h"
14 #include "base/test/test_file_util.h" 14 #include "base/test/test_file_util.h"
15 #include "chrome/app/chrome_command_ids.h" 15 #include "chrome/app/chrome_command_ids.h"
16 #include "chrome/browser/download/chrome_download_manager_delegate.h" 16 #include "chrome/browser/download/chrome_download_manager_delegate.h"
17 #include "chrome/browser/download/download_history.h" 17 #include "chrome/browser/download/download_history.h"
18 #include "chrome/browser/download/download_prefs.h" 18 #include "chrome/browser/download/download_prefs.h"
19 #include "chrome/browser/download/download_service.h" 19 #include "chrome/browser/download/download_service.h"
20 #include "chrome/browser/download/download_service_factory.h" 20 #include "chrome/browser/download/download_service_factory.h"
21 #include "chrome/browser/download/save_package_file_picker.h" 21 #include "chrome/browser/download/save_package_file_picker.h"
22 #include "chrome/browser/history/download_row.h"
23 #include "chrome/browser/net/url_request_mock_util.h" 22 #include "chrome/browser/net/url_request_mock_util.h"
24 #include "chrome/browser/profiles/profile.h" 23 #include "chrome/browser/profiles/profile.h"
25 #include "chrome/browser/ui/browser.h" 24 #include "chrome/browser/ui/browser.h"
26 #include "chrome/browser/ui/browser_commands.h" 25 #include "chrome/browser/ui/browser_commands.h"
27 #include "chrome/browser/ui/browser_window.h" 26 #include "chrome/browser/ui/browser_window.h"
28 #include "chrome/browser/ui/tabs/tab_strip_model.h" 27 #include "chrome/browser/ui/tabs/tab_strip_model.h"
29 #include "chrome/common/chrome_paths.h" 28 #include "chrome/common/chrome_paths.h"
30 #include "chrome/common/chrome_switches.h" 29 #include "chrome/common/chrome_switches.h"
31 #include "chrome/common/pref_names.h" 30 #include "chrome/common/pref_names.h"
32 #include "chrome/common/url_constants.h" 31 #include "chrome/common/url_constants.h"
33 #include "chrome/test/base/in_process_browser_test.h" 32 #include "chrome/test/base/in_process_browser_test.h"
34 #include "chrome/test/base/ui_test_utils.h" 33 #include "chrome/test/base/ui_test_utils.h"
34 #include "components/history/core/browser/download_constants.h"
35 #include "components/history/core/browser/download_row.h"
35 #include "content/public/browser/download_item.h" 36 #include "content/public/browser/download_item.h"
36 #include "content/public/browser/download_manager.h" 37 #include "content/public/browser/download_manager.h"
37 #include "content/public/browser/notification_service.h" 38 #include "content/public/browser/notification_service.h"
38 #include "content/public/browser/notification_types.h" 39 #include "content/public/browser/notification_types.h"
39 #include "content/public/browser/web_contents.h" 40 #include "content/public/browser/web_contents.h"
40 #include "content/public/common/url_constants.h" 41 #include "content/public/common/url_constants.h"
41 #include "content/public/test/test_utils.h" 42 #include "content/public/test/test_utils.h"
42 #include "net/test/url_request/url_request_mock_http_job.h" 43 #include "net/test/url_request/url_request_mock_http_job.h"
43 #include "testing/gtest/include/gtest/gtest.h" 44 #include "testing/gtest/include/gtest/gtest.h"
44 45
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 bool waiting_; 135 bool waiting_;
135 int32 download_id_; 136 int32 download_id_;
136 137
137 DISALLOW_COPY_AND_ASSIGN(DownloadRemovedObserver); 138 DISALLOW_COPY_AND_ASSIGN(DownloadRemovedObserver);
138 }; 139 };
139 140
140 bool DownloadStoredProperly( 141 bool DownloadStoredProperly(
141 const GURL& expected_url, 142 const GURL& expected_url,
142 const base::FilePath& expected_path, 143 const base::FilePath& expected_path,
143 int64 num_files, 144 int64 num_files,
144 DownloadItem::DownloadState expected_state, 145 history::DownloadState expected_state,
145 DownloadItem* item, 146 DownloadItem* item,
146 const history::DownloadRow& info) { 147 const history::DownloadRow& info) {
147 // This function may be called multiple times for a given test. Returning 148 // This function may be called multiple times for a given test. Returning
148 // false doesn't necessarily mean that the test has failed or will fail, it 149 // false doesn't necessarily mean that the test has failed or will fail, it
149 // might just mean that the test hasn't passed yet. 150 // might just mean that the test hasn't passed yet.
150 if (info.target_path != expected_path) { 151 if (info.target_path != expected_path) {
151 DVLOG(20) << __FUNCTION__ << " " << info.target_path.value() 152 DVLOG(20) << __FUNCTION__ << " " << info.target_path.value()
152 << " != " << expected_path.value(); 153 << " != " << expected_path.value();
153 return false; 154 return false;
154 } 155 }
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
376 #else 377 #else
377 #define MAYBE_SaveHTMLOnly SaveHTMLOnly 378 #define MAYBE_SaveHTMLOnly SaveHTMLOnly
378 #endif 379 #endif
379 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, MAYBE_SaveHTMLOnly) { 380 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, MAYBE_SaveHTMLOnly) {
380 GURL url = NavigateToMockURL("a"); 381 GURL url = NavigateToMockURL("a");
381 382
382 base::FilePath full_file_name, dir; 383 base::FilePath full_file_name, dir;
383 GetDestinationPaths("a", &full_file_name, &dir); 384 GetDestinationPaths("a", &full_file_name, &dir);
384 DownloadPersistedObserver persisted(browser()->profile(), base::Bind( 385 DownloadPersistedObserver persisted(browser()->profile(), base::Bind(
385 &DownloadStoredProperly, url, full_file_name, 1, 386 &DownloadStoredProperly, url, full_file_name, 1,
386 DownloadItem::COMPLETE)); 387 history::DownloadState::COMPLETE));
387 scoped_refptr<content::MessageLoopRunner> loop_runner( 388 scoped_refptr<content::MessageLoopRunner> loop_runner(
388 new content::MessageLoopRunner); 389 new content::MessageLoopRunner);
389 SavePackageFinishedObserver observer( 390 SavePackageFinishedObserver observer(
390 content::BrowserContext::GetDownloadManager(browser()->profile()), 391 content::BrowserContext::GetDownloadManager(browser()->profile()),
391 loop_runner->QuitClosure()); 392 loop_runner->QuitClosure());
392 ASSERT_TRUE(GetCurrentTab(browser())->SavePage(full_file_name, dir, 393 ASSERT_TRUE(GetCurrentTab(browser())->SavePage(full_file_name, dir,
393 content::SAVE_PAGE_TYPE_AS_ONLY_HTML)); 394 content::SAVE_PAGE_TYPE_AS_ONLY_HTML));
394 loop_runner->Run(); 395 loop_runner->Run();
395 ASSERT_TRUE(VerifySavePackageExpectations(browser(), url)); 396 ASSERT_TRUE(VerifySavePackageExpectations(browser(), url));
396 persisted.WaitForPersisted(); 397 persisted.WaitForPersisted();
(...skipping 10 matching lines...) Expand all
407 DownloadManager* manager(GetDownloadManager()); 408 DownloadManager* manager(GetDownloadManager());
408 std::vector<DownloadItem*> downloads; 409 std::vector<DownloadItem*> downloads;
409 manager->GetAllDownloads(&downloads); 410 manager->GetAllDownloads(&downloads);
410 ASSERT_EQ(0u, downloads.size()); 411 ASSERT_EQ(0u, downloads.size());
411 412
412 base::FilePath full_file_name, dir; 413 base::FilePath full_file_name, dir;
413 GetDestinationPaths("a", &full_file_name, &dir); 414 GetDestinationPaths("a", &full_file_name, &dir);
414 DownloadItemCreatedObserver creation_observer(manager); 415 DownloadItemCreatedObserver creation_observer(manager);
415 DownloadPersistedObserver persisted(browser()->profile(), base::Bind( 416 DownloadPersistedObserver persisted(browser()->profile(), base::Bind(
416 &DownloadStoredProperly, url, full_file_name, -1, 417 &DownloadStoredProperly, url, full_file_name, -1,
417 DownloadItem::CANCELLED)); 418 history::DownloadState::CANCELLED));
418 // -1 to disable number of files check; we don't update after cancel, and 419 // -1 to disable number of files check; we don't update after cancel, and
419 // we don't know when the single file completed in relationship to 420 // we don't know when the single file completed in relationship to
420 // the cancel. 421 // the cancel.
421 422
422 ASSERT_TRUE(GetCurrentTab(browser())->SavePage(full_file_name, dir, 423 ASSERT_TRUE(GetCurrentTab(browser())->SavePage(full_file_name, dir,
423 content::SAVE_PAGE_TYPE_AS_ONLY_HTML)); 424 content::SAVE_PAGE_TYPE_AS_ONLY_HTML));
424 std::vector<DownloadItem*> items; 425 std::vector<DownloadItem*> items;
425 creation_observer.WaitForDownloadItem(&items); 426 creation_observer.WaitForDownloadItem(&items);
426 ASSERT_EQ(1UL, items.size()); 427 ASSERT_EQ(1UL, items.size());
427 ASSERT_EQ(url.spec(), items[0]->GetOriginalUrl().spec()); 428 ASSERT_EQ(url.spec(), items[0]->GetOriginalUrl().spec());
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
503 GURL view_source_url = 504 GURL view_source_url =
504 GURL(content::kViewSourceScheme + std::string(":") + mock_url.spec()); 505 GURL(content::kViewSourceScheme + std::string(":") + mock_url.spec());
505 GURL actual_page_url = URLRequestMockHTTPJob::GetMockUrl( 506 GURL actual_page_url = URLRequestMockHTTPJob::GetMockUrl(
506 base::FilePath(kTestDir).Append(file_name)); 507 base::FilePath(kTestDir).Append(file_name));
507 ui_test_utils::NavigateToURL(browser(), view_source_url); 508 ui_test_utils::NavigateToURL(browser(), view_source_url);
508 509
509 base::FilePath full_file_name, dir; 510 base::FilePath full_file_name, dir;
510 GetDestinationPaths("a", &full_file_name, &dir); 511 GetDestinationPaths("a", &full_file_name, &dir);
511 DownloadPersistedObserver persisted(browser()->profile(), base::Bind( 512 DownloadPersistedObserver persisted(browser()->profile(), base::Bind(
512 &DownloadStoredProperly, actual_page_url, full_file_name, 1, 513 &DownloadStoredProperly, actual_page_url, full_file_name, 1,
513 DownloadItem::COMPLETE)); 514 history::DownloadState::COMPLETE));
514 scoped_refptr<content::MessageLoopRunner> loop_runner( 515 scoped_refptr<content::MessageLoopRunner> loop_runner(
515 new content::MessageLoopRunner); 516 new content::MessageLoopRunner);
516 SavePackageFinishedObserver observer( 517 SavePackageFinishedObserver observer(
517 content::BrowserContext::GetDownloadManager(browser()->profile()), 518 content::BrowserContext::GetDownloadManager(browser()->profile()),
518 loop_runner->QuitClosure()); 519 loop_runner->QuitClosure());
519 ASSERT_TRUE(GetCurrentTab(browser())->SavePage(full_file_name, dir, 520 ASSERT_TRUE(GetCurrentTab(browser())->SavePage(full_file_name, dir,
520 content::SAVE_PAGE_TYPE_AS_ONLY_HTML)); 521 content::SAVE_PAGE_TYPE_AS_ONLY_HTML));
521 loop_runner->Run(); 522 loop_runner->Run();
522 ASSERT_TRUE(VerifySavePackageExpectations(browser(), actual_page_url)); 523 ASSERT_TRUE(VerifySavePackageExpectations(browser(), actual_page_url));
523 persisted.WaitForPersisted(); 524 persisted.WaitForPersisted();
(...skipping 13 matching lines...) Expand all
537 #else 538 #else
538 #define MAYBE_SaveCompleteHTML SaveCompleteHTML 539 #define MAYBE_SaveCompleteHTML SaveCompleteHTML
539 #endif 540 #endif
540 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, MAYBE_SaveCompleteHTML) { 541 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, MAYBE_SaveCompleteHTML) {
541 GURL url = NavigateToMockURL("b"); 542 GURL url = NavigateToMockURL("b");
542 543
543 base::FilePath full_file_name, dir; 544 base::FilePath full_file_name, dir;
544 GetDestinationPaths("b", &full_file_name, &dir); 545 GetDestinationPaths("b", &full_file_name, &dir);
545 DownloadPersistedObserver persisted(browser()->profile(), base::Bind( 546 DownloadPersistedObserver persisted(browser()->profile(), base::Bind(
546 &DownloadStoredProperly, url, full_file_name, 3, 547 &DownloadStoredProperly, url, full_file_name, 3,
547 DownloadItem::COMPLETE)); 548 history::DownloadState::COMPLETE));
548 scoped_refptr<content::MessageLoopRunner> loop_runner( 549 scoped_refptr<content::MessageLoopRunner> loop_runner(
549 new content::MessageLoopRunner); 550 new content::MessageLoopRunner);
550 SavePackageFinishedObserver observer( 551 SavePackageFinishedObserver observer(
551 content::BrowserContext::GetDownloadManager(browser()->profile()), 552 content::BrowserContext::GetDownloadManager(browser()->profile()),
552 loop_runner->QuitClosure()); 553 loop_runner->QuitClosure());
553 ASSERT_TRUE(GetCurrentTab(browser())->SavePage( 554 ASSERT_TRUE(GetCurrentTab(browser())->SavePage(
554 full_file_name, dir, content::SAVE_PAGE_TYPE_AS_COMPLETE_HTML)); 555 full_file_name, dir, content::SAVE_PAGE_TYPE_AS_COMPLETE_HTML));
555 loop_runner->Run(); 556 loop_runner->Run();
556 ASSERT_TRUE(VerifySavePackageExpectations(browser(), url)); 557 ASSERT_TRUE(VerifySavePackageExpectations(browser(), url));
557 persisted.WaitForPersisted(); 558 persisted.WaitForPersisted();
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
632 #endif 633 #endif
633 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, MAYBE_FileNameFromPageTitle) { 634 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, MAYBE_FileNameFromPageTitle) {
634 GURL url = NavigateToMockURL("b"); 635 GURL url = NavigateToMockURL("b");
635 636
636 base::FilePath full_file_name = save_dir_.path().AppendASCII( 637 base::FilePath full_file_name = save_dir_.path().AppendASCII(
637 std::string("Test page for saving page feature") + kAppendedExtension); 638 std::string("Test page for saving page feature") + kAppendedExtension);
638 base::FilePath dir = save_dir_.path().AppendASCII( 639 base::FilePath dir = save_dir_.path().AppendASCII(
639 "Test page for saving page feature_files"); 640 "Test page for saving page feature_files");
640 DownloadPersistedObserver persisted(browser()->profile(), base::Bind( 641 DownloadPersistedObserver persisted(browser()->profile(), base::Bind(
641 &DownloadStoredProperly, url, full_file_name, 3, 642 &DownloadStoredProperly, url, full_file_name, 3,
642 DownloadItem::COMPLETE)); 643 history::DownloadState::COMPLETE));
643 scoped_refptr<content::MessageLoopRunner> loop_runner( 644 scoped_refptr<content::MessageLoopRunner> loop_runner(
644 new content::MessageLoopRunner); 645 new content::MessageLoopRunner);
645 SavePackageFinishedObserver observer( 646 SavePackageFinishedObserver observer(
646 content::BrowserContext::GetDownloadManager(browser()->profile()), 647 content::BrowserContext::GetDownloadManager(browser()->profile()),
647 loop_runner->QuitClosure()); 648 loop_runner->QuitClosure());
648 ASSERT_TRUE(GetCurrentTab(browser())->SavePage( 649 ASSERT_TRUE(GetCurrentTab(browser())->SavePage(
649 full_file_name, dir, content::SAVE_PAGE_TYPE_AS_COMPLETE_HTML)); 650 full_file_name, dir, content::SAVE_PAGE_TYPE_AS_COMPLETE_HTML));
650 651
651 loop_runner->Run(); 652 loop_runner->Run();
652 ASSERT_TRUE(VerifySavePackageExpectations(browser(), url)); 653 ASSERT_TRUE(VerifySavePackageExpectations(browser(), url));
(...skipping 20 matching lines...) Expand all
673 #else 674 #else
674 #define MAYBE_RemoveFromList RemoveFromList 675 #define MAYBE_RemoveFromList RemoveFromList
675 #endif 676 #endif
676 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, MAYBE_RemoveFromList) { 677 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, MAYBE_RemoveFromList) {
677 GURL url = NavigateToMockURL("a"); 678 GURL url = NavigateToMockURL("a");
678 679
679 base::FilePath full_file_name, dir; 680 base::FilePath full_file_name, dir;
680 GetDestinationPaths("a", &full_file_name, &dir); 681 GetDestinationPaths("a", &full_file_name, &dir);
681 DownloadPersistedObserver persisted(browser()->profile(), base::Bind( 682 DownloadPersistedObserver persisted(browser()->profile(), base::Bind(
682 &DownloadStoredProperly, url, full_file_name, 1, 683 &DownloadStoredProperly, url, full_file_name, 1,
683 DownloadItem::COMPLETE)); 684 history::DownloadState::COMPLETE));
684 scoped_refptr<content::MessageLoopRunner> loop_runner( 685 scoped_refptr<content::MessageLoopRunner> loop_runner(
685 new content::MessageLoopRunner); 686 new content::MessageLoopRunner);
686 SavePackageFinishedObserver observer( 687 SavePackageFinishedObserver observer(
687 content::BrowserContext::GetDownloadManager(browser()->profile()), 688 content::BrowserContext::GetDownloadManager(browser()->profile()),
688 loop_runner->QuitClosure()); 689 loop_runner->QuitClosure());
689 ASSERT_TRUE(GetCurrentTab(browser())->SavePage(full_file_name, dir, 690 ASSERT_TRUE(GetCurrentTab(browser())->SavePage(full_file_name, dir,
690 content::SAVE_PAGE_TYPE_AS_ONLY_HTML)); 691 content::SAVE_PAGE_TYPE_AS_ONLY_HTML));
691 692
692 loop_runner->Run(); 693 loop_runner->Run();
693 ASSERT_TRUE(VerifySavePackageExpectations(browser(), url)); 694 ASSERT_TRUE(VerifySavePackageExpectations(browser(), url));
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
763 IN_PROC_BROWSER_TEST_F(SavePageAsMHTMLBrowserTest, SavePageAsMHTML) { 764 IN_PROC_BROWSER_TEST_F(SavePageAsMHTMLBrowserTest, SavePageAsMHTML) {
764 static const int64 kFileSizeMin = 2758; 765 static const int64 kFileSizeMin = 2758;
765 GURL url = NavigateToMockURL("b"); 766 GURL url = NavigateToMockURL("b");
766 base::FilePath download_dir = DownloadPrefs::FromDownloadManager( 767 base::FilePath download_dir = DownloadPrefs::FromDownloadManager(
767 GetDownloadManager())->DownloadPath(); 768 GetDownloadManager())->DownloadPath();
768 base::FilePath full_file_name = download_dir.AppendASCII(std::string( 769 base::FilePath full_file_name = download_dir.AppendASCII(std::string(
769 "Test page for saving page feature.mhtml")); 770 "Test page for saving page feature.mhtml"));
770 SavePackageFilePicker::SetShouldPromptUser(false); 771 SavePackageFilePicker::SetShouldPromptUser(false);
771 DownloadPersistedObserver persisted(browser()->profile(), base::Bind( 772 DownloadPersistedObserver persisted(browser()->profile(), base::Bind(
772 &DownloadStoredProperly, url, full_file_name, -1, 773 &DownloadStoredProperly, url, full_file_name, -1,
773 DownloadItem::COMPLETE)); 774 history::DownloadState::COMPLETE));
774 scoped_refptr<content::MessageLoopRunner> loop_runner( 775 scoped_refptr<content::MessageLoopRunner> loop_runner(
775 new content::MessageLoopRunner); 776 new content::MessageLoopRunner);
776 SavePackageFinishedObserver observer( 777 SavePackageFinishedObserver observer(
777 content::BrowserContext::GetDownloadManager(browser()->profile()), 778 content::BrowserContext::GetDownloadManager(browser()->profile()),
778 loop_runner->QuitClosure()); 779 loop_runner->QuitClosure());
779 chrome::SavePage(browser()); 780 chrome::SavePage(browser());
780 loop_runner->Run(); 781 loop_runner->Run();
781 ASSERT_TRUE(VerifySavePackageExpectations(browser(), url)); 782 ASSERT_TRUE(VerifySavePackageExpectations(browser(), url));
782 persisted.WaitForPersisted(); 783 persisted.WaitForPersisted();
783 784
(...skipping 17 matching lines...) Expand all
801 base::FilePath download_dir = DownloadPrefs::FromDownloadManager( 802 base::FilePath download_dir = DownloadPrefs::FromDownloadManager(
802 GetDownloadManager())->DownloadPath(); 803 GetDownloadManager())->DownloadPath();
803 base::FilePath filename = download_dir.AppendASCII("dataurl.txt"); 804 base::FilePath filename = download_dir.AppendASCII("dataurl.txt");
804 ASSERT_TRUE(base::PathExists(filename)); 805 ASSERT_TRUE(base::PathExists(filename));
805 std::string contents; 806 std::string contents;
806 EXPECT_TRUE(base::ReadFileToString(filename, &contents)); 807 EXPECT_TRUE(base::ReadFileToString(filename, &contents));
807 EXPECT_EQ("foo", contents); 808 EXPECT_EQ("foo", contents);
808 } 809 }
809 810
810 } // namespace 811 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698