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

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

Issue 2168403003: Avoid file IO on UI thread by moving more save-page-as stuff to the FILE thread. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 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
« no previous file with comments | « no previous file | content/browser/download/save_package.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/bind_helpers.h" 12 #include "base/bind_helpers.h"
13 #include "base/command_line.h" 13 #include "base/command_line.h"
14 #include "base/files/file_path.h" 14 #include "base/files/file_path.h"
15 #include "base/files/file_util.h" 15 #include "base/files/file_util.h"
16 #include "base/files/scoped_temp_dir.h" 16 #include "base/files/scoped_temp_dir.h"
17 #include "base/macros.h" 17 #include "base/macros.h"
18 #include "base/path_service.h" 18 #include "base/path_service.h"
19 #include "base/run_loop.h" 19 #include "base/run_loop.h"
20 #include "base/strings/string_util.h" 20 #include "base/strings/string_util.h"
21 #include "base/strings/utf_string_conversions.h" 21 #include "base/strings/utf_string_conversions.h"
22 #include "base/test/test_file_util.h" 22 #include "base/test/test_file_util.h"
23 #include "base/threading/thread_restrictions.h"
23 #include "build/build_config.h" 24 #include "build/build_config.h"
24 #include "chrome/app/chrome_command_ids.h" 25 #include "chrome/app/chrome_command_ids.h"
25 #include "chrome/browser/download/chrome_download_manager_delegate.h" 26 #include "chrome/browser/download/chrome_download_manager_delegate.h"
26 #include "chrome/browser/download/download_history.h" 27 #include "chrome/browser/download/download_history.h"
27 #include "chrome/browser/download/download_prefs.h" 28 #include "chrome/browser/download/download_prefs.h"
28 #include "chrome/browser/download/download_service.h" 29 #include "chrome/browser/download/download_service.h"
29 #include "chrome/browser/download/download_service_factory.h" 30 #include "chrome/browser/download/download_service_factory.h"
30 #include "chrome/browser/download/save_package_file_picker.h" 31 #include "chrome/browser/download/save_package_file_picker.h"
31 #include "chrome/browser/net/url_request_mock_util.h" 32 #include "chrome/browser/net/url_request_mock_util.h"
32 #include "chrome/browser/profiles/profile.h" 33 #include "chrome/browser/profiles/profile.h"
(...skipping 686 matching lines...) Expand 10 before | Expand all | Expand 10 after
719 "Test page for saving page feature.mhtml")); 720 "Test page for saving page feature.mhtml"));
720 SavePackageFilePicker::SetShouldPromptUser(false); 721 SavePackageFilePicker::SetShouldPromptUser(false);
721 DownloadPersistedObserver persisted(browser()->profile(), base::Bind( 722 DownloadPersistedObserver persisted(browser()->profile(), base::Bind(
722 &DownloadStoredProperly, url, full_file_name, -1, 723 &DownloadStoredProperly, url, full_file_name, -1,
723 history::DownloadState::COMPLETE)); 724 history::DownloadState::COMPLETE));
724 scoped_refptr<content::MessageLoopRunner> loop_runner( 725 scoped_refptr<content::MessageLoopRunner> loop_runner(
725 new content::MessageLoopRunner); 726 new content::MessageLoopRunner);
726 SavePackageFinishedObserver observer( 727 SavePackageFinishedObserver observer(
727 content::BrowserContext::GetDownloadManager(browser()->profile()), 728 content::BrowserContext::GetDownloadManager(browser()->profile()),
728 loop_runner->QuitClosure()); 729 loop_runner->QuitClosure());
730 bool old_io_allowed_value = base::ThreadRestrictions::SetIOAllowed(false);
729 chrome::SavePage(browser()); 731 chrome::SavePage(browser());
730 loop_runner->Run(); 732 loop_runner->Run();
733 base::ThreadRestrictions::SetIOAllowed(old_io_allowed_value);
Łukasz Anforowicz 2016/07/26 22:30:50 I've reverted these changes in a more recent patch
731 ASSERT_TRUE(VerifySavePackageExpectations(browser(), url)); 734 ASSERT_TRUE(VerifySavePackageExpectations(browser(), url));
732 persisted.WaitForPersisted(); 735 persisted.WaitForPersisted();
733 736
734 ASSERT_TRUE(base::PathExists(full_file_name)); 737 ASSERT_TRUE(base::PathExists(full_file_name));
735 int64_t actual_file_size = -1; 738 int64_t actual_file_size = -1;
736 EXPECT_TRUE(base::GetFileSize(full_file_name, &actual_file_size)); 739 EXPECT_TRUE(base::GetFileSize(full_file_name, &actual_file_size));
737 EXPECT_LE(kFileSizeMin, actual_file_size); 740 EXPECT_LE(kFileSizeMin, actual_file_size);
738 741
739 std::string contents; 742 std::string contents;
740 EXPECT_TRUE(base::ReadFileToString(full_file_name, &contents)); 743 EXPECT_TRUE(base::ReadFileToString(full_file_name, &contents));
741 // Test for a CSS encoded character. This used to use HTML encoding. 744 // Test for a CSS encoded character. This used to use HTML encoding.
742 EXPECT_THAT(contents, HasSubstr("content: \"\\e003 \\e004 b\"")); 745 EXPECT_THAT(contents, HasSubstr("content: \"\\e003 \\e004 b\""));
743 } 746 }
744 747
745 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, SavePageBrowserTest_NonMHTML) { 748 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, SavePageBrowserTest_NonMHTML) {
746 SavePackageFilePicker::SetShouldPromptUser(false); 749 SavePackageFilePicker::SetShouldPromptUser(false);
747 GURL url("data:text/plain,foo"); 750 GURL url("data:text/plain,foo");
748 ui_test_utils::NavigateToURL(browser(), url); 751 ui_test_utils::NavigateToURL(browser(), url);
749 scoped_refptr<content::MessageLoopRunner> loop_runner( 752 scoped_refptr<content::MessageLoopRunner> loop_runner(
750 new content::MessageLoopRunner); 753 new content::MessageLoopRunner);
751 SavePackageFinishedObserver observer( 754 SavePackageFinishedObserver observer(
752 content::BrowserContext::GetDownloadManager(browser()->profile()), 755 content::BrowserContext::GetDownloadManager(browser()->profile()),
753 loop_runner->QuitClosure()); 756 loop_runner->QuitClosure());
757 bool old_io_allowed_value = base::ThreadRestrictions::SetIOAllowed(false);
754 chrome::SavePage(browser()); 758 chrome::SavePage(browser());
755 loop_runner->Run(); 759 loop_runner->Run();
760 base::ThreadRestrictions::SetIOAllowed(old_io_allowed_value);
756 base::FilePath download_dir = DownloadPrefs::FromDownloadManager( 761 base::FilePath download_dir = DownloadPrefs::FromDownloadManager(
757 GetDownloadManager())->DownloadPath(); 762 GetDownloadManager())->DownloadPath();
758 base::FilePath filename = download_dir.AppendASCII("dataurl.txt"); 763 base::FilePath filename = download_dir.AppendASCII("dataurl.txt");
759 ASSERT_TRUE(base::PathExists(filename)); 764 ASSERT_TRUE(base::PathExists(filename));
760 std::string contents; 765 std::string contents;
761 EXPECT_TRUE(base::ReadFileToString(filename, &contents)); 766 EXPECT_TRUE(base::ReadFileToString(filename, &contents));
762 EXPECT_EQ("foo", contents); 767 EXPECT_EQ("foo", contents);
763 } 768 }
764 769
765 // If a save-page-complete operation results in creating subresources that would 770 // If a save-page-complete operation results in creating subresources that would
(...skipping 489 matching lines...) Expand 10 before | Expand all | Expand 10 after
1255 TestOriginalVsSavedPage(save_page_type, url, 1, expected_substrings); 1260 TestOriginalVsSavedPage(save_page_type, url, 1, expected_substrings);
1256 } 1261 }
1257 1262
1258 INSTANTIATE_TEST_CASE_P( 1263 INSTANTIATE_TEST_CASE_P(
1259 SaveType, 1264 SaveType,
1260 SavePageOriginalVsSavedComparisonTest, 1265 SavePageOriginalVsSavedComparisonTest,
1261 ::testing::Values(content::SAVE_PAGE_TYPE_AS_COMPLETE_HTML, 1266 ::testing::Values(content::SAVE_PAGE_TYPE_AS_COMPLETE_HTML,
1262 content::SAVE_PAGE_TYPE_AS_MHTML)); 1267 content::SAVE_PAGE_TYPE_AS_MHTML));
1263 1268
1264 } // namespace 1269 } // namespace
OLDNEW
« no previous file with comments | « no previous file | content/browser/download/save_package.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698