2 * Copyright (C) 2011 Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 #include "core/dom/Document.h"
33 #include "public/platform/Platform.h"
34 #include "public/platform/WebString.h"
35 #include "public/platform/WebThread.h"
36 #include "public/platform/WebURL.h"
37 #include "public/platform/WebURLRequest.h"
38 #include "public/platform/WebURLResponse.h"
39 #include "public/platform/WebUnitTestSupport.h"
40 #include "public/web/WebDocument.h"
41 #include "public/web/WebFrame.h"
42 #include "public/web/WebPageSerializer.h"
43 #include "public/web/WebPageSerializerClient.h"
44 #include "public/web/WebScriptSource.h"
45 #include "public/web/WebSettings.h"
46 #include "public/web/WebView.h"
47 #include "web/tests/FrameTestHelpers.h"
48 #include "web/tests/URLTestHelpers.h"
49 #include <gtest/gtest.h>
51 using namespace blink;
52 using WebCore::Document;
53 using blink::FrameTestHelpers::runPendingTasks;
54 using blink::URLTestHelpers::toKURL;
55 using blink::URLTestHelpers::registerMockedURLLoad;
61 LineReader(const std::string& text) : m_text(text), m_index(0) { }
62 bool getNextLine(std::string* line)
65 if (m_index >= m_text.length())
68 size_t endOfLineIndex = m_text.find("\r\n", m_index);
69 if (endOfLineIndex == std::string::npos) {
70 *line = m_text.substr(m_index);
71 m_index = m_text.length();
73 *line = m_text.substr(m_index, endOfLineIndex - m_index);
74 m_index = endOfLineIndex + 2;
84 class LengthCountingWebPageSerializerClient : public WebPageSerializerClient {
86 LengthCountingWebPageSerializerClient(size_t* counter)
91 virtual void didSerializeDataForFrame(const WebURL& frameURL, const WebCString& data, PageSerializationStatus status) {
92 *m_counter += data.length();
99 class FrameDataWebPageSerializerClient : public WebPageSerializerClient {
101 FrameDataWebPageSerializerClient(const WebURL& frameURL, WebString* serializationData)
102 : m_frameURL(frameURL)
103 , m_serializationData(serializationData)
107 virtual void didSerializeDataForFrame(const WebURL& frameURL, const WebCString& data, PageSerializationStatus status)
109 if (frameURL != m_frameURL)
111 *m_serializationData = data.utf16();
116 WebString* m_serializationData;
119 class WebPageNewSerializeTest : public testing::Test {
121 WebPageNewSerializeTest()
122 : m_htmlMimeType(WebString::fromUTF8("text/html"))
123 , m_xhtmlMimeType(WebString::fromUTF8("application/xhtml+xml"))
124 , m_cssMimeType(WebString::fromUTF8("text/css"))
125 , m_pngMimeType(WebString::fromUTF8("image/png"))
126 , m_svgMimeType(WebString::fromUTF8("image/svg+xml"))
133 // We want the images to load and JavaScript to be on.
134 m_helper.initialize(true, 0, 0, &configureSettings);
137 virtual void TearDown()
139 Platform::current()->unitTestSupport()->unregisterAllMockedURLs();
142 WebURL setUpCSSTestPage()
144 WebURL topFrameURL = toKURL("http://www.test.com");
145 registerMockedURLLoad(topFrameURL, WebString::fromUTF8("css_test_page.html"), WebString::fromUTF8("pageserializer/"), htmlMimeType());
146 registerMockedURLLoad(toKURL("http://www.test.com/link_styles.css"), WebString::fromUTF8("link_styles.css"), WebString::fromUTF8("pageserializer/"), cssMimeType());
147 registerMockedURLLoad(toKURL("http://www.test.com/import_style_from_link.css"), WebString::fromUTF8("import_style_from_link.css"), WebString::fromUTF8("pageserializer/"), cssMimeType());
148 registerMockedURLLoad(toKURL("http://www.test.com/import_styles.css"), WebString::fromUTF8("import_styles.css"), WebString::fromUTF8("pageserializer/"), cssMimeType());
149 registerMockedURLLoad(toKURL("http://www.test.com/red_background.png"), WebString::fromUTF8("red_background.png"), WebString::fromUTF8("pageserializer/"), pngMimeType());
150 registerMockedURLLoad(toKURL("http://www.test.com/orange_background.png"), WebString::fromUTF8("orange_background.png"), WebString::fromUTF8("pageserializer/"), pngMimeType());
151 registerMockedURLLoad(toKURL("http://www.test.com/yellow_background.png"), WebString::fromUTF8("yellow_background.png"), WebString::fromUTF8("pageserializer/"), pngMimeType());
152 registerMockedURLLoad(toKURL("http://www.test.com/green_background.png"), WebString::fromUTF8("green_background.png"), WebString::fromUTF8("pageserializer/"), pngMimeType());
153 registerMockedURLLoad(toKURL("http://www.test.com/blue_background.png"), WebString::fromUTF8("blue_background.png"), WebString::fromUTF8("pageserializer/"), pngMimeType());
154 registerMockedURLLoad(toKURL("http://www.test.com/purple_background.png"), WebString::fromUTF8("purple_background.png"), WebString::fromUTF8("pageserializer/"), pngMimeType());
155 registerMockedURLLoad(toKURL("http://www.test.com/ul-dot.png"), WebString::fromUTF8("ul-dot.png"), WebString::fromUTF8("pageserializer/"), pngMimeType());
156 registerMockedURLLoad(toKURL("http://www.test.com/ol-dot.png"), WebString::fromUTF8("ol-dot.png"), WebString::fromUTF8("pageserializer/"), pngMimeType());
160 void loadURLInTopFrame(const WebURL& url)
162 WebURLRequest urlRequest;
163 urlRequest.initialize();
164 urlRequest.setURL(url);
165 m_helper.webView()->mainFrame()->loadRequest(urlRequest);
166 // Make sure any pending request get served.
167 Platform::current()->unitTestSupport()->serveAsynchronousMockedRequests();
168 // Some requests get delayed, run the timer.
170 // Server the delayed resources.
171 Platform::current()->unitTestSupport()->serveAsynchronousMockedRequests();
174 const WebString& htmlMimeType() const { return m_htmlMimeType; }
175 const WebString& xhtmlMimeType() const { return m_xhtmlMimeType; }
176 const WebString& cssMimeType() const { return m_cssMimeType; }
177 const WebString& pngMimeType() const { return m_pngMimeType; }
178 const WebString& svgMimeType() const { return m_svgMimeType; }
180 static bool resourceVectorContains(const WebVector<WebPageSerializer::Resource>& resources, const char* url, const char* mimeType)
182 WebURL webURL = WebURL(toKURL(url));
183 for (size_t i = 0; i < resources.size(); ++i) {
184 const WebPageSerializer::Resource& resource = resources[i];
185 if (resource.url == webURL && !resource.data.isEmpty() && !resource.mimeType.compare(WebCString(mimeType)))
191 WebView* webView() const { return m_helper.webView(); }
194 static void configureSettings(WebSettings* settings)
196 settings->setImagesEnabled(true);
197 settings->setLoadsImagesAutomatically(true);
198 settings->setJavaScriptEnabled(true);
201 FrameTestHelpers::WebViewHelper m_helper;
202 WebString m_htmlMimeType;
203 WebString m_xhtmlMimeType;
204 WebString m_cssMimeType;
205 WebString m_pngMimeType;
206 WebString m_svgMimeType;
209 // Tests that a page with resources and sub-frame is reported with all its resources.
210 TEST_F(WebPageNewSerializeTest, PageWithFrames)
212 // Register the mocked frames.
213 WebURL topFrameURL = toKURL("http://www.test.com");
214 registerMockedURLLoad(topFrameURL, WebString::fromUTF8("top_frame.html"), WebString::fromUTF8("pageserializer/"), htmlMimeType());
215 registerMockedURLLoad(toKURL("http://www.test.com/iframe.html"), WebString::fromUTF8("iframe.html"), WebString::fromUTF8("pageserializer/"), htmlMimeType());
216 registerMockedURLLoad(toKURL("http://www.test.com/iframe2.html"), WebString::fromUTF8("iframe2.html"), WebString::fromUTF8("pageserializer/"), htmlMimeType());
217 registerMockedURLLoad(toKURL("http://www.test.com/red_background.png"), WebString::fromUTF8("red_background.png"), WebString::fromUTF8("pageserializer/"), pngMimeType());
218 registerMockedURLLoad(toKURL("http://www.test.com/green_background.png"), WebString::fromUTF8("green_background.png"), WebString::fromUTF8("pageserializer/"), pngMimeType());
219 registerMockedURLLoad(toKURL("http://www.test.com/blue_background.png"), WebString::fromUTF8("blue_background.png"), WebString::fromUTF8("pageserializer/"), pngMimeType());
221 loadURLInTopFrame(topFrameURL);
222 // OBJECT/EMBED have some delay to start to load their content. The first
223 // serveAsynchronousMockedRequests call in loadURLInTopFrame() finishes
225 RefPtrWillBeRawPtr<Document> document = static_cast<PassRefPtrWillBeRawPtr<Document> >(webView()->mainFrame()->document());
226 document->updateLayoutIgnorePendingStylesheets(Document::RunPostLayoutTasksSynchronously);
227 Platform::current()->unitTestSupport()->serveAsynchronousMockedRequests();
229 WebVector<WebPageSerializer::Resource> resources;
230 WebPageSerializer::serialize(webView(), &resources);
231 ASSERT_FALSE(resources.isEmpty());
233 // The first resource should be the main-frame.
234 const WebPageSerializer::Resource& resource = resources[0];
235 EXPECT_TRUE(resource.url == WebURL(toKURL("http://www.test.com")));
236 EXPECT_EQ(0, resource.mimeType.compare(WebCString("text/html")));
237 EXPECT_FALSE(resource.data.isEmpty());
239 EXPECT_EQ(6U, resources.size()); // There should be no duplicates.
240 EXPECT_TRUE(resourceVectorContains(resources, "http://www.test.com/red_background.png", "image/png"));
241 EXPECT_TRUE(resourceVectorContains(resources, "http://www.test.com/green_background.png", "image/png"));
242 EXPECT_TRUE(resourceVectorContains(resources, "http://www.test.com/blue_background.png", "image/png"));
243 EXPECT_TRUE(resourceVectorContains(resources, "http://www.test.com/iframe.html", "text/html"));
244 EXPECT_TRUE(resourceVectorContains(resources, "http://www.test.com/iframe2.html", "text/html"));
247 // Test that when serializing a page, all CSS resources are reported, including url()'s
248 // and imports and links. Note that we don't test the resources contents, we only make sure
249 // they are all reported with the right mime type and that they contain some data.
250 TEST_F(WebPageNewSerializeTest, FAILS_CSSResources)
252 // Register the mocked frame and load it.
253 WebURL topFrameURL = setUpCSSTestPage();
254 loadURLInTopFrame(topFrameURL);
256 WebVector<WebPageSerializer::Resource> resources;
257 WebPageSerializer::serialize(webView(), &resources);
258 ASSERT_FALSE(resources.isEmpty());
260 // The first resource should be the main-frame.
261 const WebPageSerializer::Resource& resource = resources[0];
262 EXPECT_TRUE(resource.url == WebURL(toKURL("http://www.test.com")));
263 EXPECT_EQ(0, resource.mimeType.compare(WebCString("text/html")));
264 EXPECT_FALSE(resource.data.isEmpty());
266 EXPECT_EQ(12U, resources.size()); // There should be no duplicates.
267 EXPECT_TRUE(resourceVectorContains(resources, "http://www.test.com/link_styles.css", "text/css"));
268 EXPECT_TRUE(resourceVectorContains(resources, "http://www.test.com/import_styles.css", "text/css"));
269 EXPECT_TRUE(resourceVectorContains(resources, "http://www.test.com/import_style_from_link.css", "text/css"));
270 EXPECT_TRUE(resourceVectorContains(resources, "http://www.test.com/red_background.png", "image/png"));
271 EXPECT_TRUE(resourceVectorContains(resources, "http://www.test.com/orange_background.png", "image/png"));
272 EXPECT_TRUE(resourceVectorContains(resources, "http://www.test.com/yellow_background.png", "image/png"));
273 EXPECT_TRUE(resourceVectorContains(resources, "http://www.test.com/green_background.png", "image/png"));
274 EXPECT_TRUE(resourceVectorContains(resources, "http://www.test.com/blue_background.png", "image/png"));
275 EXPECT_TRUE(resourceVectorContains(resources, "http://www.test.com/purple_background.png", "image/png"));
276 EXPECT_TRUE(resourceVectorContains(resources, "http://www.test.com/ul-dot.png", "image/png"));
277 EXPECT_TRUE(resourceVectorContains(resources, "http://www.test.com/ol-dot.png", "image/png"));
280 // Tests that when serializing a page with blank frames these are reported with their resources.
281 TEST_F(WebPageNewSerializeTest, BlankFrames)
283 // Register the mocked frame and load it.
284 WebURL topFrameURL = toKURL("http://www.test.com");
285 registerMockedURLLoad(topFrameURL, WebString::fromUTF8("blank_frames.html"), WebString::fromUTF8("pageserializer/"), htmlMimeType());
286 registerMockedURLLoad(toKURL("http://www.test.com/red_background.png"), WebString::fromUTF8("red_background.png"), WebString::fromUTF8("pageserializer/"), pngMimeType());
287 registerMockedURLLoad(toKURL("http://www.test.com/orange_background.png"), WebString::fromUTF8("orange_background.png"), WebString::fromUTF8("pageserializer/"), pngMimeType());
288 registerMockedURLLoad(toKURL("http://www.test.com/blue_background.png"), WebString::fromUTF8("blue_background.png"), WebString::fromUTF8("pageserializer/"), pngMimeType());
290 loadURLInTopFrame(topFrameURL);
292 WebVector<WebPageSerializer::Resource> resources;
293 WebPageSerializer::serialize(webView(), &resources);
294 ASSERT_FALSE(resources.isEmpty());
296 // The first resource should be the main-frame.
297 const WebPageSerializer::Resource& resource = resources[0];
298 EXPECT_TRUE(resource.url == WebURL(toKURL("http://www.test.com")));
299 EXPECT_EQ(0, resource.mimeType.compare(WebCString("text/html")));
300 EXPECT_FALSE(resource.data.isEmpty());
302 EXPECT_EQ(7U, resources.size()); // There should be no duplicates.
303 EXPECT_TRUE(resourceVectorContains(resources, "http://www.test.com/red_background.png", "image/png"));
304 EXPECT_TRUE(resourceVectorContains(resources, "http://www.test.com/orange_background.png", "image/png"));
305 EXPECT_TRUE(resourceVectorContains(resources, "http://www.test.com/blue_background.png", "image/png"));
306 // The blank frames should have got a magic URL.
307 EXPECT_TRUE(resourceVectorContains(resources, "wyciwyg://frame/0", "text/html"));
308 EXPECT_TRUE(resourceVectorContains(resources, "wyciwyg://frame/1", "text/html"));
309 EXPECT_TRUE(resourceVectorContains(resources, "wyciwyg://frame/2", "text/html"));
312 TEST_F(WebPageNewSerializeTest, SerializeXMLHasRightDeclaration)
314 WebURL topFrameURL = toKURL("http://www.test.com/simple.xhtml");
315 registerMockedURLLoad(topFrameURL, WebString::fromUTF8("simple.xhtml"), WebString::fromUTF8("pageserializer/"), xhtmlMimeType());
317 loadURLInTopFrame(topFrameURL);
319 WebVector<WebPageSerializer::Resource> resources;
320 WebPageSerializer::serialize(webView(), &resources);
321 ASSERT_FALSE(resources.isEmpty());
323 // We expect only one resource, the XML.
324 ASSERT_EQ(1U, resources.size());
325 std::string xml = std::string(resources[0].data.data());
327 // We should have one and only one instance of the XML declaration.
328 size_t pos = xml.find("<?xml version=");
329 ASSERT_TRUE(pos != std::string::npos);
331 pos = xml.find("<?xml version=", pos + 1);
332 ASSERT_TRUE(pos == std::string::npos);
335 TEST_F(WebPageNewSerializeTest, FAILS_TestMHTMLEncoding)
337 // Load a page with some CSS and some images.
338 WebURL topFrameURL = setUpCSSTestPage();
339 loadURLInTopFrame(topFrameURL);
341 WebCString mhtmlData = WebPageSerializer::serializeToMHTML(webView());
342 ASSERT_FALSE(mhtmlData.isEmpty());
344 // Read the MHTML data line per line and do some pseudo-parsing to make sure the right encoding is used for the different sections.
345 LineReader lineReader(std::string(mhtmlData.data()));
346 int sectionCheckedCount = 0;
347 const char* expectedEncoding = 0;
349 while (lineReader.getNextLine(&line)) {
350 if (!line.find("Content-Type:")) {
351 ASSERT_FALSE(expectedEncoding);
352 if (line.find("multipart/related;") != std::string::npos) {
353 // Skip this one, it's part of the MHTML header.
356 if (line.find("text/") != std::string::npos)
357 expectedEncoding = "quoted-printable";
358 else if (line.find("image/") != std::string::npos)
359 expectedEncoding = "base64";
361 FAIL() << "Unexpected Content-Type: " << line;
364 if (!line.find("Content-Transfer-Encoding:")) {
365 ASSERT_TRUE(expectedEncoding);
366 EXPECT_TRUE(line.find(expectedEncoding) != std::string::npos);
367 expectedEncoding = 0;
368 sectionCheckedCount++;
371 EXPECT_EQ(12, sectionCheckedCount);
374 // Test that we don't regress https://bugs.webkit.org/show_bug.cgi?id=99105
375 TEST_F(WebPageNewSerializeTest, SVGImageDontCrash)
377 WebURL pageUrl = toKURL("http://www.test.com");
378 WebURL imageUrl = toKURL("http://www.test.com/green_rectangle.svg");
380 registerMockedURLLoad(pageUrl, WebString::fromUTF8("page_with_svg_image.html"), WebString::fromUTF8("pageserializer/"), htmlMimeType());
381 registerMockedURLLoad(imageUrl, WebString::fromUTF8("green_rectangle.svg"), WebString::fromUTF8("pageserializer/"), svgMimeType());
383 loadURLInTopFrame(pageUrl);
385 WebCString mhtml = WebPageSerializer::serializeToMHTML(webView());
386 // We expect some data to be generated.
387 EXPECT_GT(mhtml.length(), 50U);
391 TEST_F(WebPageNewSerializeTest, DontIncludeErrorImage)
393 WebURL pageUrl = toKURL("http://www.test.com");
394 WebURL imageUrl = toKURL("http://www.test.com/error_image.png");
396 registerMockedURLLoad(pageUrl, WebString::fromUTF8("page_with_img_error.html"), WebString::fromUTF8("pageserializer/"), htmlMimeType());
397 registerMockedURLLoad(imageUrl, WebString::fromUTF8("error_image.png"), WebString::fromUTF8("pageserializer/"), pngMimeType());
399 loadURLInTopFrame(pageUrl);
401 WebCString mhtmlData = WebPageSerializer::serializeToMHTML(webView());
402 ASSERT_FALSE(mhtmlData.isEmpty());
404 // Sniff the MHTML data to make sure image content is excluded.
405 LineReader lineReader(std::string(mhtmlData.data()));
407 while (lineReader.getNextLine(&line)) {
408 if (line.find("image/") != std::string::npos)
409 FAIL() << "Error Image was not excluded " << line;
414 TEST_F(WebPageNewSerializeTest, NamespaceElementsDontCrash)
416 WebURL pageUrl = toKURL("http://www.test.com");
417 registerMockedURLLoad(pageUrl, WebString::fromUTF8("namespace_element.html"), WebString::fromUTF8("pageserializer/"), htmlMimeType());
419 loadURLInTopFrame(pageUrl);
421 WebVector<WebURL> localLinks(static_cast<size_t>(1));
422 WebVector<WebString> localPaths(static_cast<size_t>(1));
423 localLinks[0] = pageUrl;
424 localPaths[0] = WebString("/");
427 LengthCountingWebPageSerializerClient client(&counter);
429 // We just want to make sure nothing crazy happens, namely that no
430 // assertions are hit. As a sanity check, we also make sure that some data
432 WebPageSerializer::serialize(webView()->mainFrame()->toWebLocalFrame(), true, &client, localLinks, localPaths, WebString(""));
434 EXPECT_GT(counter, 0U);
437 TEST_F(WebPageNewSerializeTest, SubFrameSerialization)
439 WebURL pageUrl = toKURL("http://www.test.com");
440 registerMockedURLLoad(pageUrl, WebString::fromUTF8("top_frame.html"), WebString::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"), WebString::fromUTF8("red_background.png"), WebString::fromUTF8("pageserializer/"), pngMimeType());
444 registerMockedURLLoad(toKURL("http://www.test.com/green_background.png"), WebString::fromUTF8("green_background.png"), WebString::fromUTF8("pageserializer/"), pngMimeType());
445 registerMockedURLLoad(toKURL("http://www.test.com/blue_background.png"), WebString::fromUTF8("blue_background.png"), WebString::fromUTF8("pageserializer/"), pngMimeType());
447 loadURLInTopFrame(pageUrl);
449 // OBJECT/EMBED have some delay to start to load their content. The first
450 // serveAsynchronousMockedRequests call in loadURLInTopFrame() finishes
452 RefPtrWillBeRawPtr<Document> document = static_cast<PassRefPtrWillBeRawPtr<Document> >(webView()->mainFrame()->document());
453 document->updateLayoutIgnorePendingStylesheets(Document::RunPostLayoutTasksSynchronously);
454 Platform::current()->unitTestSupport()->serveAsynchronousMockedRequests();
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");
463 WebString serializedData;
464 FrameDataWebPageSerializerClient client(pageUrl, &serializedData);
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
469 WebPageSerializer::serialize(webView()->mainFrame()->toWebLocalFrame(), true, &client, localLinks, localPaths, WebString(""));
472 EXPECT_TRUE(static_cast<String>(serializedData).contains("src=\"SavedFiles/iframe.html\""));
477 TEST_F(WebPageNewSerializeTest, TestMHTMLEncodingWithDataURL)
479 // Load a page with some data urls.
480 WebURL topFrameURL = toKURL("http://www.test.com");
481 registerMockedURLLoad(topFrameURL, WebString::fromUTF8("page_with_data.html"), WebString::fromUTF8("pageserializer/"), htmlMimeType());
482 loadURLInTopFrame(topFrameURL);
484 WebCString mhtmlData = WebPageSerializer::serializeToMHTML(webView());
485 ASSERT_FALSE(mhtmlData.isEmpty());
487 // Read the MHTML data line and check that the string data:image is found
489 size_t nbDataURLs = 0;
490 LineReader lineReader(std::string(mhtmlData.data()));
492 while (lineReader.getNextLine(&line)) {
493 if (line.find("data:image") != std::string::npos)
496 EXPECT_EQ(1u, nbDataURLs);
500 TEST_F(WebPageNewSerializeTest, TestMHTMLEncodingWithMorphingDataURL)
502 // Load a page with some data urls.
503 WebURL topFrameURL = toKURL("http://www.test.com");
504 registerMockedURLLoad(topFrameURL, WebString::fromUTF8("page_with_morphing_data.html"), WebString::fromUTF8("pageserializer/"), htmlMimeType());
505 loadURLInTopFrame(topFrameURL);
507 WebCString mhtmlData = WebPageSerializer::serializeToMHTML(webView());
508 ASSERT_FALSE(mhtmlData.isEmpty());
510 // Read the MHTML data line and check that the string data:image is found
511 // exactly two times.
512 size_t nbDataURLs = 0;
513 LineReader lineReader(std::string(mhtmlData.data()));
515 while (lineReader.getNextLine(&line)) {
516 if (line.find("data:text") != std::string::npos)
519 EXPECT_EQ(2u, nbDataURLs);