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 FrameTestHelpers::loadFrame(m_helper.webView()->mainFrame(), url.string().utf8());
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; }
171 static bool resourceVectorContains(const WebVector<WebPageSerializer::Resource>& resources, const char* url, const char* mimeType)
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)))
182 WebView* webView() const { return m_helper.webView(); }
185 static void configureSettings(WebSettings* settings)
187 settings->setImagesEnabled(true);
188 settings->setLoadsImagesAutomatically(true);
189 settings->setJavaScriptEnabled(true);
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;
200 // Tests that a page with resources and sub-frame is reported with all its resources.
201 TEST_F(WebPageNewSerializeTest, PageWithFrames)
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());
212 loadURLInTopFrame(topFrameURL);
214 WebVector<WebPageSerializer::Resource> resources;
215 WebPageSerializer::serialize(webView(), &resources);
216 ASSERT_FALSE(resources.isEmpty());
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());
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"));
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)
237 // Register the mocked frame and load it.
238 WebURL topFrameURL = setUpCSSTestPage();
239 loadURLInTopFrame(topFrameURL);
241 WebVector<WebPageSerializer::Resource> resources;
242 WebPageSerializer::serialize(webView(), &resources);
243 ASSERT_FALSE(resources.isEmpty());
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());
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"));
265 // Tests that when serializing a page with blank frames these are reported with their resources.
266 TEST_F(WebPageNewSerializeTest, BlankFrames)
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());
275 loadURLInTopFrame(topFrameURL);
277 WebVector<WebPageSerializer::Resource> resources;
278 WebPageSerializer::serialize(webView(), &resources);
279 ASSERT_FALSE(resources.isEmpty());
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());
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"));
297 TEST_F(WebPageNewSerializeTest, SerializeXMLHasRightDeclaration)
299 WebURL topFrameURL = toKURL("http://www.test.com/simple.xhtml");
300 registerMockedURLLoad(topFrameURL, WebString::fromUTF8("simple.xhtml"), WebString::fromUTF8("pageserializer/"), xhtmlMimeType());
302 loadURLInTopFrame(topFrameURL);
304 WebVector<WebPageSerializer::Resource> resources;
305 WebPageSerializer::serialize(webView(), &resources);
306 ASSERT_FALSE(resources.isEmpty());
308 // We expect only one resource, the XML.
309 ASSERT_EQ(1U, resources.size());
310 std::string xml = std::string(resources[0].data.data());
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);
316 pos = xml.find("<?xml version=", pos + 1);
317 ASSERT_TRUE(pos == std::string::npos);
320 TEST_F(WebPageNewSerializeTest, FAILS_TestMHTMLEncoding)
322 // Load a page with some CSS and some images.
323 WebURL topFrameURL = setUpCSSTestPage();
324 loadURLInTopFrame(topFrameURL);
326 WebCString mhtmlData = WebPageSerializer::serializeToMHTML(webView());
327 ASSERT_FALSE(mhtmlData.isEmpty());
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;
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.
341 if (line.find("text/") != std::string::npos)
342 expectedEncoding = "quoted-printable";
343 else if (line.find("image/") != std::string::npos)
344 expectedEncoding = "base64";
346 FAIL() << "Unexpected Content-Type: " << line;
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++;
356 EXPECT_EQ(12, sectionCheckedCount);
359 // Test that we don't regress https://bugs.webkit.org/show_bug.cgi?id=99105
360 TEST_F(WebPageNewSerializeTest, SVGImageDontCrash)
362 WebURL pageUrl = toKURL("http://www.test.com");
363 WebURL imageUrl = toKURL("http://www.test.com/green_rectangle.svg");
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());
368 loadURLInTopFrame(pageUrl);
370 WebCString mhtml = WebPageSerializer::serializeToMHTML(webView());
371 // We expect some data to be generated.
372 EXPECT_GT(mhtml.length(), 50U);
376 TEST_F(WebPageNewSerializeTest, DontIncludeErrorImage)
378 WebURL pageUrl = toKURL("http://www.test.com");
379 WebURL imageUrl = toKURL("http://www.test.com/error_image.png");
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());
384 loadURLInTopFrame(pageUrl);
386 WebCString mhtmlData = WebPageSerializer::serializeToMHTML(webView());
387 ASSERT_FALSE(mhtmlData.isEmpty());
389 // Sniff the MHTML data to make sure image content is excluded.
390 LineReader lineReader(std::string(mhtmlData.data()));
392 while (lineReader.getNextLine(&line)) {
393 if (line.find("image/") != std::string::npos)
394 FAIL() << "Error Image was not excluded " << line;
399 TEST_F(WebPageNewSerializeTest, NamespaceElementsDontCrash)
401 WebURL pageUrl = toKURL("http://www.test.com");
402 registerMockedURLLoad(pageUrl, WebString::fromUTF8("namespace_element.html"), WebString::fromUTF8("pageserializer/"), htmlMimeType());
404 loadURLInTopFrame(pageUrl);
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("/");
412 LengthCountingWebPageSerializerClient client(&counter);
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
417 WebPageSerializer::serialize(webView()->mainFrame()->toWebLocalFrame(), true, &client, localLinks, localPaths, WebString(""));
419 EXPECT_GT(counter, 0U);
422 TEST_F(WebPageNewSerializeTest, SubFrameSerialization)
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());
432 loadURLInTopFrame(pageUrl);
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");
441 WebString serializedData;
442 FrameDataWebPageSerializerClient client(pageUrl, &serializedData);
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
447 WebPageSerializer::serialize(webView()->mainFrame()->toWebLocalFrame(), true, &client, localLinks, localPaths, WebString(""));
450 EXPECT_TRUE(static_cast<String>(serializedData).contains("src=\"SavedFiles/iframe.html\""));
455 TEST_F(WebPageNewSerializeTest, TestMHTMLEncodingWithDataURL)
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);
462 WebCString mhtmlData = WebPageSerializer::serializeToMHTML(webView());
463 ASSERT_FALSE(mhtmlData.isEmpty());
465 // Read the MHTML data line and check that the string data:image is found
467 size_t nbDataURLs = 0;
468 LineReader lineReader(std::string(mhtmlData.data()));
470 while (lineReader.getNextLine(&line)) {
471 if (line.find("data:image") != std::string::npos)
474 EXPECT_EQ(1u, nbDataURLs);
478 TEST_F(WebPageNewSerializeTest, TestMHTMLEncodingWithMorphingDataURL)
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);
485 WebCString mhtmlData = WebPageSerializer::serializeToMHTML(webView());
486 ASSERT_FALSE(mhtmlData.isEmpty());
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()));
493 while (lineReader.getNextLine(&line)) {
494 if (line.find("data:text") != std::string::npos)
497 EXPECT_EQ(2u, nbDataURLs);