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

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

Issue 2317993003: //chrome/browser and //components A-E: Change ScopedTempDir::path() to GetPath() (Closed)
Patch Set: Just rebased Created 4 years, 3 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 <stddef.h> 5 #include <stddef.h>
6 #include <stdint.h> 6 #include <stdint.h>
7 #include <string> 7 #include <string>
8 #include <utility> 8 #include <utility>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after
308 308
309 protected: 309 protected:
310 void SetUp() override { 310 void SetUp() override {
311 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_dir_)); 311 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_dir_));
312 ASSERT_TRUE(save_dir_.CreateUniqueTempDir()); 312 ASSERT_TRUE(save_dir_.CreateUniqueTempDir());
313 InProcessBrowserTest::SetUp(); 313 InProcessBrowserTest::SetUp();
314 } 314 }
315 315
316 void SetUpOnMainThread() override { 316 void SetUpOnMainThread() override {
317 browser()->profile()->GetPrefs()->SetFilePath( 317 browser()->profile()->GetPrefs()->SetFilePath(
318 prefs::kDownloadDefaultDirectory, save_dir_.path()); 318 prefs::kDownloadDefaultDirectory, save_dir_.GetPath());
319 browser()->profile()->GetPrefs()->SetFilePath( 319 browser()->profile()->GetPrefs()->SetFilePath(
320 prefs::kSaveFileDefaultDirectory, save_dir_.path()); 320 prefs::kSaveFileDefaultDirectory, save_dir_.GetPath());
321 BrowserThread::PostTask( 321 BrowserThread::PostTask(
322 BrowserThread::IO, FROM_HERE, 322 BrowserThread::IO, FROM_HERE,
323 base::Bind(&chrome_browser_net::SetUrlRequestMocksEnabled, true)); 323 base::Bind(&chrome_browser_net::SetUrlRequestMocksEnabled, true));
324 } 324 }
325 325
326 GURL NavigateToMockURL(const std::string& prefix) { 326 GURL NavigateToMockURL(const std::string& prefix) {
327 GURL url = URLRequestMockHTTPJob::GetMockUrl( 327 GURL url = URLRequestMockHTTPJob::GetMockUrl(
328 "save_page/" + prefix + ".htm"); 328 "save_page/" + prefix + ".htm");
329 ui_test_utils::NavigateToURL(browser(), url); 329 ui_test_utils::NavigateToURL(browser(), url);
330 return url; 330 return url;
331 } 331 }
332 332
333 // Returns full paths of destination file and directory. 333 // Returns full paths of destination file and directory.
334 void GetDestinationPaths(const std::string& prefix, 334 void GetDestinationPaths(const std::string& prefix,
335 base::FilePath* full_file_name, 335 base::FilePath* full_file_name,
336 base::FilePath* dir, 336 base::FilePath* dir,
337 content::SavePageType save_page_type = 337 content::SavePageType save_page_type =
338 content::SAVE_PAGE_TYPE_AS_COMPLETE_HTML) { 338 content::SAVE_PAGE_TYPE_AS_COMPLETE_HTML) {
339 std::string extension = 339 std::string extension =
340 (save_page_type == content::SAVE_PAGE_TYPE_AS_MHTML) ? ".mht" : ".htm"; 340 (save_page_type == content::SAVE_PAGE_TYPE_AS_MHTML) ? ".mht" : ".htm";
341 *full_file_name = save_dir_.path().AppendASCII(prefix + extension); 341 *full_file_name = save_dir_.GetPath().AppendASCII(prefix + extension);
342 *dir = save_dir_.path().AppendASCII(prefix + "_files"); 342 *dir = save_dir_.GetPath().AppendASCII(prefix + "_files");
343 } 343 }
344 344
345 WebContents* GetCurrentTab(Browser* browser) const { 345 WebContents* GetCurrentTab(Browser* browser) const {
346 WebContents* current_tab = 346 WebContents* current_tab =
347 browser->tab_strip_model()->GetActiveWebContents(); 347 browser->tab_strip_model()->GetActiveWebContents();
348 EXPECT_TRUE(current_tab); 348 EXPECT_TRUE(current_tab);
349 return current_tab; 349 return current_tab;
350 } 350 }
351 351
352 // Returns true if and when there was a single download created, and its url 352 // Returns true if and when there was a single download created, and its url
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after
605 } 605 }
606 606
607 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, NoSave) { 607 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, NoSave) {
608 ui_test_utils::NavigateToURL(browser(), GURL(url::kAboutBlankURL)); 608 ui_test_utils::NavigateToURL(browser(), GURL(url::kAboutBlankURL));
609 EXPECT_FALSE(chrome::CanSavePage(browser())); 609 EXPECT_FALSE(chrome::CanSavePage(browser()));
610 } 610 }
611 611
612 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, FileNameFromPageTitle) { 612 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, FileNameFromPageTitle) {
613 GURL url = NavigateToMockURL("b"); 613 GURL url = NavigateToMockURL("b");
614 614
615 base::FilePath full_file_name = save_dir_.path().AppendASCII( 615 base::FilePath full_file_name = save_dir_.GetPath().AppendASCII(
616 std::string("Test page for saving page feature") + kAppendedExtension); 616 std::string("Test page for saving page feature") + kAppendedExtension);
617 base::FilePath dir = save_dir_.path().AppendASCII( 617 base::FilePath dir = save_dir_.GetPath().AppendASCII(
618 "Test page for saving page feature_files"); 618 "Test page for saving page feature_files");
619 DownloadPersistedObserver persisted(browser()->profile(), base::Bind( 619 DownloadPersistedObserver persisted(browser()->profile(), base::Bind(
620 &DownloadStoredProperly, url, full_file_name, 3, 620 &DownloadStoredProperly, url, full_file_name, 3,
621 history::DownloadState::COMPLETE)); 621 history::DownloadState::COMPLETE));
622 scoped_refptr<content::MessageLoopRunner> loop_runner( 622 scoped_refptr<content::MessageLoopRunner> loop_runner(
623 new content::MessageLoopRunner); 623 new content::MessageLoopRunner);
624 SavePackageFinishedObserver observer( 624 SavePackageFinishedObserver observer(
625 content::BrowserContext::GetDownloadManager(browser()->profile()), 625 content::BrowserContext::GetDownloadManager(browser()->profile()),
626 loop_runner->QuitClosure()); 626 loop_runner->QuitClosure());
627 ASSERT_TRUE(GetCurrentTab(browser())->SavePage( 627 ASSERT_TRUE(GetCurrentTab(browser())->SavePage(
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
815 815
816 // Test that file: URI won't be saved when referred to from an HTTP page. 816 // Test that file: URI won't be saved when referred to from an HTTP page.
817 // See also https://crbug.com/616429. 817 // See also https://crbug.com/616429.
818 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, SaveUnauthorizedResource) { 818 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, SaveUnauthorizedResource) {
819 GURL url = NavigateToMockURL("unauthorized-access"); 819 GURL url = NavigateToMockURL("unauthorized-access");
820 820
821 // Create a test file (that the web page should not have access to). 821 // Create a test file (that the web page should not have access to).
822 base::ScopedTempDir temp_dir2; 822 base::ScopedTempDir temp_dir2;
823 ASSERT_TRUE(temp_dir2.CreateUniqueTempDir()); 823 ASSERT_TRUE(temp_dir2.CreateUniqueTempDir());
824 base::FilePath file_path = 824 base::FilePath file_path =
825 temp_dir2.path().Append(FILE_PATH_LITERAL("should-not-save.jpg")); 825 temp_dir2.GetPath().Append(FILE_PATH_LITERAL("should-not-save.jpg"));
826 std::string file_content("fake-jpg"); 826 std::string file_content("fake-jpg");
827 ASSERT_LT( 827 ASSERT_LT(
828 0, base::WriteFile(file_path, file_content.data(), file_content.size())); 828 0, base::WriteFile(file_path, file_content.data(), file_content.size()));
829 829
830 // Refer to the test file from the test page. 830 // Refer to the test file from the test page.
831 GURL file_url = net::FilePathToFileURL(file_path); 831 GURL file_url = net::FilePathToFileURL(file_path);
832 ASSERT_TRUE(ExecuteScript( 832 ASSERT_TRUE(ExecuteScript(
833 browser()->tab_strip_model()->GetWebContentsAt(0), 833 browser()->tab_strip_model()->GetWebContentsAt(0),
834 base::StringPrintf("document.getElementById('resource1').src = '%s';", 834 base::StringPrintf("document.getElementById('resource1').src = '%s';",
835 file_url.spec().data()))); 835 file_url.spec().data())));
(...skipping 481 matching lines...) Expand 10 before | Expand all | Expand 10 after
1317 TestOriginalVsSavedPage(save_page_type, url, 1, expected_substrings); 1317 TestOriginalVsSavedPage(save_page_type, url, 1, expected_substrings);
1318 } 1318 }
1319 1319
1320 INSTANTIATE_TEST_CASE_P( 1320 INSTANTIATE_TEST_CASE_P(
1321 SaveType, 1321 SaveType,
1322 SavePageOriginalVsSavedComparisonTest, 1322 SavePageOriginalVsSavedComparisonTest,
1323 ::testing::Values(content::SAVE_PAGE_TYPE_AS_COMPLETE_HTML, 1323 ::testing::Values(content::SAVE_PAGE_TYPE_AS_COMPLETE_HTML,
1324 content::SAVE_PAGE_TYPE_AS_MHTML)); 1324 content::SAVE_PAGE_TYPE_AS_MHTML));
1325 1325
1326 } // namespace 1326 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698