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

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

Issue 1391423002: net: Remove FilePath version of URLRequestMockHTTPJob::GetMockUrl(). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: mmenke review Created 5 years, 2 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"
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after
294 prefs::kDownloadDefaultDirectory, save_dir_.path()); 294 prefs::kDownloadDefaultDirectory, save_dir_.path());
295 browser()->profile()->GetPrefs()->SetFilePath( 295 browser()->profile()->GetPrefs()->SetFilePath(
296 prefs::kSaveFileDefaultDirectory, save_dir_.path()); 296 prefs::kSaveFileDefaultDirectory, save_dir_.path());
297 BrowserThread::PostTask( 297 BrowserThread::PostTask(
298 BrowserThread::IO, FROM_HERE, 298 BrowserThread::IO, FROM_HERE,
299 base::Bind(&chrome_browser_net::SetUrlRequestMocksEnabled, true)); 299 base::Bind(&chrome_browser_net::SetUrlRequestMocksEnabled, true));
300 } 300 }
301 301
302 GURL NavigateToMockURL(const std::string& prefix) { 302 GURL NavigateToMockURL(const std::string& prefix) {
303 GURL url = URLRequestMockHTTPJob::GetMockUrl( 303 GURL url = URLRequestMockHTTPJob::GetMockUrl(
304 base::FilePath(kTestDir).AppendASCII(prefix + ".htm")); 304 "save_page/" + prefix + ".htm");
305 ui_test_utils::NavigateToURL(browser(), url); 305 ui_test_utils::NavigateToURL(browser(), url);
306 return url; 306 return url;
307 } 307 }
308 308
309 // Returns full paths of destination file and directory. 309 // Returns full paths of destination file and directory.
310 void GetDestinationPaths(const std::string& prefix, 310 void GetDestinationPaths(const std::string& prefix,
311 base::FilePath* full_file_name, 311 base::FilePath* full_file_name,
312 base::FilePath* dir) { 312 base::FilePath* dir) {
313 *full_file_name = save_dir_.path().AppendASCII(prefix + ".htm"); 313 *full_file_name = save_dir_.path().AppendASCII(prefix + ".htm");
314 *dir = save_dir_.path().AppendASCII(prefix + "_files"); 314 *dir = save_dir_.path().AppendASCII(prefix + "_files");
315 } 315 }
316 316
317 WebContents* GetCurrentTab(Browser* browser) const { 317 WebContents* GetCurrentTab(Browser* browser) const {
318 WebContents* current_tab = 318 WebContents* current_tab =
319 browser->tab_strip_model()->GetActiveWebContents(); 319 browser->tab_strip_model()->GetActiveWebContents();
320 EXPECT_TRUE(current_tab); 320 EXPECT_TRUE(current_tab);
321 return current_tab; 321 return current_tab;
322 } 322 }
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
503 EXPECT_FALSE(base::PathExists(dir)); 503 EXPECT_FALSE(base::PathExists(dir));
504 } 504 }
505 505
506 // Disabled on Windows due to flakiness. http://crbug.com/162323 506 // Disabled on Windows due to flakiness. http://crbug.com/162323
507 #if defined(OS_WIN) 507 #if defined(OS_WIN)
508 #define MAYBE_SaveViewSourceHTMLOnly DISABLED_SaveViewSourceHTMLOnly 508 #define MAYBE_SaveViewSourceHTMLOnly DISABLED_SaveViewSourceHTMLOnly
509 #else 509 #else
510 #define MAYBE_SaveViewSourceHTMLOnly SaveViewSourceHTMLOnly 510 #define MAYBE_SaveViewSourceHTMLOnly SaveViewSourceHTMLOnly
511 #endif 511 #endif
512 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, MAYBE_SaveViewSourceHTMLOnly) { 512 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, MAYBE_SaveViewSourceHTMLOnly) {
513 base::FilePath file_name(FILE_PATH_LITERAL("a.htm")); 513 GURL mock_url = URLRequestMockHTTPJob::GetMockUrl("save_page/a.htm");
514 GURL mock_url = URLRequestMockHTTPJob::GetMockUrl(
515 base::FilePath(kTestDir).Append(file_name));
516 GURL view_source_url = 514 GURL view_source_url =
517 GURL(content::kViewSourceScheme + std::string(":") + mock_url.spec()); 515 GURL(content::kViewSourceScheme + std::string(":") + mock_url.spec());
518 GURL actual_page_url = URLRequestMockHTTPJob::GetMockUrl( 516 GURL actual_page_url = URLRequestMockHTTPJob::GetMockUrl(
519 base::FilePath(kTestDir).Append(file_name)); 517 "save_page/a.htm");
520 ui_test_utils::NavigateToURL(browser(), view_source_url); 518 ui_test_utils::NavigateToURL(browser(), view_source_url);
521 519
522 base::FilePath full_file_name, dir; 520 base::FilePath full_file_name, dir;
523 SaveCurrentTab(actual_page_url, content::SAVE_PAGE_TYPE_AS_ONLY_HTML, "a", 1, 521 SaveCurrentTab(actual_page_url, content::SAVE_PAGE_TYPE_AS_ONLY_HTML, "a", 1,
524 &dir, &full_file_name); 522 &dir, &full_file_name);
525 ASSERT_FALSE(HasFailure()); 523 ASSERT_FALSE(HasFailure());
526 524
527 EXPECT_TRUE(base::PathExists(full_file_name)); 525 EXPECT_TRUE(base::PathExists(full_file_name));
528 EXPECT_FALSE(base::PathExists(dir)); 526 EXPECT_FALSE(base::PathExists(dir));
529 EXPECT_TRUE(base::ContentsEqual( 527 EXPECT_TRUE(base::ContentsEqual(
530 test_dir_.Append(base::FilePath(kTestDir)).Append(file_name), 528 test_dir_.Append(base::FilePath(kTestDir)).AppendASCII("a.htm"),
531 full_file_name)); 529 full_file_name));
532 } 530 }
533 531
534 // Disabled on Windows due to flakiness. http://crbug.com/162323 532 // Disabled on Windows due to flakiness. http://crbug.com/162323
535 #if defined(OS_WIN) 533 #if defined(OS_WIN)
536 #define MAYBE_SaveCompleteHTML DISABLED_SaveCompleteHTML 534 #define MAYBE_SaveCompleteHTML DISABLED_SaveCompleteHTML
537 #else 535 #else
538 #define MAYBE_SaveCompleteHTML SaveCompleteHTML 536 #define MAYBE_SaveCompleteHTML SaveCompleteHTML
539 #endif 537 #endif
540 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, DISABLED_SaveCompleteHTML) { 538 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, DISABLED_SaveCompleteHTML) {
(...skipping 29 matching lines...) Expand all
570 MAYBE_SaveDuringInitialNavigationIncognito) { 568 MAYBE_SaveDuringInitialNavigationIncognito) {
571 // Open an Incognito window. 569 // Open an Incognito window.
572 Browser* incognito = CreateIncognitoBrowser(); // Waits. 570 Browser* incognito = CreateIncognitoBrowser(); // Waits.
573 ASSERT_TRUE(incognito); 571 ASSERT_TRUE(incognito);
574 572
575 // Create a download item creation waiter on that window. 573 // Create a download item creation waiter on that window.
576 DownloadItemCreatedObserver creation_observer( 574 DownloadItemCreatedObserver creation_observer(
577 BrowserContext::GetDownloadManager(incognito->profile())); 575 BrowserContext::GetDownloadManager(incognito->profile()));
578 576
579 // Navigate, unblocking with new tab. 577 // Navigate, unblocking with new tab.
580 GURL url = URLRequestMockHTTPJob::GetMockUrl( 578 GURL url = URLRequestMockHTTPJob::GetMockUrl("save_page/b.htm");
581 base::FilePath(kTestDir).AppendASCII("b.htm"));
582 NavigateToURLWithDisposition(incognito, url, NEW_FOREGROUND_TAB, 579 NavigateToURLWithDisposition(incognito, url, NEW_FOREGROUND_TAB,
583 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); 580 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB);
584 581
585 // Save the page before completion. 582 // Save the page before completion.
586 base::FilePath full_file_name, dir; 583 base::FilePath full_file_name, dir;
587 GetDestinationPaths("b", &full_file_name, &dir); 584 GetDestinationPaths("b", &full_file_name, &dir);
588 scoped_refptr<content::MessageLoopRunner> loop_runner( 585 scoped_refptr<content::MessageLoopRunner> loop_runner(
589 new content::MessageLoopRunner); 586 new content::MessageLoopRunner);
590 SavePackageFinishedObserver observer( 587 SavePackageFinishedObserver observer(
591 content::BrowserContext::GetDownloadManager(incognito->profile()), 588 content::BrowserContext::GetDownloadManager(incognito->profile()),
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
677 EXPECT_FALSE(base::PathExists(dir)); 674 EXPECT_FALSE(base::PathExists(dir));
678 EXPECT_TRUE(base::ContentsEqual(test_dir_.Append(base::FilePath( 675 EXPECT_TRUE(base::ContentsEqual(test_dir_.Append(base::FilePath(
679 kTestDir)).Append(FILE_PATH_LITERAL("a.htm")), full_file_name)); 676 kTestDir)).Append(FILE_PATH_LITERAL("a.htm")), full_file_name));
680 } 677 }
681 678
682 // This tests that a webpage with the title "test.exe" is saved as 679 // This tests that a webpage with the title "test.exe" is saved as
683 // "test.exe.htm". 680 // "test.exe.htm".
684 // We probably don't care to handle this on Linux or Mac. 681 // We probably don't care to handle this on Linux or Mac.
685 #if defined(OS_WIN) 682 #if defined(OS_WIN)
686 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, CleanFilenameFromPageTitle) { 683 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, CleanFilenameFromPageTitle) {
687 const base::FilePath file_name(FILE_PATH_LITERAL("c.htm"));
688 base::FilePath download_dir = 684 base::FilePath download_dir =
689 DownloadPrefs::FromDownloadManager(GetDownloadManager())-> 685 DownloadPrefs::FromDownloadManager(GetDownloadManager())->
690 DownloadPath(); 686 DownloadPath();
691 base::FilePath full_file_name = 687 base::FilePath full_file_name =
692 download_dir.AppendASCII(std::string("test.exe") + kAppendedExtension); 688 download_dir.AppendASCII(std::string("test.exe") + kAppendedExtension);
693 base::FilePath dir = download_dir.AppendASCII("test.exe_files"); 689 base::FilePath dir = download_dir.AppendASCII("test.exe_files");
694 690
695 EXPECT_FALSE(base::PathExists(full_file_name)); 691 EXPECT_FALSE(base::PathExists(full_file_name));
696 GURL url = URLRequestMockHTTPJob::GetMockUrl( 692 GURL url = URLRequestMockHTTPJob::GetMockUrl("save_page/c.htm");
697 base::FilePath(kTestDir).Append(file_name));
698 ui_test_utils::NavigateToURL(browser(), url); 693 ui_test_utils::NavigateToURL(browser(), url);
699 694
700 SavePackageFilePicker::SetShouldPromptUser(false); 695 SavePackageFilePicker::SetShouldPromptUser(false);
701 scoped_refptr<content::MessageLoopRunner> loop_runner( 696 scoped_refptr<content::MessageLoopRunner> loop_runner(
702 new content::MessageLoopRunner); 697 new content::MessageLoopRunner);
703 SavePackageFinishedObserver observer( 698 SavePackageFinishedObserver observer(
704 content::BrowserContext::GetDownloadManager(browser()->profile()), 699 content::BrowserContext::GetDownloadManager(browser()->profile()),
705 loop_runner->QuitClosure()); 700 loop_runner->QuitClosure());
706 chrome::SavePage(browser()); 701 chrome::SavePage(browser());
707 loop_runner->Run(); 702 loop_runner->Run();
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
773 std::string contents; 768 std::string contents;
774 EXPECT_TRUE(base::ReadFileToString(filename, &contents)); 769 EXPECT_TRUE(base::ReadFileToString(filename, &contents));
775 EXPECT_EQ("foo", contents); 770 EXPECT_EQ("foo", contents);
776 } 771 }
777 772
778 // Test that we don't crash when the page contains an iframe that 773 // Test that we don't crash when the page contains an iframe that
779 // was handled as a download (http://crbug.com/42212). 774 // was handled as a download (http://crbug.com/42212).
780 // Flaky: https://crbug.com/537530. 775 // Flaky: https://crbug.com/537530.
781 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, DISABLED_SaveDownloadableIFrame) { 776 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, DISABLED_SaveDownloadableIFrame) {
782 GURL url = URLRequestMockHTTPJob::GetMockUrl( 777 GURL url = URLRequestMockHTTPJob::GetMockUrl(
783 base::FilePath(FILE_PATH_LITERAL("downloads")) 778 "downloads/iframe-src-is-a-download.htm");
784 .AppendASCII("iframe-src-is-a-download.htm"));
785 ui_test_utils::NavigateToURL(browser(), url); 779 ui_test_utils::NavigateToURL(browser(), url);
786 780
787 // Wait for and then dismiss the non-save-page-as-related download item 781 // Wait for and then dismiss the non-save-page-as-related download item
788 // (the one associated with downloading of "thisdayinhistory.xls" file). 782 // (the one associated with downloading of "thisdayinhistory.xls" file).
789 VerifySavePackageExpectations(browser(), url); 783 VerifySavePackageExpectations(browser(), url);
790 GetDownloadManager()->RemoveAllDownloads(); 784 GetDownloadManager()->RemoveAllDownloads();
791 785
792 base::FilePath full_file_name, dir; 786 base::FilePath full_file_name, dir;
793 SaveCurrentTab(url, content::SAVE_PAGE_TYPE_AS_COMPLETE_HTML, 787 SaveCurrentTab(url, content::SAVE_PAGE_TYPE_AS_COMPLETE_HTML,
794 "iframe-src-is-a-download", 2, &dir, &full_file_name); 788 "iframe-src-is-a-download", 2, &dir, &full_file_name);
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
866 ASSERT_TRUE(base::ReadFileToString(full_file_name, &main_contents)); 860 ASSERT_TRUE(base::ReadFileToString(full_file_name, &main_contents));
867 EXPECT_THAT(main_contents, 861 EXPECT_THAT(main_contents,
868 HasSubstr("<iframe src=\"./iframes_files/a.html\"></iframe>")); 862 HasSubstr("<iframe src=\"./iframes_files/a.html\"></iframe>"));
869 EXPECT_THAT(main_contents, 863 EXPECT_THAT(main_contents,
870 HasSubstr("<iframe src=\"./iframes_files/b.html\"></iframe>")); 864 HasSubstr("<iframe src=\"./iframes_files/b.html\"></iframe>"));
871 EXPECT_THAT(main_contents, 865 EXPECT_THAT(main_contents,
872 HasSubstr("<img src=\"./iframes_files/1.png\">")); 866 HasSubstr("<img src=\"./iframes_files/1.png\">"));
873 } 867 }
874 868
875 } // namespace 869 } // namespace
OLDNEW
« no previous file with comments | « chrome/browser/download/download_browsertest.cc ('k') | chrome/browser/errorpage_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698