Upstream version 8.37.180.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / web / tests / WebPageNewSerializerTest.cpp
1 /*
2  * Copyright (C) 2011 Google Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are
6  * met:
7  *
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
13  * distribution.
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.
17  *
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.
29  */
30 #include "config.h"
31
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>
50
51 using namespace blink;
52 using WebCore::Document;
53 using blink::FrameTestHelpers::runPendingTasks;
54 using blink::URLTestHelpers::toKURL;
55 using blink::URLTestHelpers::registerMockedURLLoad;
56
57 namespace {
58
59 class LineReader {
60 public:
61     LineReader(const std::string& text) : m_text(text), m_index(0) { }
62     bool getNextLine(std::string* line)
63     {
64         line->clear();
65         if (m_index >= m_text.length())
66             return false;
67
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();
72         } else {
73             *line = m_text.substr(m_index, endOfLineIndex - m_index);
74             m_index = endOfLineIndex + 2;
75         }
76         return true;
77     }
78
79 private:
80     std::string m_text;
81     size_t m_index;
82 };
83
84 class LengthCountingWebPageSerializerClient : public WebPageSerializerClient {
85 public:
86     LengthCountingWebPageSerializerClient(size_t* counter)
87         : m_counter(counter)
88     {
89     }
90
91     virtual void didSerializeDataForFrame(const WebURL& frameURL, const WebCString& data, PageSerializationStatus status) {
92         *m_counter += data.length();
93     }
94
95 private:
96     size_t* m_counter;
97 };
98
99 class FrameDataWebPageSerializerClient : public WebPageSerializerClient {
100 public:
101     FrameDataWebPageSerializerClient(const WebURL& frameURL, WebString* serializationData)
102         : m_frameURL(frameURL)
103         , m_serializationData(serializationData)
104     {
105     }
106
107     virtual void didSerializeDataForFrame(const WebURL& frameURL, const WebCString& 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
119 class WebPageNewSerializeTest : public testing::Test {
120 public:
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"))
127     {
128     }
129
130 protected:
131     virtual void SetUp()
132     {
133         // We want the images to load and JavaScript to be on.
134         m_helper.initialize(true, 0, 0, &configureSettings);
135     }
136
137     virtual void TearDown()
138     {
139         Platform::current()->unitTestSupport()->unregisterAllMockedURLs();
140     }
141
142     WebURL setUpCSSTestPage()
143     {
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());
157         return topFrameURL;
158     }
159
160     void loadURLInTopFrame(const WebURL& url)
161     {
162         FrameTestHelpers::loadFrame(m_helper.webView()->mainFrame(), url.string().utf8());
163     }
164
165     const WebString& htmlMimeType() const { return m_htmlMimeType; }
166     const WebString& xhtmlMimeType() const { return m_xhtmlMimeType; }
167     const WebString& cssMimeType() const { return m_cssMimeType; }
168     const WebString& pngMimeType() const { return m_pngMimeType; }
169     const WebString& svgMimeType() const { return m_svgMimeType; }
170
171     static bool resourceVectorContains(const WebVector<WebPageSerializer::Resource>& resources, const char* url, const char* mimeType)
172     {
173         WebURL webURL = WebURL(toKURL(url));
174         for (size_t i = 0; i < resources.size(); ++i) {
175             const WebPageSerializer::Resource& resource = resources[i];
176             if (resource.url == webURL && !resource.data.isEmpty() && !resource.mimeType.compare(WebCString(mimeType)))
177                 return true;
178         }
179         return false;
180     }
181
182     WebView* webView() const { return m_helper.webView(); }
183
184 private:
185     static void configureSettings(WebSettings* settings)
186     {
187         settings->setImagesEnabled(true);
188         settings->setLoadsImagesAutomatically(true);
189         settings->setJavaScriptEnabled(true);
190     }
191
192     FrameTestHelpers::WebViewHelper m_helper;
193     WebString m_htmlMimeType;
194     WebString m_xhtmlMimeType;
195     WebString m_cssMimeType;
196     WebString m_pngMimeType;
197     WebString m_svgMimeType;
198 };
199
200 // Tests that a page with resources and sub-frame is reported with all its resources.
201 TEST_F(WebPageNewSerializeTest, PageWithFrames)
202 {
203     // Register the mocked frames.
204     WebURL topFrameURL = toKURL("http://www.test.com");
205     registerMockedURLLoad(topFrameURL, WebString::fromUTF8("top_frame.html"), WebString::fromUTF8("pageserializer/"), htmlMimeType());
206     registerMockedURLLoad(toKURL("http://www.test.com/iframe.html"), WebString::fromUTF8("iframe.html"), WebString::fromUTF8("pageserializer/"), htmlMimeType());
207     registerMockedURLLoad(toKURL("http://www.test.com/iframe2.html"), WebString::fromUTF8("iframe2.html"), WebString::fromUTF8("pageserializer/"), htmlMimeType());
208     registerMockedURLLoad(toKURL("http://www.test.com/red_background.png"), WebString::fromUTF8("red_background.png"), WebString::fromUTF8("pageserializer/"), pngMimeType());
209     registerMockedURLLoad(toKURL("http://www.test.com/green_background.png"), WebString::fromUTF8("green_background.png"), WebString::fromUTF8("pageserializer/"), pngMimeType());
210     registerMockedURLLoad(toKURL("http://www.test.com/blue_background.png"), WebString::fromUTF8("blue_background.png"), WebString::fromUTF8("pageserializer/"), pngMimeType());
211
212     loadURLInTopFrame(topFrameURL);
213
214     WebVector<WebPageSerializer::Resource> resources;
215     WebPageSerializer::serialize(webView(), &resources);
216     ASSERT_FALSE(resources.isEmpty());
217
218     // The first resource should be the main-frame.
219     const WebPageSerializer::Resource& resource = resources[0];
220     EXPECT_TRUE(resource.url == WebURL(toKURL("http://www.test.com")));
221     EXPECT_EQ(0, resource.mimeType.compare(WebCString("text/html")));
222     EXPECT_FALSE(resource.data.isEmpty());
223
224     EXPECT_EQ(6U, resources.size()); // There should be no duplicates.
225     EXPECT_TRUE(resourceVectorContains(resources, "http://www.test.com/red_background.png", "image/png"));
226     EXPECT_TRUE(resourceVectorContains(resources, "http://www.test.com/green_background.png", "image/png"));
227     EXPECT_TRUE(resourceVectorContains(resources, "http://www.test.com/blue_background.png", "image/png"));
228     EXPECT_TRUE(resourceVectorContains(resources, "http://www.test.com/iframe.html", "text/html"));
229     EXPECT_TRUE(resourceVectorContains(resources, "http://www.test.com/iframe2.html", "text/html"));
230 }
231
232 // Test that when serializing a page, all CSS resources are reported, including url()'s
233 // and imports and links. Note that we don't test the resources contents, we only make sure
234 // they are all reported with the right mime type and that they contain some data.
235 TEST_F(WebPageNewSerializeTest, FAILS_CSSResources)
236 {
237     // Register the mocked frame and load it.
238     WebURL topFrameURL = setUpCSSTestPage();
239     loadURLInTopFrame(topFrameURL);
240
241     WebVector<WebPageSerializer::Resource> resources;
242     WebPageSerializer::serialize(webView(), &resources);
243     ASSERT_FALSE(resources.isEmpty());
244
245     // The first resource should be the main-frame.
246     const WebPageSerializer::Resource& resource = resources[0];
247     EXPECT_TRUE(resource.url == WebURL(toKURL("http://www.test.com")));
248     EXPECT_EQ(0, resource.mimeType.compare(WebCString("text/html")));
249     EXPECT_FALSE(resource.data.isEmpty());
250
251     EXPECT_EQ(12U, resources.size()); // There should be no duplicates.
252     EXPECT_TRUE(resourceVectorContains(resources, "http://www.test.com/link_styles.css", "text/css"));
253     EXPECT_TRUE(resourceVectorContains(resources, "http://www.test.com/import_styles.css", "text/css"));
254     EXPECT_TRUE(resourceVectorContains(resources, "http://www.test.com/import_style_from_link.css", "text/css"));
255     EXPECT_TRUE(resourceVectorContains(resources, "http://www.test.com/red_background.png", "image/png"));
256     EXPECT_TRUE(resourceVectorContains(resources, "http://www.test.com/orange_background.png", "image/png"));
257     EXPECT_TRUE(resourceVectorContains(resources, "http://www.test.com/yellow_background.png", "image/png"));
258     EXPECT_TRUE(resourceVectorContains(resources, "http://www.test.com/green_background.png", "image/png"));
259     EXPECT_TRUE(resourceVectorContains(resources, "http://www.test.com/blue_background.png", "image/png"));
260     EXPECT_TRUE(resourceVectorContains(resources, "http://www.test.com/purple_background.png", "image/png"));
261     EXPECT_TRUE(resourceVectorContains(resources, "http://www.test.com/ul-dot.png", "image/png"));
262     EXPECT_TRUE(resourceVectorContains(resources, "http://www.test.com/ol-dot.png", "image/png"));
263 }
264
265 // Tests that when serializing a page with blank frames these are reported with their resources.
266 TEST_F(WebPageNewSerializeTest, BlankFrames)
267 {
268     // Register the mocked frame and load it.
269     WebURL topFrameURL = toKURL("http://www.test.com");
270     registerMockedURLLoad(topFrameURL, WebString::fromUTF8("blank_frames.html"), WebString::fromUTF8("pageserializer/"), htmlMimeType());
271     registerMockedURLLoad(toKURL("http://www.test.com/red_background.png"), WebString::fromUTF8("red_background.png"), WebString::fromUTF8("pageserializer/"), pngMimeType());
272     registerMockedURLLoad(toKURL("http://www.test.com/orange_background.png"), WebString::fromUTF8("orange_background.png"), WebString::fromUTF8("pageserializer/"), pngMimeType());
273     registerMockedURLLoad(toKURL("http://www.test.com/blue_background.png"), WebString::fromUTF8("blue_background.png"), WebString::fromUTF8("pageserializer/"), pngMimeType());
274
275     loadURLInTopFrame(topFrameURL);
276
277     WebVector<WebPageSerializer::Resource> resources;
278     WebPageSerializer::serialize(webView(), &resources);
279     ASSERT_FALSE(resources.isEmpty());
280
281     // The first resource should be the main-frame.
282     const WebPageSerializer::Resource& resource = resources[0];
283     EXPECT_TRUE(resource.url == WebURL(toKURL("http://www.test.com")));
284     EXPECT_EQ(0, resource.mimeType.compare(WebCString("text/html")));
285     EXPECT_FALSE(resource.data.isEmpty());
286
287     EXPECT_EQ(7U, resources.size()); // There should be no duplicates.
288     EXPECT_TRUE(resourceVectorContains(resources, "http://www.test.com/red_background.png", "image/png"));
289     EXPECT_TRUE(resourceVectorContains(resources, "http://www.test.com/orange_background.png", "image/png"));
290     EXPECT_TRUE(resourceVectorContains(resources, "http://www.test.com/blue_background.png", "image/png"));
291     // The blank frames should have got a magic URL.
292     EXPECT_TRUE(resourceVectorContains(resources, "wyciwyg://frame/0", "text/html"));
293     EXPECT_TRUE(resourceVectorContains(resources, "wyciwyg://frame/1", "text/html"));
294     EXPECT_TRUE(resourceVectorContains(resources, "wyciwyg://frame/2", "text/html"));
295 }
296
297 TEST_F(WebPageNewSerializeTest, SerializeXMLHasRightDeclaration)
298 {
299     WebURL topFrameURL = toKURL("http://www.test.com/simple.xhtml");
300     registerMockedURLLoad(topFrameURL, WebString::fromUTF8("simple.xhtml"), WebString::fromUTF8("pageserializer/"), xhtmlMimeType());
301
302     loadURLInTopFrame(topFrameURL);
303
304     WebVector<WebPageSerializer::Resource> resources;
305     WebPageSerializer::serialize(webView(), &resources);
306     ASSERT_FALSE(resources.isEmpty());
307
308     // We expect only one resource, the XML.
309     ASSERT_EQ(1U, resources.size());
310     std::string xml = std::string(resources[0].data.data());
311
312     // We should have one and only one instance of the XML declaration.
313     size_t pos = xml.find("<?xml version=");
314     ASSERT_TRUE(pos != std::string::npos);
315
316     pos = xml.find("<?xml version=", pos + 1);
317     ASSERT_TRUE(pos == std::string::npos);
318 }
319
320 TEST_F(WebPageNewSerializeTest, FAILS_TestMHTMLEncoding)
321 {
322     // Load a page with some CSS and some images.
323     WebURL topFrameURL = setUpCSSTestPage();
324     loadURLInTopFrame(topFrameURL);
325
326     WebCString mhtmlData = WebPageSerializer::serializeToMHTML(webView());
327     ASSERT_FALSE(mhtmlData.isEmpty());
328
329     // Read the MHTML data line per line and do some pseudo-parsing to make sure the right encoding is used for the different sections.
330     LineReader lineReader(std::string(mhtmlData.data()));
331     int sectionCheckedCount = 0;
332     const char* expectedEncoding = 0;
333     std::string line;
334     while (lineReader.getNextLine(&line)) {
335         if (!line.find("Content-Type:")) {
336             ASSERT_FALSE(expectedEncoding);
337             if (line.find("multipart/related;") != std::string::npos) {
338                 // Skip this one, it's part of the MHTML header.
339                 continue;
340             }
341             if (line.find("text/") != std::string::npos)
342                 expectedEncoding = "quoted-printable";
343             else if (line.find("image/") != std::string::npos)
344                 expectedEncoding = "base64";
345             else
346                 FAIL() << "Unexpected Content-Type: " << line;
347             continue;
348         }
349         if (!line.find("Content-Transfer-Encoding:")) {
350            ASSERT_TRUE(expectedEncoding);
351            EXPECT_TRUE(line.find(expectedEncoding) != std::string::npos);
352            expectedEncoding = 0;
353            sectionCheckedCount++;
354         }
355     }
356     EXPECT_EQ(12, sectionCheckedCount);
357 }
358
359 // Test that we don't regress https://bugs.webkit.org/show_bug.cgi?id=99105
360 TEST_F(WebPageNewSerializeTest, SVGImageDontCrash)
361 {
362     WebURL pageUrl = toKURL("http://www.test.com");
363     WebURL imageUrl = toKURL("http://www.test.com/green_rectangle.svg");
364
365     registerMockedURLLoad(pageUrl, WebString::fromUTF8("page_with_svg_image.html"), WebString::fromUTF8("pageserializer/"), htmlMimeType());
366     registerMockedURLLoad(imageUrl, WebString::fromUTF8("green_rectangle.svg"), WebString::fromUTF8("pageserializer/"), svgMimeType());
367
368     loadURLInTopFrame(pageUrl);
369
370     WebCString mhtml = WebPageSerializer::serializeToMHTML(webView());
371     // We expect some data to be generated.
372     EXPECT_GT(mhtml.length(), 50U);
373 }
374
375
376 TEST_F(WebPageNewSerializeTest, DontIncludeErrorImage)
377 {
378     WebURL pageUrl = toKURL("http://www.test.com");
379     WebURL imageUrl = toKURL("http://www.test.com/error_image.png");
380
381     registerMockedURLLoad(pageUrl, WebString::fromUTF8("page_with_img_error.html"), WebString::fromUTF8("pageserializer/"), htmlMimeType());
382     registerMockedURLLoad(imageUrl, WebString::fromUTF8("error_image.png"), WebString::fromUTF8("pageserializer/"), pngMimeType());
383
384     loadURLInTopFrame(pageUrl);
385
386     WebCString mhtmlData = WebPageSerializer::serializeToMHTML(webView());
387     ASSERT_FALSE(mhtmlData.isEmpty());
388
389     // Sniff the MHTML data to make sure image content is excluded.
390     LineReader lineReader(std::string(mhtmlData.data()));
391     std::string line;
392     while (lineReader.getNextLine(&line)) {
393         if (line.find("image/") != std::string::npos)
394             FAIL() << "Error Image was not excluded " << line;
395     }
396 }
397
398
399 TEST_F(WebPageNewSerializeTest, NamespaceElementsDontCrash)
400 {
401     WebURL pageUrl = toKURL("http://www.test.com");
402     registerMockedURLLoad(pageUrl, WebString::fromUTF8("namespace_element.html"), WebString::fromUTF8("pageserializer/"), htmlMimeType());
403
404     loadURLInTopFrame(pageUrl);
405
406     WebVector<WebURL> localLinks(static_cast<size_t>(1));
407     WebVector<WebString> localPaths(static_cast<size_t>(1));
408     localLinks[0] = pageUrl;
409     localPaths[0] = WebString("/");
410
411     size_t counter = 0;
412     LengthCountingWebPageSerializerClient client(&counter);
413
414     // We just want to make sure nothing crazy happens, namely that no
415     // assertions are hit. As a sanity check, we also make sure that some data
416     // was returned.
417     WebPageSerializer::serialize(webView()->mainFrame()->toWebLocalFrame(), true, &client, localLinks, localPaths, WebString(""));
418
419     EXPECT_GT(counter, 0U);
420 }
421
422 TEST_F(WebPageNewSerializeTest, SubFrameSerialization)
423 {
424     WebURL pageUrl = toKURL("http://www.test.com");
425     registerMockedURLLoad(pageUrl, WebString::fromUTF8("top_frame.html"), WebString::fromUTF8("pageserializer/"), htmlMimeType());
426     registerMockedURLLoad(toKURL("http://www.test.com/iframe.html"), WebString::fromUTF8("iframe.html"), WebString::fromUTF8("pageserializer/"), htmlMimeType());
427     registerMockedURLLoad(toKURL("http://www.test.com/iframe2.html"), WebString::fromUTF8("iframe2.html"), WebString::fromUTF8("pageserializer/"), htmlMimeType());
428     registerMockedURLLoad(toKURL("http://www.test.com/red_background.png"), WebString::fromUTF8("red_background.png"), WebString::fromUTF8("pageserializer/"), pngMimeType());
429     registerMockedURLLoad(toKURL("http://www.test.com/green_background.png"), WebString::fromUTF8("green_background.png"), WebString::fromUTF8("pageserializer/"), pngMimeType());
430     registerMockedURLLoad(toKURL("http://www.test.com/blue_background.png"), WebString::fromUTF8("blue_background.png"), WebString::fromUTF8("pageserializer/"), pngMimeType());
431
432     loadURLInTopFrame(pageUrl);
433
434     WebVector<WebURL> localLinks(static_cast<size_t>(2));
435     WebVector<WebString> localPaths(static_cast<size_t>(2));
436     localLinks[0] = pageUrl;
437     localPaths[0] = WebString("/");
438     localLinks[1] = toKURL("http://www.test.com/iframe.html");
439     localPaths[1] = WebString("SavedFiles/iframe.html");
440
441     WebString serializedData;
442     FrameDataWebPageSerializerClient client(pageUrl, &serializedData);
443
444     // We just want to make sure nothing crazy happens, namely that no
445     // assertions are hit. As a sanity check, we also make sure that some data
446     // was returned.
447     WebPageSerializer::serialize(webView()->mainFrame()->toWebLocalFrame(), true, &client, localLinks, localPaths, WebString(""));
448
449     // Subframe src
450     EXPECT_TRUE(static_cast<String>(serializedData).contains("src=\"SavedFiles/iframe.html\""));
451 }
452
453 }
454
455 TEST_F(WebPageNewSerializeTest, TestMHTMLEncodingWithDataURL)
456 {
457     // Load a page with some data urls.
458     WebURL topFrameURL = toKURL("http://www.test.com");
459     registerMockedURLLoad(topFrameURL, WebString::fromUTF8("page_with_data.html"), WebString::fromUTF8("pageserializer/"), htmlMimeType());
460     loadURLInTopFrame(topFrameURL);
461
462     WebCString mhtmlData = WebPageSerializer::serializeToMHTML(webView());
463     ASSERT_FALSE(mhtmlData.isEmpty());
464
465     // Read the MHTML data line and check that the string data:image is found
466     // exactly one time.
467     size_t nbDataURLs = 0;
468     LineReader lineReader(std::string(mhtmlData.data()));
469     std::string line;
470     while (lineReader.getNextLine(&line)) {
471         if (line.find("data:image") != std::string::npos)
472             nbDataURLs++;
473     }
474     EXPECT_EQ(1u, nbDataURLs);
475 }
476
477
478 TEST_F(WebPageNewSerializeTest, TestMHTMLEncodingWithMorphingDataURL)
479 {
480     // Load a page with some data urls.
481     WebURL topFrameURL = toKURL("http://www.test.com");
482     registerMockedURLLoad(topFrameURL, WebString::fromUTF8("page_with_morphing_data.html"), WebString::fromUTF8("pageserializer/"), htmlMimeType());
483     loadURLInTopFrame(topFrameURL);
484
485     WebCString mhtmlData = WebPageSerializer::serializeToMHTML(webView());
486     ASSERT_FALSE(mhtmlData.isEmpty());
487
488     // Read the MHTML data line and check that the string data:image is found
489     // exactly two times.
490     size_t nbDataURLs = 0;
491     LineReader lineReader(std::string(mhtmlData.data()));
492     std::string line;
493     while (lineReader.getNextLine(&line)) {
494         if (line.find("data:text") != std::string::npos)
495             nbDataURLs++;
496     }
497     EXPECT_EQ(2u, nbDataURLs);
498 }