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

Side by Side Diff: content/renderer/dom_serializer_browsertest.cc

Issue 1373573002: ABANDONED: OOPIFs: Moving stitching of local paths from renderer to browser process. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@page-serialization-recursive-begone
Patch Set: Self-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) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/command_line.h" 6 #include "base/command_line.h"
7 #include "base/compiler_specific.h" 7 #include "base/compiler_specific.h"
8 #include "base/containers/hash_tables.h" 8 #include "base/containers/hash_tables.h"
9 #include "base/files/file_path.h" 9 #include "base/files/file_path.h"
10 #include "base/files/file_util.h" 10 #include "base/files/file_util.h"
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 } 152 }
153 153
154 private: 154 private:
155 base::Closure quit_closure_; 155 base::Closure quit_closure_;
156 }; 156 };
157 157
158 class DomSerializerTests : public ContentBrowserTest, 158 class DomSerializerTests : public ContentBrowserTest,
159 public WebPageSerializerClient { 159 public WebPageSerializerClient {
160 public: 160 public:
161 DomSerializerTests() 161 DomSerializerTests()
162 : serialized_(false), 162 : got_end_of_frame_notification_(false),
163 local_directory_name_(FILE_PATH_LITERAL("./dummy_files/")) {} 163 local_directory_name_(FILE_PATH_LITERAL("./dummy_files/")) {}
164 164
165 void SetUpCommandLine(base::CommandLine* command_line) override { 165 void SetUpCommandLine(base::CommandLine* command_line) override {
166 command_line->AppendSwitch(switches::kSingleProcess); 166 command_line->AppendSwitch(switches::kSingleProcess);
167 #if defined(OS_WIN) 167 #if defined(OS_WIN)
168 // Don't want to try to create a GPU process. 168 // Don't want to try to create a GPU process.
169 command_line->AppendSwitch(switches::kDisableGpu); 169 command_line->AppendSwitch(switches::kDisableGpu);
170 #endif 170 #endif
171 } 171 }
172 172
173 void SetUpOnMainThread() override { 173 void SetUpOnMainThread() override {
174 render_view_routing_id_ = 174 render_view_routing_id_ =
175 shell()->web_contents()->GetRenderViewHost()->GetRoutingID(); 175 shell()->web_contents()->GetRenderViewHost()->GetRoutingID();
176 } 176 }
177 177
178 // DomSerializerDelegate. 178 void writeHtmlFragment(const WebCString& data) override {
179 virtual void didSerializeDataForFrame(const WebURL& frame_web_url, 179 serialization_output_ += data.data();
180 const WebCString& data,
181 PageSerializationStatus status) {
182
183 GURL frame_url(frame_web_url);
184 // If the all frames are finished saving, check all finish status
185 if (status == WebPageSerializerClient::AllFramesAreFinished) {
186 SerializationFinishStatusMap::iterator it =
187 serialization_finish_status_.begin();
188 for (; it != serialization_finish_status_.end(); ++it)
189 ASSERT_TRUE(it->second);
190 serialized_ = true;
191 return;
192 }
193
194 // Check finish status of current frame.
195 SerializationFinishStatusMap::iterator it =
196 serialization_finish_status_.find(frame_url.spec());
197 // New frame, set initial status as false.
198 if (it == serialization_finish_status_.end())
199 serialization_finish_status_[frame_url.spec()] = false;
200
201 it = serialization_finish_status_.find(frame_url.spec());
202 ASSERT_TRUE(it != serialization_finish_status_.end());
203 // In process frame, finish status should be false.
204 ASSERT_FALSE(it->second);
205
206 // Add data to corresponding frame's content.
207 serialized_frame_map_[frame_url.spec()] += data.data();
208
209 // Current frame is completed saving, change the finish status.
210 if (status == WebPageSerializerClient::CurrentFrameIsFinished)
211 it->second = true;
212 } 180 }
213 181
214 bool HasSerializedFrame(const GURL& frame_url) { 182 void writeLocalPathForSubFrame(const WebFrame& subFrame) override {
215 return serialized_frame_map_.find(frame_url.spec()) != 183 // Tests in content/renderer/dom_serializer_browsertest.cc do not verify
216 serialized_frame_map_.end(); 184 // local paths in the serializer html (they are verified by
185 // chrome/browser/download/save_page_browsertest.cc). Therefore the body of
186 // writeLocalPathForSubFrame can be empty below.
217 } 187 }
218 188
219 const std::string& GetSerializedContentForFrame( 189 void writeLocalPathForSavableResource(
220 const GURL& frame_url) { 190 const WebURL& savableResourceURL) override {
221 return serialized_frame_map_[frame_url.spec()]; 191 // Tests in content/renderer/dom_serializer_browsertest.cc do not verify
192 // local paths in the serializer html (they are verified by
193 // chrome/browser/download/save_page_browsertest.cc). Therefore the body of
194 // writeLocalPathForSavableResource can be empty below.
222 } 195 }
223 196
197 void endOfFrame() override { got_end_of_frame_notification_ = true; }
198
199 const std::string& GetSerializedContent() { return serialization_output_; }
200
224 RenderView* GetRenderView() { 201 RenderView* GetRenderView() {
225 return RenderView::FromRoutingID(render_view_routing_id_); 202 return RenderView::FromRoutingID(render_view_routing_id_);
226 } 203 }
227 204
228 WebView* GetWebView() { 205 WebView* GetWebView() {
229 return GetRenderView()->GetWebView(); 206 return GetRenderView()->GetWebView();
230 } 207 }
231 208
232 WebFrame* GetMainFrame() { 209 WebFrame* GetMainFrame() {
233 return GetWebView()->mainFrame(); 210 return GetWebView()->mainFrame();
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
265 // Find corresponding WebFrame according to frame_url. 242 // Find corresponding WebFrame according to frame_url.
266 WebFrame* web_frame = FindSubFrameByURL(GetWebView(), frame_url); 243 WebFrame* web_frame = FindSubFrameByURL(GetWebView(), frame_url);
267 ASSERT_TRUE(web_frame != NULL); 244 ASSERT_TRUE(web_frame != NULL);
268 WebVector<WebURL> links; 245 WebVector<WebURL> links;
269 links.assign(&frame_url, 1); 246 links.assign(&frame_url, 1);
270 WebString file_path = 247 WebString file_path =
271 base::FilePath(FILE_PATH_LITERAL("c:\\dummy.htm")).AsUTF16Unsafe(); 248 base::FilePath(FILE_PATH_LITERAL("c:\\dummy.htm")).AsUTF16Unsafe();
272 WebVector<WebString> local_paths; 249 WebVector<WebString> local_paths;
273 local_paths.assign(&file_path, 1); 250 local_paths.assign(&file_path, 1);
274 // Start serializing DOM. 251 // Start serializing DOM.
275 bool result = WebPageSerializer::serialize(web_frame->toWebLocalFrame(), 252 bool result = WebPageSerializer::serialize(
276 static_cast<WebPageSerializerClient*>(this), 253 web_frame->toWebLocalFrame(),
277 links, 254 static_cast<WebPageSerializerClient*>(this));
278 local_paths,
279 local_directory_name_.AsUTF16Unsafe());
280 ASSERT_TRUE(result); 255 ASSERT_TRUE(result);
281 ASSERT_TRUE(serialized_); 256 ASSERT_TRUE(got_end_of_frame_notification_);
282 } 257 }
283 258
284 void SerializeHTMLDOMWithDocTypeOnRenderer(const GURL& file_url) { 259 void SerializeHTMLDOMWithDocTypeOnRenderer(const GURL& file_url) {
285 // Make sure original contents have document type. 260 // Make sure original contents have document type.
286 WebFrame* web_frame = FindSubFrameByURL(GetWebView(), file_url); 261 WebFrame* web_frame = FindSubFrameByURL(GetWebView(), file_url);
287 ASSERT_TRUE(web_frame != NULL); 262 ASSERT_TRUE(web_frame != NULL);
288 WebDocument doc = web_frame->document(); 263 WebDocument doc = web_frame->document();
289 ASSERT_TRUE(HasDocType(doc)); 264 ASSERT_TRUE(HasDocType(doc));
290 // Do serialization. 265 // Do serialization.
291 SerializeDomForURL(file_url); 266 SerializeDomForURL(file_url);
292 // Load the serialized contents. 267 // Load the serialized contents.
293 ASSERT_TRUE(HasSerializedFrame(file_url)); 268 const std::string& serialized_contents = GetSerializedContent();
294 const std::string& serialized_contents =
295 GetSerializedContentForFrame(file_url);
296 LoadContents(serialized_contents, file_url, 269 LoadContents(serialized_contents, file_url,
297 web_frame->document().encoding()); 270 web_frame->document().encoding());
298 // Make sure serialized contents still have document type. 271 // Make sure serialized contents still have document type.
299 web_frame = GetMainFrame(); 272 web_frame = GetMainFrame();
300 doc = web_frame->document(); 273 doc = web_frame->document();
301 ASSERT_TRUE(HasDocType(doc)); 274 ASSERT_TRUE(HasDocType(doc));
302 } 275 }
303 276
304 void SerializeHTMLDOMWithoutDocTypeOnRenderer(const GURL& file_url) { 277 void SerializeHTMLDOMWithoutDocTypeOnRenderer(const GURL& file_url) {
305 // Make sure original contents do not have document type. 278 // Make sure original contents do not have document type.
306 WebFrame* web_frame = FindSubFrameByURL(GetWebView(), file_url); 279 WebFrame* web_frame = FindSubFrameByURL(GetWebView(), file_url);
307 ASSERT_TRUE(web_frame != NULL); 280 ASSERT_TRUE(web_frame != NULL);
308 WebDocument doc = web_frame->document(); 281 WebDocument doc = web_frame->document();
309 ASSERT_TRUE(!HasDocType(doc)); 282 ASSERT_TRUE(!HasDocType(doc));
310 // Do serialization. 283 // Do serialization.
311 SerializeDomForURL(file_url); 284 SerializeDomForURL(file_url);
312 // Load the serialized contents. 285 // Load the serialized contents.
313 ASSERT_TRUE(HasSerializedFrame(file_url)); 286 const std::string& serialized_contents = GetSerializedContent();
314 const std::string& serialized_contents =
315 GetSerializedContentForFrame(file_url);
316 LoadContents(serialized_contents, file_url, 287 LoadContents(serialized_contents, file_url,
317 web_frame->document().encoding()); 288 web_frame->document().encoding());
318 // Make sure serialized contents do not have document type. 289 // Make sure serialized contents do not have document type.
319 web_frame = GetMainFrame(); 290 web_frame = GetMainFrame();
320 doc = web_frame->document(); 291 doc = web_frame->document();
321 ASSERT_TRUE(!HasDocType(doc)); 292 ASSERT_TRUE(!HasDocType(doc));
322 } 293 }
323 294
324 void SerializeXMLDocWithBuiltInEntitiesOnRenderer( 295 void SerializeXMLDocWithBuiltInEntitiesOnRenderer(
325 const GURL& xml_file_url, const std::string& original_contents) { 296 const GURL& xml_file_url, const std::string& original_contents) {
326 // Do serialization. 297 // Do serialization.
327 SerializeDomForURL(xml_file_url); 298 SerializeDomForURL(xml_file_url);
328 // Compare the serialized contents with original contents. 299 // Compare the serialized contents with original contents.
329 ASSERT_TRUE(HasSerializedFrame(xml_file_url)); 300 const std::string& serialized_contents = GetSerializedContent();
330 const std::string& serialized_contents =
331 GetSerializedContentForFrame(xml_file_url);
332 ASSERT_EQ(original_contents, serialized_contents); 301 ASSERT_EQ(original_contents, serialized_contents);
333 } 302 }
334 303
335 void SerializeHTMLDOMWithAddingMOTWOnRenderer( 304 void SerializeHTMLDOMWithAddingMOTWOnRenderer(
336 const GURL& file_url, const std::string& original_contents) { 305 const GURL& file_url, const std::string& original_contents) {
337 // Make sure original contents does not have MOTW; 306 // Make sure original contents does not have MOTW;
338 std::string motw_declaration = 307 std::string motw_declaration =
339 WebPageSerializer::generateMarkOfTheWebDeclaration(file_url).utf8(); 308 WebPageSerializer::generateMarkOfTheWebDeclaration(file_url).utf8();
340 ASSERT_FALSE(motw_declaration.empty()); 309 ASSERT_FALSE(motw_declaration.empty());
341 // The encoding of original contents is ISO-8859-1, so we convert the MOTW 310 // The encoding of original contents is ISO-8859-1, so we convert the MOTW
342 // declaration to ASCII and search whether original contents has it or not. 311 // declaration to ASCII and search whether original contents has it or not.
343 ASSERT_TRUE(std::string::npos == original_contents.find(motw_declaration)); 312 ASSERT_TRUE(std::string::npos == original_contents.find(motw_declaration));
344 313
345 // Do serialization. 314 // Do serialization.
346 SerializeDomForURL(file_url); 315 SerializeDomForURL(file_url);
347 // Make sure the serialized contents have MOTW ; 316 // Make sure the serialized contents have MOTW ;
348 ASSERT_TRUE(HasSerializedFrame(file_url)); 317 const std::string& serialized_contents = GetSerializedContent();
349 const std::string& serialized_contents =
350 GetSerializedContentForFrame(file_url);
351 ASSERT_FALSE(std::string::npos == 318 ASSERT_FALSE(std::string::npos ==
352 serialized_contents.find(motw_declaration)); 319 serialized_contents.find(motw_declaration));
353 } 320 }
354 321
355 void SerializeHTMLDOMWithNoMetaCharsetInOriginalDocOnRenderer( 322 void SerializeHTMLDOMWithNoMetaCharsetInOriginalDocOnRenderer(
356 const GURL& file_url) { 323 const GURL& file_url) {
357 // Make sure there is no META charset declaration in original document. 324 // Make sure there is no META charset declaration in original document.
358 WebFrame* web_frame = FindSubFrameByURL(GetWebView(), file_url); 325 WebFrame* web_frame = FindSubFrameByURL(GetWebView(), file_url);
359 ASSERT_TRUE(web_frame != NULL); 326 ASSERT_TRUE(web_frame != NULL);
360 WebDocument doc = web_frame->document(); 327 WebDocument doc = web_frame->document();
361 ASSERT_TRUE(doc.isHTMLDocument()); 328 ASSERT_TRUE(doc.isHTMLDocument());
362 WebElement head_element = doc.head(); 329 WebElement head_element = doc.head();
363 ASSERT_TRUE(!head_element.isNull()); 330 ASSERT_TRUE(!head_element.isNull());
364 // Go through all children of HEAD element. 331 // Go through all children of HEAD element.
365 for (WebNode child = head_element.firstChild(); !child.isNull(); 332 for (WebNode child = head_element.firstChild(); !child.isNull();
366 child = child.nextSibling()) { 333 child = child.nextSibling()) {
367 std::string charset_info; 334 std::string charset_info;
368 if (IsMetaElement(child, charset_info)) 335 if (IsMetaElement(child, charset_info))
369 ASSERT_TRUE(charset_info.empty()); 336 ASSERT_TRUE(charset_info.empty());
370 } 337 }
371 // Do serialization. 338 // Do serialization.
372 SerializeDomForURL(file_url); 339 SerializeDomForURL(file_url);
373 340
374 // Load the serialized contents. 341 // Load the serialized contents.
375 ASSERT_TRUE(HasSerializedFrame(file_url)); 342 const std::string& serialized_contents = GetSerializedContent();
376 const std::string& serialized_contents =
377 GetSerializedContentForFrame(file_url);
378 LoadContents(serialized_contents, file_url, 343 LoadContents(serialized_contents, file_url,
379 web_frame->document().encoding()); 344 web_frame->document().encoding());
380 // Make sure the first child of HEAD element is META which has charset 345 // Make sure the first child of HEAD element is META which has charset
381 // declaration in serialized contents. 346 // declaration in serialized contents.
382 web_frame = GetMainFrame(); 347 web_frame = GetMainFrame();
383 ASSERT_TRUE(web_frame != NULL); 348 ASSERT_TRUE(web_frame != NULL);
384 doc = web_frame->document(); 349 doc = web_frame->document();
385 ASSERT_TRUE(doc.isHTMLDocument()); 350 ASSERT_TRUE(doc.isHTMLDocument());
386 head_element = doc.head(); 351 head_element = doc.head();
387 ASSERT_TRUE(!head_element.isNull()); 352 ASSERT_TRUE(!head_element.isNull());
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
421 if (IsMetaElement(child, charset_info) && !charset_info.empty()) 386 if (IsMetaElement(child, charset_info) && !charset_info.empty())
422 charset_declaration_count++; 387 charset_declaration_count++;
423 } 388 }
424 // The original doc has more than META tags which have charset declaration. 389 // The original doc has more than META tags which have charset declaration.
425 ASSERT_TRUE(charset_declaration_count > 1); 390 ASSERT_TRUE(charset_declaration_count > 1);
426 391
427 // Do serialization. 392 // Do serialization.
428 SerializeDomForURL(file_url); 393 SerializeDomForURL(file_url);
429 394
430 // Load the serialized contents. 395 // Load the serialized contents.
431 ASSERT_TRUE(HasSerializedFrame(file_url)); 396 const std::string& serialized_contents = GetSerializedContent();
432 const std::string& serialized_contents =
433 GetSerializedContentForFrame(file_url);
434 LoadContents(serialized_contents, file_url, 397 LoadContents(serialized_contents, file_url,
435 web_frame->document().encoding()); 398 web_frame->document().encoding());
436 // Make sure only first child of HEAD element is META which has charset 399 // Make sure only first child of HEAD element is META which has charset
437 // declaration in serialized contents. 400 // declaration in serialized contents.
438 web_frame = GetMainFrame(); 401 web_frame = GetMainFrame();
439 ASSERT_TRUE(web_frame != NULL); 402 ASSERT_TRUE(web_frame != NULL);
440 doc = web_frame->document(); 403 doc = web_frame->document();
441 ASSERT_TRUE(doc.isHTMLDocument()); 404 ASSERT_TRUE(doc.isHTMLDocument());
442 head_ele = doc.head(); 405 head_ele = doc.head();
443 ASSERT_TRUE(!head_ele.isNull()); 406 ASSERT_TRUE(!head_ele.isNull());
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
478 WebDocument doc = web_frame->document(); 441 WebDocument doc = web_frame->document();
479 ASSERT_TRUE(doc.isHTMLDocument()); 442 ASSERT_TRUE(doc.isHTMLDocument());
480 WebElement body_ele = doc.body(); 443 WebElement body_ele = doc.body();
481 ASSERT_TRUE(!body_ele.isNull()); 444 ASSERT_TRUE(!body_ele.isNull());
482 WebNode text_node = body_ele.firstChild(); 445 WebNode text_node = body_ele.firstChild();
483 ASSERT_TRUE(text_node.isTextNode()); 446 ASSERT_TRUE(text_node.isTextNode());
484 ASSERT_TRUE(std::string(text_node.nodeValue().utf8()) == "&<>\"\'"); 447 ASSERT_TRUE(std::string(text_node.nodeValue().utf8()) == "&<>\"\'");
485 // Do serialization. 448 // Do serialization.
486 SerializeDomForURL(file_url); 449 SerializeDomForURL(file_url);
487 // Compare the serialized contents with original contents. 450 // Compare the serialized contents with original contents.
488 ASSERT_TRUE(HasSerializedFrame(file_url)); 451 const std::string& serialized_contents = GetSerializedContent();
489 const std::string& serialized_contents =
490 GetSerializedContentForFrame(file_url);
491 // Compare the serialized contents with original contents to make sure 452 // Compare the serialized contents with original contents to make sure
492 // they are same. 453 // they are same.
493 // Because we add MOTW when serializing DOM, so before comparison, we also 454 // Because we add MOTW when serializing DOM, so before comparison, we also
494 // need to add MOTW to original_contents. 455 // need to add MOTW to original_contents.
495 std::string original_str = 456 std::string original_str =
496 WebPageSerializer::generateMarkOfTheWebDeclaration(file_url).utf8(); 457 WebPageSerializer::generateMarkOfTheWebDeclaration(file_url).utf8();
497 original_str += original_contents; 458 original_str += original_contents;
498 // Since WebCore now inserts a new HEAD element if there is no HEAD element 459 // Since WebCore now inserts a new HEAD element if there is no HEAD element
499 // when creating BODY element. (Please see 460 // when creating BODY element. (Please see
500 // HTMLParser::bodyCreateErrorCheck.) We need to append the HEAD content and 461 // HTMLParser::bodyCreateErrorCheck.) We need to append the HEAD content and
(...skipping 30 matching lines...) Expand all
531 ASSERT_TRUE(web_frame != NULL); 492 ASSERT_TRUE(web_frame != NULL);
532 WebDocument doc = web_frame->document(); 493 WebDocument doc = web_frame->document();
533 ASSERT_TRUE(doc.isHTMLDocument()); 494 ASSERT_TRUE(doc.isHTMLDocument());
534 WebElement body_ele = doc.body(); 495 WebElement body_ele = doc.body();
535 ASSERT_TRUE(!body_ele.isNull()); 496 ASSERT_TRUE(!body_ele.isNull());
536 WebString value = body_ele.getAttribute("title"); 497 WebString value = body_ele.getAttribute("title");
537 ASSERT_TRUE(std::string(value.utf8()) == "&<>\"\'"); 498 ASSERT_TRUE(std::string(value.utf8()) == "&<>\"\'");
538 // Do serialization. 499 // Do serialization.
539 SerializeDomForURL(file_url); 500 SerializeDomForURL(file_url);
540 // Compare the serialized contents with original contents. 501 // Compare the serialized contents with original contents.
541 ASSERT_TRUE(HasSerializedFrame(file_url)); 502 const std::string& serialized_contents = GetSerializedContent();
542 const std::string& serialized_contents =
543 GetSerializedContentForFrame(file_url);
544 // Compare the serialized contents with original contents to make sure 503 // Compare the serialized contents with original contents to make sure
545 // they are same. 504 // they are same.
546 std::string original_str = 505 std::string original_str =
547 WebPageSerializer::generateMarkOfTheWebDeclaration(file_url).utf8(); 506 WebPageSerializer::generateMarkOfTheWebDeclaration(file_url).utf8();
548 original_str += original_contents; 507 original_str += original_contents;
549 if (!doc.isNull()) { 508 if (!doc.isNull()) {
550 WebString encoding = web_frame->document().encoding(); 509 WebString encoding = web_frame->document().encoding();
551 std::string htmlTag("<html>"); 510 std::string htmlTag("<html>");
552 std::string::size_type pos = original_str.find(htmlTag); 511 std::string::size_type pos = original_str.find(htmlTag);
553 ASSERT_NE(std::string::npos, pos); 512 ASSERT_NE(std::string::npos, pos);
(...skipping 18 matching lines...) Expand all
572 '%', 0x2285, 0x00b9, '\'', 0 531 '%', 0x2285, 0x00b9, '\'', 0
573 }; 532 };
574 WebString value = body_element.getAttribute("title"); 533 WebString value = body_element.getAttribute("title");
575 WebString content = doc.contentAsTextForTesting(); 534 WebString content = doc.contentAsTextForTesting();
576 ASSERT_TRUE(base::UTF16ToWide(value) == parsed_value); 535 ASSERT_TRUE(base::UTF16ToWide(value) == parsed_value);
577 ASSERT_TRUE(base::UTF16ToWide(content) == parsed_value); 536 ASSERT_TRUE(base::UTF16ToWide(content) == parsed_value);
578 537
579 // Do serialization. 538 // Do serialization.
580 SerializeDomForURL(file_url); 539 SerializeDomForURL(file_url);
581 // Check the serialized string. 540 // Check the serialized string.
582 ASSERT_TRUE(HasSerializedFrame(file_url)); 541 const std::string& serialized_contents = GetSerializedContent();
583 const std::string& serialized_contents =
584 GetSerializedContentForFrame(file_url);
585 // Confirm that the serialized string has no non-standard HTML entities. 542 // Confirm that the serialized string has no non-standard HTML entities.
586 ASSERT_EQ(std::string::npos, serialized_contents.find("&percnt;")); 543 ASSERT_EQ(std::string::npos, serialized_contents.find("&percnt;"));
587 ASSERT_EQ(std::string::npos, serialized_contents.find("&nsup;")); 544 ASSERT_EQ(std::string::npos, serialized_contents.find("&nsup;"));
588 ASSERT_EQ(std::string::npos, serialized_contents.find("&sup1;")); 545 ASSERT_EQ(std::string::npos, serialized_contents.find("&sup1;"));
589 ASSERT_EQ(std::string::npos, serialized_contents.find("&apos;")); 546 ASSERT_EQ(std::string::npos, serialized_contents.find("&apos;"));
590 } 547 }
591 548
592 void SerializeHTMLDOMWithBaseTagOnRenderer(const GURL& file_url, 549 void SerializeHTMLDOMWithBaseTagOnRenderer(const GURL& file_url,
593 const GURL& path_dir_url) { 550 const GURL& path_dir_url) {
594 // There are total 2 available base tags in this test file. 551 // There are total 2 available base tags in this test file.
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
626 ASSERT_EQ(original_base_tag_count, kTotalBaseTagCountInTestFile); 583 ASSERT_EQ(original_base_tag_count, kTotalBaseTagCountInTestFile);
627 // Make sure in original document, the base URL is not equal with the 584 // Make sure in original document, the base URL is not equal with the
628 // |path_dir_url|. 585 // |path_dir_url|.
629 GURL original_base_url(doc.baseURL()); 586 GURL original_base_url(doc.baseURL());
630 ASSERT_NE(original_base_url, path_dir_url); 587 ASSERT_NE(original_base_url, path_dir_url);
631 588
632 // Do serialization. 589 // Do serialization.
633 SerializeDomForURL(file_url); 590 SerializeDomForURL(file_url);
634 591
635 // Load the serialized contents. 592 // Load the serialized contents.
636 ASSERT_TRUE(HasSerializedFrame(file_url)); 593 const std::string& serialized_contents = GetSerializedContent();
637 const std::string& serialized_contents =
638 GetSerializedContentForFrame(file_url);
639 LoadContents(serialized_contents, file_url, 594 LoadContents(serialized_contents, file_url,
640 web_frame->document().encoding()); 595 web_frame->document().encoding());
641 596
642 // Make sure all links are absolute URLs and doc there are some number of 597 // Make sure all links are absolute URLs and doc there are some number of
643 // BASE tags in serialized HTML data. Each of those BASE tags have same base 598 // BASE tags in serialized HTML data. Each of those BASE tags have same base
644 // URL which is as same as URL of current test file. 599 // URL which is as same as URL of current test file.
645 web_frame = GetMainFrame(); 600 web_frame = GetMainFrame();
646 ASSERT_TRUE(web_frame != NULL); 601 ASSERT_TRUE(web_frame != NULL);
647 doc = web_frame->document(); 602 doc = web_frame->document();
648 ASSERT_TRUE(doc.isHTMLDocument()); 603 ASSERT_TRUE(doc.isHTMLDocument());
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
695 WebDocument doc = web_frame->document(); 650 WebDocument doc = web_frame->document();
696 ASSERT_TRUE(doc.isHTMLDocument()); 651 ASSERT_TRUE(doc.isHTMLDocument());
697 WebElement head_element = doc.head(); 652 WebElement head_element = doc.head();
698 ASSERT_TRUE(!head_element.isNull()); 653 ASSERT_TRUE(!head_element.isNull());
699 ASSERT_TRUE(!head_element.hasChildNodes()); 654 ASSERT_TRUE(!head_element.hasChildNodes());
700 ASSERT_TRUE(head_element.childNodes().length() == 0); 655 ASSERT_TRUE(head_element.childNodes().length() == 0);
701 656
702 // Do serialization. 657 // Do serialization.
703 SerializeDomForURL(file_url); 658 SerializeDomForURL(file_url);
704 // Make sure the serialized contents have META ; 659 // Make sure the serialized contents have META ;
705 ASSERT_TRUE(HasSerializedFrame(file_url)); 660 const std::string& serialized_contents = GetSerializedContent();
706 const std::string& serialized_contents =
707 GetSerializedContentForFrame(file_url);
708 661
709 // Reload serialized contents and make sure there is only one META tag. 662 // Reload serialized contents and make sure there is only one META tag.
710 LoadContents(serialized_contents, file_url, 663 LoadContents(serialized_contents, file_url,
711 web_frame->document().encoding()); 664 web_frame->document().encoding());
712 web_frame = GetMainFrame(); 665 web_frame = GetMainFrame();
713 ASSERT_TRUE(web_frame != NULL); 666 ASSERT_TRUE(web_frame != NULL);
714 doc = web_frame->document(); 667 doc = web_frame->document();
715 ASSERT_TRUE(doc.isHTMLDocument()); 668 ASSERT_TRUE(doc.isHTMLDocument());
716 head_element = doc.head(); 669 head_element = doc.head();
717 ASSERT_TRUE(!head_element.isNull()); 670 ASSERT_TRUE(!head_element.isNull());
(...skipping 25 matching lines...) Expand all
743 WebDocument doc = web_frame->document(); 696 WebDocument doc = web_frame->document();
744 WebNode lastNodeInBody = doc.body().lastChild(); 697 WebNode lastNodeInBody = doc.body().lastChild();
745 ASSERT_TRUE(lastNodeInBody.isElementNode()); 698 ASSERT_TRUE(lastNodeInBody.isElementNode());
746 WebString uri = GetSubResourceLinkFromElement( 699 WebString uri = GetSubResourceLinkFromElement(
747 lastNodeInBody.to<WebElement>()); 700 lastNodeInBody.to<WebElement>());
748 EXPECT_TRUE(uri.isNull()); 701 EXPECT_TRUE(uri.isNull());
749 } 702 }
750 703
751 private: 704 private:
752 int32 render_view_routing_id_; 705 int32 render_view_routing_id_;
753 // Map frame_url to corresponding serialized_content. 706 std::string serialization_output_;
754 typedef base::hash_map<std::string, std::string> SerializedFrameContentMap;
755 SerializedFrameContentMap serialized_frame_map_;
756 // Map frame_url to corresponding status of serialization finish. 707 // Map frame_url to corresponding status of serialization finish.
757 typedef base::hash_map<std::string, bool> SerializationFinishStatusMap; 708 typedef base::hash_map<std::string, bool> SerializationFinishStatusMap;
758 SerializationFinishStatusMap serialization_finish_status_; 709 SerializationFinishStatusMap serialization_finish_status_;
759 // Flag indicates whether the process of serializing DOM is finished or not. 710 // Flag indicates whether the process of serializing DOM is finished or not.
760 bool serialized_; 711 bool got_end_of_frame_notification_;
761 // The local_directory_name_ is dummy relative path of directory which 712 // The local_directory_name_ is dummy relative path of directory which
762 // contain all saved auxiliary files included all sub frames and resources. 713 // contain all saved auxiliary files included all sub frames and resources.
763 const base::FilePath local_directory_name_; 714 const base::FilePath local_directory_name_;
764 }; 715 };
765 716
766 // If original contents have document type, the serialized contents also have 717 // If original contents have document type, the serialized contents also have
767 // document type. 718 // document type.
768 // Disabled by ellyjones@ on 2015-05-18, see https://crbug.com/488495. 719 // Disabled by ellyjones@ on 2015-05-18, see https://crbug.com/488495.
769 #if defined(OS_MACOSX) 720 #if defined(OS_MACOSX)
770 #define MAYBE_SerializeHTMLDOMWithDocType DISABLED_SerializeHTMLDOMWithDocType 721 #define MAYBE_SerializeHTMLDOMWithDocType DISABLED_SerializeHTMLDOMWithDocType
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
1002 NavigateToURL(shell(), file_url); 953 NavigateToURL(shell(), file_url);
1003 954
1004 PostTaskToInProcessRendererAndWait( 955 PostTaskToInProcessRendererAndWait(
1005 base::Bind( 956 base::Bind(
1006 &DomSerializerTests:: 957 &DomSerializerTests::
1007 SubResourceForElementsInNonHTMLNamespaceOnRenderer, 958 SubResourceForElementsInNonHTMLNamespaceOnRenderer,
1008 base::Unretained(this), file_url)); 959 base::Unretained(this), file_url));
1009 } 960 }
1010 961
1011 } // namespace content 962 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698