| 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 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 266 const char kDisabledAttr[] = "disabled=3D\"\""; | 266 const char kDisabledAttr[] = "disabled=3D\"\""; |
| 267 int matches = | 267 int matches = |
| 268 MatchSubstring(mhtml, kDisabledAttr, arraysize(kDisabledAttr) - 1); | 268 MatchSubstring(mhtml, kDisabledAttr, arraysize(kDisabledAttr) - 1); |
| 269 EXPECT_EQ(21, matches); | 269 EXPECT_EQ(21, matches); |
| 270 } | 270 } |
| 271 | 271 |
| 272 TEST_F(WebFrameSerializerSanitizationTest, RemoveHiddenElements) { | 272 TEST_F(WebFrameSerializerSanitizationTest, RemoveHiddenElements) { |
| 273 String mhtml = | 273 String mhtml = |
| 274 GenerateMHTMLParts("http://www.test.com", "hidden_elements.html"); | 274 GenerateMHTMLParts("http://www.test.com", "hidden_elements.html"); |
| 275 | 275 |
| 276 // These hidden elements that do not affect layout should be removed. | 276 // The element with hidden attribute should be removed. |
| 277 EXPECT_EQ(WTF::kNotFound, mhtml.Find("<h1")); | |
| 278 EXPECT_EQ(WTF::kNotFound, mhtml.Find("<p id=3D\"hidden_id\"")); | 277 EXPECT_EQ(WTF::kNotFound, mhtml.Find("<p id=3D\"hidden_id\"")); |
| 278 |
| 279 // The hidden form element should be removed. |
| 279 EXPECT_EQ(WTF::kNotFound, mhtml.Find("<input type=3D\"hidden\"")); | 280 EXPECT_EQ(WTF::kNotFound, mhtml.Find("<input type=3D\"hidden\"")); |
| 280 | 281 |
| 281 // These default-hidden elements should not be removed. | 282 // All other hidden elements should not be removed. |
| 282 EXPECT_NE(WTF::kNotFound, mhtml.Find("<html")); | 283 EXPECT_NE(WTF::kNotFound, mhtml.Find("<html")); |
| 283 EXPECT_NE(WTF::kNotFound, mhtml.Find("<head")); | 284 EXPECT_NE(WTF::kNotFound, mhtml.Find("<head")); |
| 284 EXPECT_NE(WTF::kNotFound, mhtml.Find("<style")); | 285 EXPECT_NE(WTF::kNotFound, mhtml.Find("<style")); |
| 285 EXPECT_NE(WTF::kNotFound, mhtml.Find("<title")); | 286 EXPECT_NE(WTF::kNotFound, mhtml.Find("<title")); |
| 287 EXPECT_NE(WTF::kNotFound, mhtml.Find("<h1")); |
| 288 EXPECT_NE(WTF::kNotFound, mhtml.Find("<h2")); |
| 286 EXPECT_NE(WTF::kNotFound, mhtml.Find("<datalist")); | 289 EXPECT_NE(WTF::kNotFound, mhtml.Find("<datalist")); |
| 287 EXPECT_NE(WTF::kNotFound, mhtml.Find("<option")); | 290 EXPECT_NE(WTF::kNotFound, mhtml.Find("<option")); |
| 288 // One for meta in head and another for meta in body. | 291 // One for meta in head and another for meta in body. |
| 289 EXPECT_EQ(2, MatchSubstring(mhtml, "<meta", 5)); | 292 EXPECT_EQ(2, MatchSubstring(mhtml, "<meta", 5)); |
| 290 // One for style in head and another for style in body. | 293 // One for style in head and another for style in body. |
| 291 EXPECT_EQ(2, MatchSubstring(mhtml, "<style", 6)); | 294 EXPECT_EQ(2, MatchSubstring(mhtml, "<style", 6)); |
| 292 // One for link in head and another for link in body. | 295 // One for link in head and another for link in body. |
| 293 EXPECT_EQ(2, MatchSubstring(mhtml, "<link", 5)); | 296 EXPECT_EQ(2, MatchSubstring(mhtml, "<link", 5)); |
| 294 | 297 |
| 295 // These hidden elements that affect layout should remain intact. | |
| 296 EXPECT_NE(WTF::kNotFound, mhtml.Find("<h2")); | |
| 297 | |
| 298 // These visible elements should remain intact. | 298 // These visible elements should remain intact. |
| 299 EXPECT_NE(WTF::kNotFound, mhtml.Find("<h2")); | |
| 300 EXPECT_NE(WTF::kNotFound, mhtml.Find("<p id=3D\"visible_id\"")); | 299 EXPECT_NE(WTF::kNotFound, mhtml.Find("<p id=3D\"visible_id\"")); |
| 301 EXPECT_NE(WTF::kNotFound, mhtml.Find("<form")); | 300 EXPECT_NE(WTF::kNotFound, mhtml.Find("<form")); |
| 302 EXPECT_NE(WTF::kNotFound, mhtml.Find("<input type=3D\"text\"")); | 301 EXPECT_NE(WTF::kNotFound, mhtml.Find("<input type=3D\"text\"")); |
| 303 EXPECT_NE(WTF::kNotFound, mhtml.Find("<div")); | 302 EXPECT_NE(WTF::kNotFound, mhtml.Find("<div")); |
| 304 } | 303 } |
| 305 | 304 |
| 306 // Regression test for crbug.com/678893, where in some cases serializing an | 305 // Regression test for crbug.com/678893, where in some cases serializing an |
| 307 // image document could cause code to pick an element from an empty container. | 306 // image document could cause code to pick an element from an empty container. |
| 308 TEST_F(WebFrameSerializerSanitizationTest, FromBrokenImageDocument) { | 307 TEST_F(WebFrameSerializerSanitizationTest, FromBrokenImageDocument) { |
| 309 String mhtml = GenerateMHTMLParts("http://www.test.com", "broken-image.png", | 308 String mhtml = GenerateMHTMLParts("http://www.test.com", "broken-image.png", |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 384 mhtml.Find("<meta http-equiv=3D\"Content-Security-Policy")); | 383 mhtml.Find("<meta http-equiv=3D\"Content-Security-Policy")); |
| 385 EXPECT_NE(WTF::kNotFound, mhtml.Find("<meta name=3D\"description")); | 384 EXPECT_NE(WTF::kNotFound, mhtml.Find("<meta name=3D\"description")); |
| 386 EXPECT_NE(WTF::kNotFound, mhtml.Find("<meta http-equiv=3D\"refresh")); | 385 EXPECT_NE(WTF::kNotFound, mhtml.Find("<meta http-equiv=3D\"refresh")); |
| 387 | 386 |
| 388 // If an element is removed, its children should also be skipped. | 387 // If an element is removed, its children should also be skipped. |
| 389 EXPECT_EQ(WTF::kNotFound, mhtml.Find("<select")); | 388 EXPECT_EQ(WTF::kNotFound, mhtml.Find("<select")); |
| 390 EXPECT_EQ(WTF::kNotFound, mhtml.Find("<option")); | 389 EXPECT_EQ(WTF::kNotFound, mhtml.Find("<option")); |
| 391 } | 390 } |
| 392 | 391 |
| 393 } // namespace blink | 392 } // namespace blink |
| OLD | NEW |