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

Side by Side Diff: Source/web/tests/WebPageNewSerializerTest.cpp

Issue 275433011: Regression(r169412): Fix serialization of frame / iframe (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 7 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 | Annotate | Revision Log
« no previous file with comments | « Source/core/html/HTMLFrameElementBase.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2011 Google Inc. All rights reserved. 2 * Copyright (C) 2011 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 } 89 }
90 90
91 virtual void didSerializeDataForFrame(const WebURL& frameURL, const WebCStri ng& data, PageSerializationStatus status) { 91 virtual void didSerializeDataForFrame(const WebURL& frameURL, const WebCStri ng& data, PageSerializationStatus status) {
92 *m_counter += data.length(); 92 *m_counter += data.length();
93 } 93 }
94 94
95 private: 95 private:
96 size_t* m_counter; 96 size_t* m_counter;
97 }; 97 };
98 98
99 class FrameDataWebPageSerializerClient : public WebPageSerializerClient {
100 public:
101 FrameDataWebPageSerializerClient(const WebURL& frameURL, WebString* serializ ationData)
102 : m_frameURL(frameURL)
103 , m_serializationData(serializationData)
104 {
105 }
106
107 virtual void didSerializeDataForFrame(const WebURL& frameURL, const WebCStri ng& data, PageSerializationStatus status)
108 {
109 if (frameURL != m_frameURL)
110 return;
111 *m_serializationData = data.utf16();
112 }
113
114 private:
115 WebURL m_frameURL;
116 WebString* m_serializationData;
117 };
118
99 class WebPageNewSerializeTest : public testing::Test { 119 class WebPageNewSerializeTest : public testing::Test {
100 public: 120 public:
101 WebPageNewSerializeTest() 121 WebPageNewSerializeTest()
102 : m_htmlMimeType(WebString::fromUTF8("text/html")) 122 : m_htmlMimeType(WebString::fromUTF8("text/html"))
103 , m_xhtmlMimeType(WebString::fromUTF8("application/xhtml+xml")) 123 , m_xhtmlMimeType(WebString::fromUTF8("application/xhtml+xml"))
104 , m_cssMimeType(WebString::fromUTF8("text/css")) 124 , m_cssMimeType(WebString::fromUTF8("text/css"))
105 , m_pngMimeType(WebString::fromUTF8("image/png")) 125 , m_pngMimeType(WebString::fromUTF8("image/png"))
106 , m_svgMimeType(WebString::fromUTF8("image/svg+xml")) 126 , m_svgMimeType(WebString::fromUTF8("image/svg+xml"))
107 { 127 {
108 } 128 }
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after
407 LengthCountingWebPageSerializerClient client(&counter); 427 LengthCountingWebPageSerializerClient client(&counter);
408 428
409 // We just want to make sure nothing crazy happens, namely that no 429 // We just want to make sure nothing crazy happens, namely that no
410 // assertions are hit. As a sanity check, we also make sure that some data 430 // assertions are hit. As a sanity check, we also make sure that some data
411 // was returned. 431 // was returned.
412 WebPageSerializer::serialize(webView()->mainFrame()->toWebLocalFrame(), true , &client, localLinks, localPaths, WebString("")); 432 WebPageSerializer::serialize(webView()->mainFrame()->toWebLocalFrame(), true , &client, localLinks, localPaths, WebString(""));
413 433
414 EXPECT_GT(counter, 0U); 434 EXPECT_GT(counter, 0U);
415 } 435 }
416 436
437 TEST_F(WebPageNewSerializeTest, SubFrameSerialization)
438 {
439 WebURL pageUrl = toKURL("http://www.test.com");
440 registerMockedURLLoad(pageUrl, WebString::fromUTF8("top_frame.html"), WebStr ing::fromUTF8("pageserializer/"), htmlMimeType());
441 registerMockedURLLoad(toKURL("http://www.test.com/iframe.html"), WebString:: fromUTF8("iframe.html"), WebString::fromUTF8("pageserializer/"), htmlMimeType()) ;
442 registerMockedURLLoad(toKURL("http://www.test.com/iframe2.html"), WebString: :fromUTF8("iframe2.html"), WebString::fromUTF8("pageserializer/"), htmlMimeType( ));
443 registerMockedURLLoad(toKURL("http://www.test.com/red_background.png"), WebS tring::fromUTF8("red_background.png"), WebString::fromUTF8("pageserializer/"), p ngMimeType());
444 registerMockedURLLoad(toKURL("http://www.test.com/green_background.png"), We bString::fromUTF8("green_background.png"), WebString::fromUTF8("pageserializer/" ), pngMimeType());
445 registerMockedURLLoad(toKURL("http://www.test.com/blue_background.png"), Web String::fromUTF8("blue_background.png"), WebString::fromUTF8("pageserializer/"), pngMimeType());
446
447 loadURLInTopFrame(pageUrl);
448
449 // OBJECT/EMBED have some delay to start to load their content. The first
450 // serveAsynchronousMockedRequests call in loadURLInTopFrame() finishes
451 // before the start.
452 RefPtrWillBeRawPtr<Document> document = static_cast<PassRefPtrWillBeRawPtr<D ocument> >(webView()->mainFrame()->document());
453 document->updateLayoutIgnorePendingStylesheets(Document::RunPostLayoutTasksS ynchronously);
454 Platform::current()->unitTestSupport()->serveAsynchronousMockedRequests();
455
456 WebVector<WebURL> localLinks(static_cast<size_t>(2));
457 WebVector<WebString> localPaths(static_cast<size_t>(2));
458 localLinks[0] = pageUrl;
459 localPaths[0] = WebString("/");
460 localLinks[1] = toKURL("http://www.test.com/iframe.html");
461 localPaths[1] = WebString("SavedFiles/iframe.html");
462
463 WebString serializedData;
464 FrameDataWebPageSerializerClient client(pageUrl, &serializedData);
465
466 // We just want to make sure nothing crazy happens, namely that no
467 // assertions are hit. As a sanity check, we also make sure that some data
468 // was returned.
469 WebPageSerializer::serialize(webView()->mainFrame()->toWebLocalFrame(), true , &client, localLinks, localPaths, WebString(""));
470
471 // Subframe src
472 EXPECT_TRUE(static_cast<String>(serializedData).contains("src=\"SavedFiles/i frame.html\""));
473 }
474
417 } 475 }
418 476
419 TEST_F(WebPageNewSerializeTest, TestMHTMLEncodingWithDataURL) 477 TEST_F(WebPageNewSerializeTest, TestMHTMLEncodingWithDataURL)
420 { 478 {
421 // Load a page with some data urls. 479 // Load a page with some data urls.
422 WebURL topFrameURL = toKURL("http://www.test.com"); 480 WebURL topFrameURL = toKURL("http://www.test.com");
423 registerMockedURLLoad(topFrameURL, WebString::fromUTF8("page_with_data.html" ), WebString::fromUTF8("pageserializer/"), htmlMimeType()); 481 registerMockedURLLoad(topFrameURL, WebString::fromUTF8("page_with_data.html" ), WebString::fromUTF8("pageserializer/"), htmlMimeType());
424 loadURLInTopFrame(topFrameURL); 482 loadURLInTopFrame(topFrameURL);
425 483
426 WebCString mhtmlData = WebPageSerializer::serializeToMHTML(webView()); 484 WebCString mhtmlData = WebPageSerializer::serializeToMHTML(webView());
(...skipping 26 matching lines...) Expand all
453 // exactly two times. 511 // exactly two times.
454 size_t nbDataURLs = 0; 512 size_t nbDataURLs = 0;
455 LineReader lineReader(std::string(mhtmlData.data())); 513 LineReader lineReader(std::string(mhtmlData.data()));
456 std::string line; 514 std::string line;
457 while (lineReader.getNextLine(&line)) { 515 while (lineReader.getNextLine(&line)) {
458 if (line.find("data:text") != std::string::npos) 516 if (line.find("data:text") != std::string::npos)
459 nbDataURLs++; 517 nbDataURLs++;
460 } 518 }
461 EXPECT_EQ(2u, nbDataURLs); 519 EXPECT_EQ(2u, nbDataURLs);
462 } 520 }
OLDNEW
« no previous file with comments | « Source/core/html/HTMLFrameElementBase.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698