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

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

Issue 1386873003: OOPIFs: Transitioning MHTML generation from view-oriented to frame-oriented. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@mhtml-generation-mgr-cleanup
Patch Set: Moving "using" declaration under a singly-included section of frame_messges.h Created 5 years 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/mhtml_generation_manager.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 <string> 5 #include <string>
6 #include <vector> 6 #include <vector>
7 7
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/bind_helpers.h" 9 #include "base/bind_helpers.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
11 #include "base/files/file_path.h" 11 #include "base/files/file_path.h"
12 #include "base/files/file_util.h" 12 #include "base/files/file_util.h"
13 #include "base/files/scoped_temp_dir.h" 13 #include "base/files/scoped_temp_dir.h"
14 #include "base/path_service.h" 14 #include "base/path_service.h"
15 #include "base/prefs/pref_member.h" 15 #include "base/prefs/pref_member.h"
16 #include "base/prefs/pref_service.h" 16 #include "base/prefs/pref_service.h"
17 #include "base/run_loop.h" 17 #include "base/run_loop.h"
18 #include "base/strings/string_split.h" 18 #include "base/strings/string_util.h"
19 #include "base/strings/utf_string_conversions.h" 19 #include "base/strings/utf_string_conversions.h"
20 #include "base/test/test_file_util.h" 20 #include "base/test/test_file_util.h"
21 #include "chrome/app/chrome_command_ids.h" 21 #include "chrome/app/chrome_command_ids.h"
22 #include "chrome/browser/download/chrome_download_manager_delegate.h" 22 #include "chrome/browser/download/chrome_download_manager_delegate.h"
23 #include "chrome/browser/download/download_history.h" 23 #include "chrome/browser/download/download_history.h"
24 #include "chrome/browser/download/download_prefs.h" 24 #include "chrome/browser/download/download_prefs.h"
25 #include "chrome/browser/download/download_service.h" 25 #include "chrome/browser/download/download_service.h"
26 #include "chrome/browser/download/download_service_factory.h" 26 #include "chrome/browser/download/download_service_factory.h"
27 #include "chrome/browser/download/save_package_file_picker.h" 27 #include "chrome/browser/download/save_package_file_picker.h"
28 #include "chrome/browser/net/url_request_mock_util.h" 28 #include "chrome/browser/net/url_request_mock_util.h"
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 68
69 // Returns file contents with each continuous run of whitespace replaced by a 69 // Returns file contents with each continuous run of whitespace replaced by a
70 // single space. 70 // single space.
71 std::string ReadFileAndCollapseWhitespace(const base::FilePath& file_path) { 71 std::string ReadFileAndCollapseWhitespace(const base::FilePath& file_path) {
72 std::string file_contents; 72 std::string file_contents;
73 if (!base::ReadFileToString(file_path, &file_contents)) { 73 if (!base::ReadFileToString(file_path, &file_contents)) {
74 ADD_FAILURE() << "Failed to read \"" << file_path.value() << "\" file."; 74 ADD_FAILURE() << "Failed to read \"" << file_path.value() << "\" file.";
75 return std::string(); 75 return std::string();
76 } 76 }
77 77
78 std::vector<std::string> words = 78 return base::CollapseWhitespaceASCII(file_contents, false);
79 base::SplitString(file_contents, " \t\r\n", base::TRIM_WHITESPACE,
80 base::SPLIT_WANT_NONEMPTY);
81
82 return base::JoinString(words, " ");
83 } 79 }
84 80
85 // Waits for an item record in the downloads database to match |filter|. See 81 // Waits for an item record in the downloads database to match |filter|. See
86 // DownloadStoredProperly() below for an example filter. 82 // DownloadStoredProperly() below for an example filter.
87 class DownloadPersistedObserver : public DownloadHistory::Observer { 83 class DownloadPersistedObserver : public DownloadHistory::Observer {
88 public: 84 public:
89 typedef base::Callback<bool( 85 typedef base::Callback<bool(
90 DownloadItem* item, 86 DownloadItem* item,
91 const history::DownloadRow&)> PersistedFilter; 87 const history::DownloadRow&)> PersistedFilter;
92 88
(...skipping 765 matching lines...) Expand 10 before | Expand all | Expand 10 after
858 ASSERT_TRUE(base::ReadFileToString(dir.AppendASCII("a.html"), &a_contents)); 854 ASSERT_TRUE(base::ReadFileToString(dir.AppendASCII("a.html"), &a_contents));
859 EXPECT_THAT(a_contents, 855 EXPECT_THAT(a_contents,
860 HasSubstr("a.htm: 1b8aae2b-e164-462f-bd5b-98aa366205f2")); 856 HasSubstr("a.htm: 1b8aae2b-e164-462f-bd5b-98aa366205f2"));
861 std::string b_contents; 857 std::string b_contents;
862 ASSERT_TRUE(base::ReadFileToString(dir.AppendASCII("b.html"), &b_contents)); 858 ASSERT_TRUE(base::ReadFileToString(dir.AppendASCII("b.html"), &b_contents));
863 EXPECT_THAT(b_contents, 859 EXPECT_THAT(b_contents,
864 HasSubstr("b.htm: 3a35f7fa-96a9-4487-9f18-4470263907fa")); 860 HasSubstr("b.htm: 3a35f7fa-96a9-4487-9f18-4470263907fa"));
865 } 861 }
866 862
867 // Test for crbug.com/538766. 863 // Test for crbug.com/538766.
868 // Disabled because the test will fail until the bug is fixed 864 IN_PROC_BROWSER_TEST_F(SavePageSitePerProcessBrowserTest, SaveAsMHTML) {
869 // (but note that the test only fails with --site-per-process flag).
870 IN_PROC_BROWSER_TEST_F(SavePageSitePerProcessBrowserTest,
871 DISABLED_SaveAsMHTML) {
872 GURL url( 865 GURL url(
873 embedded_test_server()->GetURL("a.com", "/save_page/frames-xsite.htm")); 866 embedded_test_server()->GetURL("a.com", "/save_page/frames-xsite.htm"));
874 ui_test_utils::NavigateToURL(browser(), url); 867 ui_test_utils::NavigateToURL(browser(), url);
875 868
876 base::FilePath full_file_name, dir; 869 base::FilePath full_file_name, dir;
877 SaveCurrentTab(url, content::SAVE_PAGE_TYPE_AS_MHTML, "frames-xsite-mhtml", 870 SaveCurrentTab(url, content::SAVE_PAGE_TYPE_AS_MHTML, "frames-xsite-mhtml",
878 -1, &dir, &full_file_name); 871 -1, &dir, &full_file_name);
879 ASSERT_FALSE(HasFailure()); 872 ASSERT_FALSE(HasFailure());
880 873
881 std::string mhtml; 874 std::string mhtml;
(...skipping 22 matching lines...) Expand all
904 // to twice - from iframes.htm and from b.htm). 897 // to twice - from iframes.htm and from b.htm).
905 int count = 0; 898 int count = 0;
906 size_t pos = 0; 899 size_t pos = 0;
907 for (;;) { 900 for (;;) {
908 pos = mhtml.find("Content-Type: image/png", pos); 901 pos = mhtml.find("Content-Type: image/png", pos);
909 if (pos == std::string::npos) 902 if (pos == std::string::npos)
910 break; 903 break;
911 count++; 904 count++;
912 pos++; 905 pos++;
913 } 906 }
914 EXPECT_EQ(1, count) << "Verify number of image/png parts in the mhtml output"; 907 // TODO(lukasza): Need to dedupe savable resources (i.e. 1.png) across frames.
908 // This will be fixed by crrev.com/1417323006.
909 // EXPECT_EQ(1, count)
910 // << "Verify number of image/png parts in the mhtml output";
915 } 911 }
916 912
917 // Test suite that verifies that the frame tree "looks" the same before 913 // Test suite that verifies that the frame tree "looks" the same before
918 // and after a save-page-as. 914 // and after a save-page-as.
919 class SavePageMultiFrameBrowserTest 915 class SavePageMultiFrameBrowserTest
920 : public SavePageSitePerProcessBrowserTest, 916 : public SavePageSitePerProcessBrowserTest,
921 public ::testing::WithParamInterface<content::SavePageType> { 917 public ::testing::WithParamInterface<content::SavePageType> {
922 protected: 918 protected:
923 void TestMultiFramePage(content::SavePageType save_page_type, 919 void TestMultiFramePage(content::SavePageType save_page_type,
924 const GURL& url, 920 const GURL& url,
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
1016 std::string arr[] = { 1012 std::string arr[] = {
1017 "frames-xsite.htm: 896fd88d-a77a-4f46-afd8-24db7d5af9c2", 1013 "frames-xsite.htm: 896fd88d-a77a-4f46-afd8-24db7d5af9c2",
1018 "a.htm: 1b8aae2b-e164-462f-bd5b-98aa366205f2", 1014 "a.htm: 1b8aae2b-e164-462f-bd5b-98aa366205f2",
1019 "b.htm: 3a35f7fa-96a9-4487-9f18-4470263907fa", 1015 "b.htm: 3a35f7fa-96a9-4487-9f18-4470263907fa",
1020 }; 1016 };
1021 std::vector<std::string> expected_substrings(std::begin(arr), std::end(arr)); 1017 std::vector<std::string> expected_substrings(std::begin(arr), std::end(arr));
1022 1018
1023 GURL url( 1019 GURL url(
1024 embedded_test_server()->GetURL("a.com", "/save_page/frames-xsite.htm")); 1020 embedded_test_server()->GetURL("a.com", "/save_page/frames-xsite.htm"));
1025 1021
1026 // TODO(lukasza): crbug.com/538766: Enable CrossSite testing of MHTML.
1027 if (save_page_type == content::SAVE_PAGE_TYPE_AS_MHTML)
1028 return;
1029
1030 // TODO(lukasza/paulmeyer): crbug.com/457440: Can enable verification 1022 // TODO(lukasza/paulmeyer): crbug.com/457440: Can enable verification
1031 // of the original page once find-in-page works for OOP frames. 1023 // of the original page once find-in-page works for OOP frames.
1032 bool skip_verification_of_original_page = true; 1024 bool skip_verification_of_original_page = true;
1033 1025
1034 TestMultiFramePage(save_page_type, url, 3, expected_substrings, 1026 TestMultiFramePage(save_page_type, url, 3, expected_substrings,
1035 skip_verification_of_original_page); 1027 skip_verification_of_original_page);
1036 } 1028 }
1037 1029
1038 // Test compares original-vs-saved for a page with <object> elements. 1030 // Test compares original-vs-saved for a page with <object> elements.
1039 // (see crbug.com/553478). 1031 // (see crbug.com/553478).
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
1181 TestMultiFramePage(save_page_type, url, 7, expected_substrings); 1173 TestMultiFramePage(save_page_type, url, 7, expected_substrings);
1182 } 1174 }
1183 1175
1184 INSTANTIATE_TEST_CASE_P( 1176 INSTANTIATE_TEST_CASE_P(
1185 SaveType, 1177 SaveType,
1186 SavePageMultiFrameBrowserTest, 1178 SavePageMultiFrameBrowserTest,
1187 ::testing::Values(content::SAVE_PAGE_TYPE_AS_COMPLETE_HTML, 1179 ::testing::Values(content::SAVE_PAGE_TYPE_AS_COMPLETE_HTML,
1188 content::SAVE_PAGE_TYPE_AS_MHTML)); 1180 content::SAVE_PAGE_TYPE_AS_MHTML));
1189 1181
1190 } // namespace 1182 } // namespace
OLDNEW
« no previous file with comments | « no previous file | content/browser/download/mhtml_generation_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698