| OLD | NEW |
| 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 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 198 | 198 |
| 199 FrameTestHelpers::WebViewHelper m_helper; | 199 FrameTestHelpers::WebViewHelper m_helper; |
| 200 | 200 |
| 201 WebString m_htmlMimeType; | 201 WebString m_htmlMimeType; |
| 202 WebString m_xhtmlMimeType; | 202 WebString m_xhtmlMimeType; |
| 203 WebString m_cssMimeType; | 203 WebString m_cssMimeType; |
| 204 WebString m_pngMimeType; | 204 WebString m_pngMimeType; |
| 205 WebString m_svgMimeType; | 205 WebString m_svgMimeType; |
| 206 }; | 206 }; |
| 207 | 207 |
| 208 // Tests that a page with resources and sub-frame is reported with all its resou
rces. | |
| 209 TEST_F(WebPageNewSerializeTest, PageWithFrames) | |
| 210 { | |
| 211 // Register the mocked frames. | |
| 212 registerMockedURLLoad(toTestURL(""), WebString::fromUTF8("top_frame.html"),
WebString::fromUTF8("pageserializer/"), htmlMimeType()); | |
| 213 registerMockedURLLoad(toTestURL("iframe.html"), WebString::fromUTF8("iframe.
html"), WebString::fromUTF8("pageserializer/"), htmlMimeType()); | |
| 214 registerMockedURLLoad(toTestURL("iframe2.html"), WebString::fromUTF8("iframe
2.html"), WebString::fromUTF8("pageserializer/"), htmlMimeType()); | |
| 215 registerMockedURLLoad(toTestURL("red_background.png"), WebString::fromUTF8("
red_background.png"), WebString::fromUTF8("pageserializer/"), pngMimeType()); | |
| 216 registerMockedURLLoad(toTestURL("green_background.png"), WebString::fromUTF8
("green_background.png"), WebString::fromUTF8("pageserializer/"), pngMimeType())
; | |
| 217 registerMockedURLLoad(toTestURL("blue_background.png"), WebString::fromUTF8(
"blue_background.png"), WebString::fromUTF8("pageserializer/"), pngMimeType()); | |
| 218 | |
| 219 loadURLInTopFrame(toKURL(m_baseURL)); | |
| 220 | |
| 221 WebVector<WebPageSerializer::Resource> resources; | |
| 222 WebPageSerializer::serialize(webView(), &resources); | |
| 223 ASSERT_FALSE(resources.isEmpty()); | |
| 224 | |
| 225 // The first resource should be the main-frame. | |
| 226 const WebPageSerializer::Resource& resource = resources[0]; | |
| 227 EXPECT_TRUE(resource.url == WebURL(toKURL(m_baseURL))); | |
| 228 EXPECT_EQ(0, resource.mimeType.compare(WebCString("text/html"))); | |
| 229 EXPECT_FALSE(resource.data.isEmpty()); | |
| 230 | |
| 231 EXPECT_EQ(6U, resources.size()); // There should be no duplicates. | |
| 232 EXPECT_TRUE(resourceVectorContains(resources, m_baseURL + "red_background.pn
g", "image/png")); | |
| 233 EXPECT_TRUE(resourceVectorContains(resources, m_baseURL + "green_background.
png", "image/png")); | |
| 234 EXPECT_TRUE(resourceVectorContains(resources, m_baseURL + "blue_background.p
ng", "image/png")); | |
| 235 EXPECT_TRUE(resourceVectorContains(resources, m_baseURL + "iframe.html", "te
xt/html")); | |
| 236 EXPECT_TRUE(resourceVectorContains(resources, m_baseURL + "iframe2.html", "t
ext/html")); | |
| 237 } | |
| 238 | |
| 239 // Test that when serializing a page, all CSS resources are reported, including
url()'s | 208 // Test that when serializing a page, all CSS resources are reported, including
url()'s |
| 240 // and imports and links. Note that we don't test the resources contents, we onl
y make sure | 209 // and imports and links. Note that we don't test the resources contents, we onl
y make sure |
| 241 // they are all reported with the right mime type and that they contain some dat
a. | 210 // they are all reported with the right mime type and that they contain some dat
a. |
| 242 TEST_F(WebPageNewSerializeTest, FAILS_CSSResources) | 211 TEST_F(WebPageNewSerializeTest, FAILS_CSSResources) |
| 243 { | 212 { |
| 244 // Register the mocked frame and load it. | 213 // Register the mocked frame and load it. |
| 245 WebURL topFrameURL = setUpCSSTestPage(); | 214 WebURL topFrameURL = setUpCSSTestPage(); |
| 246 loadURLInTopFrame(topFrameURL); | 215 loadURLInTopFrame(topFrameURL); |
| 247 | 216 |
| 248 WebVector<WebPageSerializer::Resource> resources; | 217 WebVector<WebPageSerializer::Resource> resources; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 262 EXPECT_TRUE(resourceVectorContains(resources, m_baseURL + "red_background.pn
g", "image/png")); | 231 EXPECT_TRUE(resourceVectorContains(resources, m_baseURL + "red_background.pn
g", "image/png")); |
| 263 EXPECT_TRUE(resourceVectorContains(resources, m_baseURL + "orange_background
.png", "image/png")); | 232 EXPECT_TRUE(resourceVectorContains(resources, m_baseURL + "orange_background
.png", "image/png")); |
| 264 EXPECT_TRUE(resourceVectorContains(resources, m_baseURL + "yellow_background
.png", "image/png")); | 233 EXPECT_TRUE(resourceVectorContains(resources, m_baseURL + "yellow_background
.png", "image/png")); |
| 265 EXPECT_TRUE(resourceVectorContains(resources, m_baseURL + "green_background.
png", "image/png")); | 234 EXPECT_TRUE(resourceVectorContains(resources, m_baseURL + "green_background.
png", "image/png")); |
| 266 EXPECT_TRUE(resourceVectorContains(resources, m_baseURL + "blue_background.p
ng", "image/png")); | 235 EXPECT_TRUE(resourceVectorContains(resources, m_baseURL + "blue_background.p
ng", "image/png")); |
| 267 EXPECT_TRUE(resourceVectorContains(resources, m_baseURL + "purple_background
.png", "image/png")); | 236 EXPECT_TRUE(resourceVectorContains(resources, m_baseURL + "purple_background
.png", "image/png")); |
| 268 EXPECT_TRUE(resourceVectorContains(resources, m_baseURL + "ul-dot.png", "ima
ge/png")); | 237 EXPECT_TRUE(resourceVectorContains(resources, m_baseURL + "ul-dot.png", "ima
ge/png")); |
| 269 EXPECT_TRUE(resourceVectorContains(resources, m_baseURL + "ol-dot.png", "ima
ge/png")); | 238 EXPECT_TRUE(resourceVectorContains(resources, m_baseURL + "ol-dot.png", "ima
ge/png")); |
| 270 } | 239 } |
| 271 | 240 |
| 272 // Tests that when serializing a page with blank frames these are reported with
their resources. | |
| 273 TEST_F(WebPageNewSerializeTest, BlankFrames) | |
| 274 { | |
| 275 // Register the mocked frame and load it. | |
| 276 WebURL topFrameURL = toKURL(m_baseURL); | |
| 277 registerMockedURLLoad(topFrameURL, WebString::fromUTF8("blank_frames.html"),
WebString::fromUTF8("pageserializer/"), htmlMimeType()); | |
| 278 registerMockedURLLoad(toTestURL("red_background.png"), WebString::fromUTF8("
red_background.png"), WebString::fromUTF8("pageserializer/"), pngMimeType()); | |
| 279 registerMockedURLLoad(toTestURL("orange_background.png"), WebString::fromUTF
8("orange_background.png"), WebString::fromUTF8("pageserializer/"), pngMimeType(
)); | |
| 280 registerMockedURLLoad(toTestURL("blue_background.png"), WebString::fromUTF8(
"blue_background.png"), WebString::fromUTF8("pageserializer/"), pngMimeType()); | |
| 281 | |
| 282 loadURLInTopFrame(topFrameURL); | |
| 283 | |
| 284 WebVector<WebPageSerializer::Resource> resources; | |
| 285 WebPageSerializer::serialize(webView(), &resources); | |
| 286 ASSERT_FALSE(resources.isEmpty()); | |
| 287 | |
| 288 // The first resource should be the main-frame. | |
| 289 const WebPageSerializer::Resource& resource = resources[0]; | |
| 290 EXPECT_TRUE(resource.url == WebURL(toKURL(m_baseURL))); | |
| 291 EXPECT_EQ(0, resource.mimeType.compare(WebCString("text/html"))); | |
| 292 EXPECT_FALSE(resource.data.isEmpty()); | |
| 293 | |
| 294 EXPECT_EQ(7U, resources.size()); // There should be no duplicates. | |
| 295 EXPECT_TRUE(resourceVectorContains(resources, m_baseURL + "red_background.pn
g", "image/png")); | |
| 296 EXPECT_TRUE(resourceVectorContains(resources, m_baseURL + "orange_background
.png", "image/png")); | |
| 297 EXPECT_TRUE(resourceVectorContains(resources, m_baseURL + "blue_background.p
ng", "image/png")); | |
| 298 // The blank frames should have got a magic URL. | |
| 299 EXPECT_TRUE(resourceVectorContains(resources, "wyciwyg://frame/0", "text/htm
l")); | |
| 300 EXPECT_TRUE(resourceVectorContains(resources, "wyciwyg://frame/1", "text/htm
l")); | |
| 301 EXPECT_TRUE(resourceVectorContains(resources, "wyciwyg://frame/2", "text/htm
l")); | |
| 302 } | |
| 303 | |
| 304 TEST_F(WebPageNewSerializeTest, SerializeXMLHasRightDeclaration) | 241 TEST_F(WebPageNewSerializeTest, SerializeXMLHasRightDeclaration) |
| 305 { | 242 { |
| 306 WebURL topFrameURL = toTestURL("simple.xhtml"); | 243 WebURL topFrameURL = toTestURL("simple.xhtml"); |
| 307 registerMockedURLLoad(topFrameURL, WebString::fromUTF8("simple.xhtml"), WebS
tring::fromUTF8("pageserializer/"), xhtmlMimeType()); | 244 registerMockedURLLoad(topFrameURL, WebString::fromUTF8("simple.xhtml"), WebS
tring::fromUTF8("pageserializer/"), xhtmlMimeType()); |
| 308 | 245 |
| 309 loadURLInTopFrame(topFrameURL); | 246 loadURLInTopFrame(topFrameURL); |
| 310 | 247 |
| 311 WebVector<WebPageSerializer::Resource> resources; | 248 WebVector<WebPageSerializer::Resource> resources; |
| 312 WebPageSerializer::serialize(webView(), &resources); | 249 WebPageSerializer::serialize(webView(), &resources); |
| 313 ASSERT_FALSE(resources.isEmpty()); | 250 ASSERT_FALSE(resources.isEmpty()); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 356 if (!line.find("Content-Transfer-Encoding:")) { | 293 if (!line.find("Content-Transfer-Encoding:")) { |
| 357 ASSERT_TRUE(expectedEncoding); | 294 ASSERT_TRUE(expectedEncoding); |
| 358 EXPECT_TRUE(line.find(expectedEncoding) != std::string::npos); | 295 EXPECT_TRUE(line.find(expectedEncoding) != std::string::npos); |
| 359 expectedEncoding = 0; | 296 expectedEncoding = 0; |
| 360 sectionCheckedCount++; | 297 sectionCheckedCount++; |
| 361 } | 298 } |
| 362 } | 299 } |
| 363 EXPECT_EQ(12, sectionCheckedCount); | 300 EXPECT_EQ(12, sectionCheckedCount); |
| 364 } | 301 } |
| 365 | 302 |
| 366 TEST_F(WebPageNewSerializeTest, SubFrameSerialization) | |
| 367 { | |
| 368 WebURL pageUrl = toKURL(m_baseURL); | |
| 369 registerMockedURLLoad(pageUrl, WebString::fromUTF8("top_frame.html"), WebStr
ing::fromUTF8("pageserializer/"), htmlMimeType()); | |
| 370 registerMockedURLLoad(toTestURL("iframe.html"), WebString::fromUTF8("iframe.
html"), WebString::fromUTF8("pageserializer/"), htmlMimeType()); | |
| 371 registerMockedURLLoad(toTestURL("iframe2.html"), WebString::fromUTF8("iframe
2.html"), WebString::fromUTF8("pageserializer/"), htmlMimeType()); | |
| 372 registerMockedURLLoad(toTestURL("red_background.png"), WebString::fromUTF8("
red_background.png"), WebString::fromUTF8("pageserializer/"), pngMimeType()); | |
| 373 registerMockedURLLoad(toTestURL("green_background.png"), WebString::fromUTF8
("green_background.png"), WebString::fromUTF8("pageserializer/"), pngMimeType())
; | |
| 374 registerMockedURLLoad(toTestURL("blue_background.png"), WebString::fromUTF8(
"blue_background.png"), WebString::fromUTF8("pageserializer/"), pngMimeType()); | |
| 375 | |
| 376 loadURLInTopFrame(pageUrl); | |
| 377 | |
| 378 WebVector<WebURL> localLinks(static_cast<size_t>(2)); | |
| 379 WebVector<WebString> localPaths(static_cast<size_t>(2)); | |
| 380 localLinks[0] = pageUrl; | |
| 381 localPaths[0] = WebString("/"); | |
| 382 localLinks[1] = toTestURL("iframe.html"); | |
| 383 localPaths[1] = WebString("SavedFiles/iframe.html"); | |
| 384 | |
| 385 WebString serializedData; | |
| 386 FrameDataWebPageSerializerClient client(pageUrl, &serializedData); | |
| 387 | |
| 388 // We just want to make sure nothing crazy happens, namely that no | |
| 389 // assertions are hit. As a sanity check, we also make sure that some data | |
| 390 // was returned. | |
| 391 WebPageSerializer::serialize(webView()->mainFrame()->toWebLocalFrame(), true
, &client, localLinks, localPaths, WebString("")); | |
| 392 | |
| 393 // Subframe src | |
| 394 EXPECT_TRUE(static_cast<String>(serializedData).contains("src=\"SavedFiles/i
frame.html\"")); | |
| 395 } | 303 } |
| 396 | |
| 397 } | |
| OLD | NEW |