| 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 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 253 | 253 |
| 254 // These non-scripting attributes should remain intact. | 254 // These non-scripting attributes should remain intact. |
| 255 EXPECT_NE(WTF::kNotFound, mhtml.Find("class=")); | 255 EXPECT_NE(WTF::kNotFound, mhtml.Find("class=")); |
| 256 EXPECT_NE(WTF::kNotFound, mhtml.Find("id=")); | 256 EXPECT_NE(WTF::kNotFound, mhtml.Find("id=")); |
| 257 | 257 |
| 258 // srcdoc attribute of frame element should be replaced with src attribute. | 258 // srcdoc attribute of frame element should be replaced with src attribute. |
| 259 EXPECT_EQ(WTF::kNotFound, mhtml.Find("srcdoc=")); | 259 EXPECT_EQ(WTF::kNotFound, mhtml.Find("srcdoc=")); |
| 260 EXPECT_NE(WTF::kNotFound, mhtml.Find("src=")); | 260 EXPECT_NE(WTF::kNotFound, mhtml.Find("src=")); |
| 261 } | 261 } |
| 262 | 262 |
| 263 TEST_F(WebFrameSerializerSanitizationTest, RemoveOtherAttributes) { |
| 264 String mhtml = |
| 265 GenerateMHTMLParts("http://www.test.com", "remove_attributes.html"); |
| 266 EXPECT_EQ(WTF::kNotFound, mhtml.Find("ping=")); |
| 267 } |
| 268 |
| 263 TEST_F(WebFrameSerializerSanitizationTest, DisableFormElements) { | 269 TEST_F(WebFrameSerializerSanitizationTest, DisableFormElements) { |
| 264 String mhtml = GenerateMHTMLParts("http://www.test.com", "form.html"); | 270 String mhtml = GenerateMHTMLParts("http://www.test.com", "form.html"); |
| 265 | 271 |
| 266 const char kDisabledAttr[] = "disabled=3D\"\""; | 272 const char kDisabledAttr[] = "disabled=3D\"\""; |
| 267 int matches = | 273 int matches = |
| 268 MatchSubstring(mhtml, kDisabledAttr, arraysize(kDisabledAttr) - 1); | 274 MatchSubstring(mhtml, kDisabledAttr, arraysize(kDisabledAttr) - 1); |
| 269 EXPECT_EQ(21, matches); | 275 EXPECT_EQ(21, matches); |
| 270 } | 276 } |
| 271 | 277 |
| 272 TEST_F(WebFrameSerializerSanitizationTest, RemoveHiddenElements) { | 278 TEST_F(WebFrameSerializerSanitizationTest, RemoveHiddenElements) { |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 365 WebView()->Resize(WebSize(500, 500)); | 371 WebView()->Resize(WebSize(500, 500)); |
| 366 SetRemovePopupOverlay(false); | 372 SetRemovePopupOverlay(false); |
| 367 String mhtml = GenerateMHTMLParts("http://www.test.com", "popup.html"); | 373 String mhtml = GenerateMHTMLParts("http://www.test.com", "popup.html"); |
| 368 EXPECT_NE(WTF::kNotFound, mhtml.Find("class=3D\"overlay")); | 374 EXPECT_NE(WTF::kNotFound, mhtml.Find("class=3D\"overlay")); |
| 369 EXPECT_NE(WTF::kNotFound, mhtml.Find("class=3D\"modal")); | 375 EXPECT_NE(WTF::kNotFound, mhtml.Find("class=3D\"modal")); |
| 370 } | 376 } |
| 371 | 377 |
| 372 TEST_F(WebFrameSerializerSanitizationTest, RemoveElements) { | 378 TEST_F(WebFrameSerializerSanitizationTest, RemoveElements) { |
| 373 String mhtml = | 379 String mhtml = |
| 374 GenerateMHTMLParts("http://www.test.com", "remove_elements.html"); | 380 GenerateMHTMLParts("http://www.test.com", "remove_elements.html"); |
| 375 LOG(ERROR) << mhtml; | |
| 376 | 381 |
| 377 EXPECT_EQ(WTF::kNotFound, mhtml.Find("<script")); | 382 EXPECT_EQ(WTF::kNotFound, mhtml.Find("<script")); |
| 378 EXPECT_EQ(WTF::kNotFound, mhtml.Find("<noscript")); | 383 EXPECT_EQ(WTF::kNotFound, mhtml.Find("<noscript")); |
| 379 | 384 |
| 380 // Only the meta element containing "Content-Security-Policy" is removed. | 385 // Only the meta element containing "Content-Security-Policy" is removed. |
| 381 // Other meta elements should be preserved. | 386 // Other meta elements should be preserved. |
| 382 EXPECT_EQ(WTF::kNotFound, | 387 EXPECT_EQ(WTF::kNotFound, |
| 383 mhtml.Find("<meta http-equiv=3D\"Content-Security-Policy")); | 388 mhtml.Find("<meta http-equiv=3D\"Content-Security-Policy")); |
| 384 EXPECT_NE(WTF::kNotFound, mhtml.Find("<meta name=3D\"description")); | 389 EXPECT_NE(WTF::kNotFound, mhtml.Find("<meta name=3D\"description")); |
| 385 EXPECT_NE(WTF::kNotFound, mhtml.Find("<meta http-equiv=3D\"refresh")); | 390 EXPECT_NE(WTF::kNotFound, mhtml.Find("<meta http-equiv=3D\"refresh")); |
| 386 | 391 |
| 387 // If an element is removed, its children should also be skipped. | 392 // If an element is removed, its children should also be skipped. |
| 388 EXPECT_EQ(WTF::kNotFound, mhtml.Find("<select")); | 393 EXPECT_EQ(WTF::kNotFound, mhtml.Find("<select")); |
| 389 EXPECT_EQ(WTF::kNotFound, mhtml.Find("<option")); | 394 EXPECT_EQ(WTF::kNotFound, mhtml.Find("<option")); |
| 390 } | 395 } |
| 391 | 396 |
| 392 } // namespace blink | 397 } // namespace blink |
| OLD | NEW |