OLD | NEW |
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 1007 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1018 | 1018 |
1019 // Test suite that verifies that the frame tree "looks" the same before | 1019 // Test suite that verifies that the frame tree "looks" the same before |
1020 // and after a save-page-as. | 1020 // and after a save-page-as. |
1021 class SavePageOriginalVsSavedComparisonTest | 1021 class SavePageOriginalVsSavedComparisonTest |
1022 : public SavePageSitePerProcessBrowserTest, | 1022 : public SavePageSitePerProcessBrowserTest, |
1023 public ::testing::WithParamInterface<content::SavePageType> { | 1023 public ::testing::WithParamInterface<content::SavePageType> { |
1024 protected: | 1024 protected: |
1025 void TestOriginalVsSavedPage( | 1025 void TestOriginalVsSavedPage( |
1026 content::SavePageType save_page_type, | 1026 content::SavePageType save_page_type, |
1027 const GURL& url, | 1027 const GURL& url, |
1028 int expected_number_of_frames, | 1028 int expected_number_of_frames_in_original_page, |
| 1029 int expected_number_of_frames_in_mhtml_page, |
1029 const std::vector<std::string>& expected_substrings) { | 1030 const std::vector<std::string>& expected_substrings) { |
1030 // Navigate to the test page and verify if test expectations | 1031 // Navigate to the test page and verify if test expectations |
1031 // are met (this is mostly a sanity check - a failure to meet | 1032 // are met (this is mostly a sanity check - a failure to meet |
1032 // expectations would probably mean that there is a test bug | 1033 // expectations would probably mean that there is a test bug |
1033 // (i.e. that we got called with wrong expected_foo argument). | 1034 // (i.e. that we got called with wrong expected_foo argument). |
1034 ui_test_utils::NavigateToURL(browser(), url); | 1035 ui_test_utils::NavigateToURL(browser(), url); |
1035 DLOG(INFO) << "Verifying test expectations for original page... : " | 1036 DLOG(INFO) << "Verifying test expectations for original page... : " |
1036 << GetCurrentTab(browser())->GetLastCommittedURL(); | 1037 << GetCurrentTab(browser())->GetLastCommittedURL(); |
1037 AssertExpectationsAboutCurrentTab(expected_number_of_frames, | 1038 AssertExpectationsAboutCurrentTab( |
1038 expected_substrings); | 1039 expected_number_of_frames_in_original_page, expected_substrings); |
1039 | 1040 |
1040 // Save the page. | 1041 // Save the page. |
1041 base::FilePath full_file_name, dir; | 1042 base::FilePath full_file_name, dir; |
1042 SaveCurrentTab(url, save_page_type, "save_result", -1, &dir, | 1043 SaveCurrentTab(url, save_page_type, "save_result", -1, &dir, |
1043 &full_file_name); | 1044 &full_file_name); |
1044 ASSERT_FALSE(HasFailure()); | 1045 ASSERT_FALSE(HasFailure()); |
1045 | 1046 |
1046 // Stop the test server (to make sure the locally saved page | 1047 // Stop the test server (to make sure the locally saved page |
1047 // is self-contained / won't try to open original resources). | 1048 // is self-contained / won't try to open original resources). |
1048 ASSERT_TRUE(embedded_test_server()->ShutdownAndWaitUntilComplete()); | 1049 ASSERT_TRUE(embedded_test_server()->ShutdownAndWaitUntilComplete()); |
1049 | 1050 |
1050 // Open the saved page and verify if test expectations are | 1051 // Open the saved page and verify if test expectations are |
1051 // met (i.e. if the same expectations are met for "after" | 1052 // met (i.e. if the same expectations are met for "after" |
1052 // [saved version of the page] as for the "before" | 1053 // [saved version of the page] as for the "before" |
1053 // [the original version of the page]. | 1054 // [the original version of the page]. |
1054 ui_test_utils::NavigateToURL(browser(), | 1055 ui_test_utils::NavigateToURL(browser(), |
1055 GURL(net::FilePathToFileURL(full_file_name))); | 1056 GURL(net::FilePathToFileURL(full_file_name))); |
1056 DLOG(INFO) << "Verifying test expectations for saved page... : " | 1057 DLOG(INFO) << "Verifying test expectations for saved page... : " |
1057 << GetCurrentTab(browser())->GetLastCommittedURL(); | 1058 << GetCurrentTab(browser())->GetLastCommittedURL(); |
1058 AssertExpectationsAboutCurrentTab(expected_number_of_frames, | 1059 // Hidden elements, i.e., hidden frames, will be removed only from MHTML |
| 1060 // page. They're still kept in other types of serialization, like saving |
| 1061 // as a complete html page. |
| 1062 int expected_number_of_frames_in_saved_page = |
| 1063 (save_page_type == content::SAVE_PAGE_TYPE_AS_MHTML) ? |
| 1064 expected_number_of_frames_in_mhtml_page : |
| 1065 expected_number_of_frames_in_original_page; |
| 1066 AssertExpectationsAboutCurrentTab(expected_number_of_frames_in_saved_page, |
1059 expected_substrings); | 1067 expected_substrings); |
1060 } | 1068 } |
1061 | 1069 |
1062 // Helper method to deduplicate some code across 2 tests. | 1070 // Helper method to deduplicate some code across 2 tests. |
1063 void RunObjectElementsTest(GURL url) { | 1071 void RunObjectElementsTest(GURL url) { |
1064 content::SavePageType save_page_type = GetParam(); | 1072 content::SavePageType save_page_type = GetParam(); |
1065 | 1073 |
1066 // 7 comes from: | 1074 // 7 comes from: |
1067 // - main frame (frames-objects.htm) | 1075 // - main frame (frames-objects.htm) |
1068 // - object with frame-nested.htm + 2 subframes (frames-nested2.htm + b.htm) | 1076 // - object with frame-nested.htm + 2 subframes (frames-nested2.htm + b.htm) |
(...skipping 12 matching lines...) Expand all Loading... |
1081 "text-object.txt: ae52dd09-9746-4b7e-86a6-6ada5e2680c2", | 1089 "text-object.txt: ae52dd09-9746-4b7e-86a6-6ada5e2680c2", |
1082 }; | 1090 }; |
1083 std::vector<std::string> expected_substrings(std::begin(arr), | 1091 std::vector<std::string> expected_substrings(std::begin(arr), |
1084 std::end(arr)); | 1092 std::end(arr)); |
1085 | 1093 |
1086 // TODO(lukasza): crbug.com/553478: Enable <object> testing of MHTML. | 1094 // TODO(lukasza): crbug.com/553478: Enable <object> testing of MHTML. |
1087 if (save_page_type == content::SAVE_PAGE_TYPE_AS_MHTML) | 1095 if (save_page_type == content::SAVE_PAGE_TYPE_AS_MHTML) |
1088 return; | 1096 return; |
1089 | 1097 |
1090 TestOriginalVsSavedPage(save_page_type, url, expected_number_of_frames, | 1098 TestOriginalVsSavedPage(save_page_type, url, expected_number_of_frames, |
1091 expected_substrings); | 1099 expected_number_of_frames, expected_substrings); |
1092 } | 1100 } |
1093 | 1101 |
1094 private: | 1102 private: |
1095 void AssertExpectationsAboutCurrentTab( | 1103 void AssertExpectationsAboutCurrentTab( |
1096 int expected_number_of_frames, | 1104 int expected_number_of_frames, |
1097 const std::vector<std::string>& expected_substrings) { | 1105 const std::vector<std::string>& expected_substrings) { |
1098 int actual_number_of_frames = 0; | 1106 int actual_number_of_frames = 0; |
1099 GetCurrentTab(browser())->ForEachFrame(base::Bind( | 1107 GetCurrentTab(browser())->ForEachFrame(base::Bind( |
1100 &IncrementInteger, base::Unretained(&actual_number_of_frames))); | 1108 &IncrementInteger, base::Unretained(&actual_number_of_frames))); |
1101 EXPECT_EQ(expected_number_of_frames, actual_number_of_frames); | 1109 EXPECT_EQ(expected_number_of_frames, actual_number_of_frames); |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1148 std::string arr[] = { | 1156 std::string arr[] = { |
1149 "frames-xsite.htm: 896fd88d-a77a-4f46-afd8-24db7d5af9c2", | 1157 "frames-xsite.htm: 896fd88d-a77a-4f46-afd8-24db7d5af9c2", |
1150 "a.htm: 1b8aae2b-e164-462f-bd5b-98aa366205f2", | 1158 "a.htm: 1b8aae2b-e164-462f-bd5b-98aa366205f2", |
1151 "b.htm: 3a35f7fa-96a9-4487-9f18-4470263907fa", | 1159 "b.htm: 3a35f7fa-96a9-4487-9f18-4470263907fa", |
1152 }; | 1160 }; |
1153 std::vector<std::string> expected_substrings(std::begin(arr), std::end(arr)); | 1161 std::vector<std::string> expected_substrings(std::begin(arr), std::end(arr)); |
1154 | 1162 |
1155 GURL url( | 1163 GURL url( |
1156 embedded_test_server()->GetURL("a.com", "/save_page/frames-xsite.htm")); | 1164 embedded_test_server()->GetURL("a.com", "/save_page/frames-xsite.htm")); |
1157 | 1165 |
1158 TestOriginalVsSavedPage(save_page_type, url, 3, expected_substrings); | 1166 TestOriginalVsSavedPage(save_page_type, url, 3, 3, expected_substrings); |
1159 } | 1167 } |
1160 | 1168 |
1161 // Test compares original-vs-saved for a page with <object> elements. | 1169 // Test compares original-vs-saved for a page with <object> elements. |
1162 // (see crbug.com/553478). | 1170 // (see crbug.com/553478). |
1163 IN_PROC_BROWSER_TEST_P(SavePageOriginalVsSavedComparisonTest, | 1171 IN_PROC_BROWSER_TEST_P(SavePageOriginalVsSavedComparisonTest, |
1164 ObjectElementsViaHttp) { | 1172 ObjectElementsViaHttp) { |
1165 GURL url( | 1173 GURL url( |
1166 embedded_test_server()->GetURL("a.com", "/save_page/frames-objects.htm")); | 1174 embedded_test_server()->GetURL("a.com", "/save_page/frames-objects.htm")); |
1167 | 1175 |
1168 RunObjectElementsTest(url); | 1176 RunObjectElementsTest(url); |
(...skipping 21 matching lines...) Expand all Loading... |
1190 "main: acb0609d-eb10-4c26-83e2-ad8afb7b0ff3", | 1198 "main: acb0609d-eb10-4c26-83e2-ad8afb7b0ff3", |
1191 "sub1: b124df3a-d39f-47a1-ae04-5bb5d0bf549e", | 1199 "sub1: b124df3a-d39f-47a1-ae04-5bb5d0bf549e", |
1192 "sub2: 07014068-604d-45ae-884f-a068cfe7bc0a", | 1200 "sub2: 07014068-604d-45ae-884f-a068cfe7bc0a", |
1193 "sub3: 06cc8fcc-c692-4a1a-a10f-1645b746e8f4", | 1201 "sub3: 06cc8fcc-c692-4a1a-a10f-1645b746e8f4", |
1194 }; | 1202 }; |
1195 std::vector<std::string> expected_substrings(std::begin(arr), std::end(arr)); | 1203 std::vector<std::string> expected_substrings(std::begin(arr), std::end(arr)); |
1196 | 1204 |
1197 GURL url(embedded_test_server()->GetURL("a.com", | 1205 GURL url(embedded_test_server()->GetURL("a.com", |
1198 "/save_page/frames-about-blank.htm")); | 1206 "/save_page/frames-about-blank.htm")); |
1199 | 1207 |
1200 TestOriginalVsSavedPage(save_page_type, url, 4, expected_substrings); | 1208 TestOriginalVsSavedPage(save_page_type, url, 4, 4, expected_substrings); |
1201 } | 1209 } |
1202 | 1210 |
1203 // Test compares original-vs-saved for a page with nested frames. | 1211 // Test compares original-vs-saved for a page with nested frames. |
1204 // Two levels of nesting are especially good for verifying correct | 1212 // Two levels of nesting are especially good for verifying correct |
1205 // link rewriting for subframes-vs-main-frame (see crbug.com/554666). | 1213 // link rewriting for subframes-vs-main-frame (see crbug.com/554666). |
1206 IN_PROC_BROWSER_TEST_P(SavePageOriginalVsSavedComparisonTest, NestedFrames) { | 1214 IN_PROC_BROWSER_TEST_P(SavePageOriginalVsSavedComparisonTest, NestedFrames) { |
1207 content::SavePageType save_page_type = GetParam(); | 1215 content::SavePageType save_page_type = GetParam(); |
1208 | 1216 |
1209 std::string arr[] = { | 1217 std::string arr[] = { |
1210 "frames-nested.htm: 4388232f-8d45-4d2e-9807-721b381be153", | 1218 "frames-nested.htm: 4388232f-8d45-4d2e-9807-721b381be153", |
1211 "frames-nested2.htm: 6d23dc47-f283-4977-96ec-66bcf72301a4", | 1219 "frames-nested2.htm: 6d23dc47-f283-4977-96ec-66bcf72301a4", |
1212 "b.htm: 3a35f7fa-96a9-4487-9f18-4470263907fa", | 1220 "b.htm: 3a35f7fa-96a9-4487-9f18-4470263907fa", |
1213 }; | 1221 }; |
1214 std::vector<std::string> expected_substrings(std::begin(arr), std::end(arr)); | 1222 std::vector<std::string> expected_substrings(std::begin(arr), std::end(arr)); |
1215 | 1223 |
1216 GURL url( | 1224 GURL url( |
1217 embedded_test_server()->GetURL("a.com", "/save_page/frames-nested.htm")); | 1225 embedded_test_server()->GetURL("a.com", "/save_page/frames-nested.htm")); |
1218 | 1226 |
1219 TestOriginalVsSavedPage(save_page_type, url, 3, expected_substrings); | 1227 TestOriginalVsSavedPage(save_page_type, url, 3, 3, expected_substrings); |
1220 } | 1228 } |
1221 | 1229 |
1222 // Test for crbug.com/106364 and crbug.com/538188. | 1230 // Test for crbug.com/106364 and crbug.com/538188. |
1223 // Test frames have the same uri ... | 1231 // Test frames have the same uri ... |
1224 // subframe1 and subframe2 - both have src=b.htm | 1232 // subframe1 and subframe2 - both have src=b.htm |
1225 // subframe3 and subframe4 - about:blank (no src, only srcdoc attribute). | 1233 // subframe3 and subframe4 - about:blank (no src, only srcdoc attribute). |
1226 // ... but different content (generated by main frame's javascript). | 1234 // ... but different content (generated by main frame's javascript). |
1227 IN_PROC_BROWSER_TEST_P(SavePageOriginalVsSavedComparisonTest, RuntimeChanges) { | 1235 IN_PROC_BROWSER_TEST_P(SavePageOriginalVsSavedComparisonTest, RuntimeChanges) { |
1228 content::SavePageType save_page_type = GetParam(); | 1236 content::SavePageType save_page_type = GetParam(); |
1229 | 1237 |
1230 std::string arr[] = { | 1238 std::string arr[] = { |
1231 "frames-runtime-changes.htm: 4388232f-8d45-4d2e-9807-721b381be153", | 1239 "frames-runtime-changes.htm: 4388232f-8d45-4d2e-9807-721b381be153", |
1232 "subframe1: 21595339-61fc-4854-b6df-0668328ea263", | 1240 "subframe1: 21595339-61fc-4854-b6df-0668328ea263", |
1233 "subframe2: adf55719-15e7-45be-9eda-d12fe782a1bd", | 1241 "subframe2: adf55719-15e7-45be-9eda-d12fe782a1bd", |
1234 "subframe3: 50e294bf-3a5b-499d-8772-651ead26952f", | 1242 "subframe3: 50e294bf-3a5b-499d-8772-651ead26952f", |
1235 "subframe4: e0ea9289-7467-4d32-ba5c-c604e8d84cb7", | 1243 "subframe4: e0ea9289-7467-4d32-ba5c-c604e8d84cb7", |
1236 }; | 1244 }; |
1237 std::vector<std::string> expected_substrings(std::begin(arr), std::end(arr)); | 1245 std::vector<std::string> expected_substrings(std::begin(arr), std::end(arr)); |
1238 | 1246 |
1239 GURL url(embedded_test_server()->GetURL( | 1247 GURL url(embedded_test_server()->GetURL( |
1240 "a.com", "/save_page/frames-runtime-changes.htm?do_runtime_changes=1")); | 1248 "a.com", "/save_page/frames-runtime-changes.htm?do_runtime_changes=1")); |
1241 | 1249 |
1242 TestOriginalVsSavedPage(save_page_type, url, 5, expected_substrings); | 1250 TestOriginalVsSavedPage(save_page_type, url, 5, 5, expected_substrings); |
1243 } | 1251 } |
1244 | 1252 |
1245 // Test for saving frames with various encodings: | 1253 // Test for saving frames with various encodings: |
1246 // - iso-8859-2: encoding declared via <meta> element | 1254 // - iso-8859-2: encoding declared via <meta> element |
1247 // - utf16-le-bom.htm, utf16-be-bom.htm: encoding detected via BOM | 1255 // - utf16-le-bom.htm, utf16-be-bom.htm: encoding detected via BOM |
1248 // - utf16-le-nobom.htm, utf16-le-nobom.htm, utf32.htm - encoding declared via | 1256 // - utf16-le-nobom.htm, utf16-le-nobom.htm, utf32.htm - encoding declared via |
1249 // mocked http headers | 1257 // mocked http headers |
1250 IN_PROC_BROWSER_TEST_P(SavePageOriginalVsSavedComparisonTest, Encoding) { | 1258 IN_PROC_BROWSER_TEST_P(SavePageOriginalVsSavedComparisonTest, Encoding) { |
1251 content::SavePageType save_page_type = GetParam(); | 1259 content::SavePageType save_page_type = GetParam(); |
1252 | 1260 |
(...skipping 19 matching lines...) Expand all Loading... |
1272 | 1280 |
1273 // TODO(lukasza): crbug.com/541699: MHTML needs to handle multi-byte encodings | 1281 // TODO(lukasza): crbug.com/541699: MHTML needs to handle multi-byte encodings |
1274 // by either: | 1282 // by either: |
1275 // 1. Continuing to preserve the original encoding, but starting to round-trip | 1283 // 1. Continuing to preserve the original encoding, but starting to round-trip |
1276 // the encoding declaration (in Content-Type MIME/MHTML header?) | 1284 // the encoding declaration (in Content-Type MIME/MHTML header?) |
1277 // 2. Saving html docs in UTF8. | 1285 // 2. Saving html docs in UTF8. |
1278 // 3. Saving the BOM (not sure if this will help for all cases though). | 1286 // 3. Saving the BOM (not sure if this will help for all cases though). |
1279 if (save_page_type == content::SAVE_PAGE_TYPE_AS_MHTML) | 1287 if (save_page_type == content::SAVE_PAGE_TYPE_AS_MHTML) |
1280 return; | 1288 return; |
1281 | 1289 |
1282 TestOriginalVsSavedPage(save_page_type, url, 7, expected_substrings); | 1290 TestOriginalVsSavedPage(save_page_type, url, 7, 7, expected_substrings); |
1283 } | 1291 } |
1284 | 1292 |
1285 // Test for saving style element and attribute (see also crbug.com/568293). | 1293 // Test for saving style element and attribute (see also crbug.com/568293). |
1286 IN_PROC_BROWSER_TEST_P(SavePageOriginalVsSavedComparisonTest, Style) { | 1294 IN_PROC_BROWSER_TEST_P(SavePageOriginalVsSavedComparisonTest, Style) { |
1287 content::SavePageType save_page_type = GetParam(); | 1295 content::SavePageType save_page_type = GetParam(); |
1288 | 1296 |
1289 std::string arr[] = { | 1297 std::string arr[] = { |
1290 "style.htm: af84c3ca-0fc6-4b0d-bf7a-5ac18a4dab62", | 1298 "style.htm: af84c3ca-0fc6-4b0d-bf7a-5ac18a4dab62", |
1291 "frameE: c9539ccd-47b0-47cf-a03b-734614865872", | 1299 "frameF: c9539ccd-47b0-47cf-a03b-734614865872", |
1292 }; | 1300 }; |
1293 std::vector<std::string> expected_substrings(std::begin(arr), std::end(arr)); | 1301 std::vector<std::string> expected_substrings(std::begin(arr), std::end(arr)); |
1294 | 1302 |
1295 GURL url(embedded_test_server()->GetURL("a.com", "/save_page/style.htm")); | 1303 GURL url(embedded_test_server()->GetURL("a.com", "/save_page/style.htm")); |
1296 | 1304 |
1297 TestOriginalVsSavedPage(save_page_type, url, 6, expected_substrings); | 1305 // The original page has 7 iframes. 2 of them are both hidden and affecting |
| 1306 // no layout. So these two are excluded from the saved page. |
| 1307 TestOriginalVsSavedPage(save_page_type, url, 7, 5, expected_substrings); |
1298 } | 1308 } |
1299 | 1309 |
1300 // Test for saving a page with broken subresources: | 1310 // Test for saving a page with broken subresources: |
1301 // - Broken, undecodable image (see also https://crbug.com/586680) | 1311 // - Broken, undecodable image (see also https://crbug.com/586680) |
1302 // - Broken link, to unresolvable host (see also https://crbug.com/594219) | 1312 // - Broken link, to unresolvable host (see also https://crbug.com/594219) |
1303 IN_PROC_BROWSER_TEST_P(SavePageOriginalVsSavedComparisonTest, BrokenImage) { | 1313 IN_PROC_BROWSER_TEST_P(SavePageOriginalVsSavedComparisonTest, BrokenImage) { |
1304 // Clear resolver rules to make sure that *.no.such.host used in the test html | 1314 // Clear resolver rules to make sure that *.no.such.host used in the test html |
1305 // doesn't resolve to 127.0.0.1 | 1315 // doesn't resolve to 127.0.0.1 |
1306 host_resolver()->ClearRules(); | 1316 host_resolver()->ClearRules(); |
1307 | 1317 |
1308 content::SavePageType save_page_type = GetParam(); | 1318 content::SavePageType save_page_type = GetParam(); |
1309 | 1319 |
1310 std::string arr[] = { | 1320 std::string arr[] = { |
1311 "broken-image.htm: 1e846775-b3ed-4d9c-a124-029554a1eb9d", | 1321 "broken-image.htm: 1e846775-b3ed-4d9c-a124-029554a1eb9d", |
1312 }; | 1322 }; |
1313 std::vector<std::string> expected_substrings(std::begin(arr), std::end(arr)); | 1323 std::vector<std::string> expected_substrings(std::begin(arr), std::end(arr)); |
1314 | 1324 |
1315 GURL url(embedded_test_server()->GetURL("127.0.0.1", | 1325 GURL url(embedded_test_server()->GetURL("127.0.0.1", |
1316 "/save_page/broken-image.htm")); | 1326 "/save_page/broken-image.htm")); |
1317 | 1327 |
1318 TestOriginalVsSavedPage(save_page_type, url, 1, expected_substrings); | 1328 TestOriginalVsSavedPage(save_page_type, url, 1, 1, expected_substrings); |
1319 } | 1329 } |
1320 | 1330 |
1321 INSTANTIATE_TEST_CASE_P( | 1331 INSTANTIATE_TEST_CASE_P( |
1322 SaveType, | 1332 SaveType, |
1323 SavePageOriginalVsSavedComparisonTest, | 1333 SavePageOriginalVsSavedComparisonTest, |
1324 ::testing::Values(content::SAVE_PAGE_TYPE_AS_COMPLETE_HTML, | 1334 ::testing::Values(content::SAVE_PAGE_TYPE_AS_COMPLETE_HTML, |
1325 content::SAVE_PAGE_TYPE_AS_MHTML)); | 1335 content::SAVE_PAGE_TYPE_AS_MHTML)); |
1326 | 1336 |
1327 } // namespace | 1337 } // namespace |
OLD | NEW |