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 13 matching lines...) Expand all Loading... |
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 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. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 */ | 29 */ |
30 | 30 |
31 #include "public/web/WebFrameSerializer.h" | 31 #include "public/web/WebFrameSerializer.h" |
32 | 32 |
33 #include "core/exported/WebViewBase.h" | 33 #include "core/exported/WebViewBase.h" |
| 34 #include "platform/testing/HistogramTester.h" |
34 #include "platform/testing/URLTestHelpers.h" | 35 #include "platform/testing/URLTestHelpers.h" |
35 #include "platform/testing/UnitTestHelpers.h" | 36 #include "platform/testing/UnitTestHelpers.h" |
36 #include "platform/weborigin/KURL.h" | 37 #include "platform/weborigin/KURL.h" |
37 #include "platform/wtf/text/StringBuilder.h" | 38 #include "platform/wtf/text/StringBuilder.h" |
38 #include "public/platform/Platform.h" | 39 #include "public/platform/Platform.h" |
39 #include "public/platform/WebCString.h" | 40 #include "public/platform/WebCString.h" |
40 #include "public/platform/WebCache.h" | 41 #include "public/platform/WebCache.h" |
41 #include "public/platform/WebString.h" | 42 #include "public/platform/WebString.h" |
42 #include "public/platform/WebURL.h" | 43 #include "public/platform/WebURL.h" |
43 #include "public/platform/WebURLLoaderMockFactory.h" | 44 #include "public/platform/WebURLLoaderMockFactory.h" |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
227 FrameTestHelpers::LoadFrame(MainFrameImpl(), url.Utf8().data()); | 228 FrameTestHelpers::LoadFrame(MainFrameImpl(), url.Utf8().data()); |
228 WebThreadSafeData result = WebFrameSerializer::GenerateMHTMLParts( | 229 WebThreadSafeData result = WebFrameSerializer::GenerateMHTMLParts( |
229 WebString("boundary"), MainFrameImpl(), &mhtml_delegate_); | 230 WebString("boundary"), MainFrameImpl(), &mhtml_delegate_); |
230 return String(result.Data(), result.size()); | 231 return String(result.Data(), result.size()); |
231 } | 232 } |
232 | 233 |
233 void SetRemovePopupOverlay(bool remove_popup_overlay) { | 234 void SetRemovePopupOverlay(bool remove_popup_overlay) { |
234 mhtml_delegate_.SetRemovePopupOverlay(remove_popup_overlay); | 235 mhtml_delegate_.SetRemovePopupOverlay(remove_popup_overlay); |
235 } | 236 } |
236 | 237 |
| 238 protected: |
| 239 HistogramTester histogram_tester_; |
| 240 |
237 private: | 241 private: |
238 SimpleMHTMLPartsGenerationDelegate mhtml_delegate_; | 242 SimpleMHTMLPartsGenerationDelegate mhtml_delegate_; |
239 }; | 243 }; |
240 | 244 |
241 TEST_F(WebFrameSerializerSanitizationTest, RemoveInlineScriptInAttributes) { | 245 TEST_F(WebFrameSerializerSanitizationTest, RemoveInlineScriptInAttributes) { |
242 String mhtml = | 246 String mhtml = |
243 GenerateMHTMLParts("http://www.test.com", "script_in_attributes.html"); | 247 GenerateMHTMLParts("http://www.test.com", "script_in_attributes.html"); |
244 | 248 |
245 // These scripting attributes should be removed. | 249 // These scripting attributes should be removed. |
246 EXPECT_EQ(WTF::kNotFound, mhtml.Find("onload=")); | 250 EXPECT_EQ(WTF::kNotFound, mhtml.Find("onload=")); |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
352 EXPECT_NE(WTF::kNotFound, mhtml.Find("id=3D\"i1\">")); | 356 EXPECT_NE(WTF::kNotFound, mhtml.Find("id=3D\"i1\">")); |
353 EXPECT_NE(WTF::kNotFound, mhtml.Find("id=3D\"i2\" width=3D\"8\">")); | 357 EXPECT_NE(WTF::kNotFound, mhtml.Find("id=3D\"i2\" width=3D\"8\">")); |
354 } | 358 } |
355 | 359 |
356 TEST_F(WebFrameSerializerSanitizationTest, RemovePopupOverlayIfRequested) { | 360 TEST_F(WebFrameSerializerSanitizationTest, RemovePopupOverlayIfRequested) { |
357 WebView()->Resize(WebSize(500, 500)); | 361 WebView()->Resize(WebSize(500, 500)); |
358 SetRemovePopupOverlay(true); | 362 SetRemovePopupOverlay(true); |
359 String mhtml = GenerateMHTMLParts("http://www.test.com", "popup.html"); | 363 String mhtml = GenerateMHTMLParts("http://www.test.com", "popup.html"); |
360 EXPECT_EQ(WTF::kNotFound, mhtml.Find("class=3D\"overlay")); | 364 EXPECT_EQ(WTF::kNotFound, mhtml.Find("class=3D\"overlay")); |
361 EXPECT_EQ(WTF::kNotFound, mhtml.Find("class=3D\"modal")); | 365 EXPECT_EQ(WTF::kNotFound, mhtml.Find("class=3D\"modal")); |
| 366 histogram_tester_.ExpectUniqueSample( |
| 367 "PageSerialization.MhtmlGeneration.PopupOverlaySkipped", true, 1); |
| 368 } |
| 369 |
| 370 TEST_F(WebFrameSerializerSanitizationTest, PopupOverlayNotFound) { |
| 371 WebView()->Resize(WebSize(500, 500)); |
| 372 SetRemovePopupOverlay(true); |
| 373 String mhtml = |
| 374 GenerateMHTMLParts("http://www.test.com", "text_only_page.html"); |
| 375 histogram_tester_.ExpectUniqueSample( |
| 376 "PageSerialization.MhtmlGeneration.PopupOverlaySkipped", false, 1); |
362 } | 377 } |
363 | 378 |
364 TEST_F(WebFrameSerializerSanitizationTest, KeepPopupOverlayIfNotRequested) { | 379 TEST_F(WebFrameSerializerSanitizationTest, KeepPopupOverlayIfNotRequested) { |
365 WebView()->Resize(WebSize(500, 500)); | 380 WebView()->Resize(WebSize(500, 500)); |
366 SetRemovePopupOverlay(false); | 381 SetRemovePopupOverlay(false); |
367 String mhtml = GenerateMHTMLParts("http://www.test.com", "popup.html"); | 382 String mhtml = GenerateMHTMLParts("http://www.test.com", "popup.html"); |
368 EXPECT_NE(WTF::kNotFound, mhtml.Find("class=3D\"overlay")); | 383 EXPECT_NE(WTF::kNotFound, mhtml.Find("class=3D\"overlay")); |
369 EXPECT_NE(WTF::kNotFound, mhtml.Find("class=3D\"modal")); | 384 EXPECT_NE(WTF::kNotFound, mhtml.Find("class=3D\"modal")); |
| 385 histogram_tester_.ExpectTotalCount( |
| 386 "PageSerialization.MhtmlGeneration.PopupOverlaySkipped", 0); |
370 } | 387 } |
371 | 388 |
372 TEST_F(WebFrameSerializerSanitizationTest, RemoveElements) { | 389 TEST_F(WebFrameSerializerSanitizationTest, RemoveElements) { |
373 String mhtml = | 390 String mhtml = |
374 GenerateMHTMLParts("http://www.test.com", "remove_elements.html"); | 391 GenerateMHTMLParts("http://www.test.com", "remove_elements.html"); |
375 LOG(ERROR) << mhtml; | 392 LOG(ERROR) << mhtml; |
376 | 393 |
377 EXPECT_EQ(WTF::kNotFound, mhtml.Find("<script")); | 394 EXPECT_EQ(WTF::kNotFound, mhtml.Find("<script")); |
378 EXPECT_EQ(WTF::kNotFound, mhtml.Find("<noscript")); | 395 EXPECT_EQ(WTF::kNotFound, mhtml.Find("<noscript")); |
379 | 396 |
380 // Only the meta element containing "Content-Security-Policy" is removed. | 397 // Only the meta element containing "Content-Security-Policy" is removed. |
381 // Other meta elements should be preserved. | 398 // Other meta elements should be preserved. |
382 EXPECT_EQ(WTF::kNotFound, | 399 EXPECT_EQ(WTF::kNotFound, |
383 mhtml.Find("<meta http-equiv=3D\"Content-Security-Policy")); | 400 mhtml.Find("<meta http-equiv=3D\"Content-Security-Policy")); |
384 EXPECT_NE(WTF::kNotFound, mhtml.Find("<meta name=3D\"description")); | 401 EXPECT_NE(WTF::kNotFound, mhtml.Find("<meta name=3D\"description")); |
385 EXPECT_NE(WTF::kNotFound, mhtml.Find("<meta http-equiv=3D\"refresh")); | 402 EXPECT_NE(WTF::kNotFound, mhtml.Find("<meta http-equiv=3D\"refresh")); |
386 | 403 |
387 // If an element is removed, its children should also be skipped. | 404 // If an element is removed, its children should also be skipped. |
388 EXPECT_EQ(WTF::kNotFound, mhtml.Find("<select")); | 405 EXPECT_EQ(WTF::kNotFound, mhtml.Find("<select")); |
389 EXPECT_EQ(WTF::kNotFound, mhtml.Find("<option")); | 406 EXPECT_EQ(WTF::kNotFound, mhtml.Find("<option")); |
390 } | 407 } |
391 | 408 |
392 } // namespace blink | 409 } // namespace blink |
OLD | NEW |