Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "core/html/parser/HTMLDocumentParser.h" | |
| 6 | |
| 7 #include "core/dom/Document.h" | |
| 8 #include "platform/testing/UnitTestHelpers.h" | |
| 9 #include "testing/gtest/include/gtest/gtest.h" | |
| 10 #include "web/tests/sim/SimRequest.h" | |
| 11 #include "web/tests/sim/SimTest.h" | |
| 12 | |
| 13 namespace blink { | |
| 14 | |
| 15 using namespace HTMLNames; | |
| 16 | |
| 17 class HTMLDocumentParserLoadingTest : public SimTest {}; | |
|
kouhei (in TOK)
2017/01/19 04:19:41
SimTest runs w/ bg parser disabled.
I think we nee
Pat Meenan
2017/01/19 13:49:32
Done.
| |
| 18 | |
| 19 TEST_F(HTMLDocumentParserLoadingTest, | |
| 20 ShouldNotPauseParsingForExternalStylesheetsInHead) { | |
| 21 SimRequest mainResource("https://example.com/test.html", "text/html"); | |
| 22 SimRequest cssHeadResource("https://example.com/testHead.css", "text/css"); | |
| 23 | |
| 24 loadURL("https://example.com/test.html"); | |
| 25 | |
| 26 mainResource.complete( | |
| 27 "<!DOCTYPE html>" | |
| 28 "<html><head>" | |
| 29 "<link rel=stylesheet href=testHead.css>" | |
| 30 "</head><body>" | |
| 31 "<div id=\"bodyDiv\"></div>" | |
| 32 "</body></html>"); | |
| 33 | |
| 34 EXPECT_TRUE(document().getElementById("bodyDiv")); | |
| 35 cssHeadResource.complete(""); | |
| 36 EXPECT_TRUE(document().getElementById("bodyDiv")); | |
| 37 } | |
| 38 | |
| 39 TEST_F(HTMLDocumentParserLoadingTest, | |
| 40 ShouldNotPauseParsingForExternalStylesheetsImportedInHead) { | |
| 41 SimRequest mainResource("https://example.com/test.html", "text/html"); | |
| 42 SimRequest cssHeadResource("https://example.com/testHead.css", "text/css"); | |
| 43 | |
| 44 loadURL("https://example.com/test.html"); | |
| 45 | |
| 46 mainResource.complete( | |
| 47 "<!DOCTYPE html>" | |
| 48 "<html><head>" | |
| 49 "<style>" | |
| 50 "@import 'testHead.css'" | |
| 51 "</style>" | |
| 52 "</head><body>" | |
| 53 "<div id=\"bodyDiv\"></div>" | |
| 54 "</body></html>"); | |
| 55 | |
| 56 EXPECT_TRUE(document().getElementById("bodyDiv")); | |
| 57 cssHeadResource.complete(""); | |
| 58 EXPECT_TRUE(document().getElementById("bodyDiv")); | |
| 59 } | |
| 60 | |
| 61 TEST_F(HTMLDocumentParserLoadingTest, | |
| 62 ShouldPauseParsingForExternalStylesheetsInBody) { | |
| 63 SimRequest mainResource("https://example.com/test.html", "text/html"); | |
| 64 SimRequest cssHeadResource("https://example.com/testHead.css", "text/css"); | |
| 65 SimRequest cssBodyResource("https://example.com/testBody.css", "text/css"); | |
| 66 | |
| 67 loadURL("https://example.com/test.html"); | |
| 68 | |
| 69 mainResource.complete( | |
| 70 "<!DOCTYPE html>" | |
| 71 "<html><head>" | |
| 72 "<link rel=stylesheet href=testHead.css>" | |
| 73 "</head><body>" | |
| 74 "<div id=\"before\"></div>" | |
| 75 "<link rel=stylesheet href=testBody.css>" | |
| 76 "<div id=\"after\"></div>" | |
| 77 "</body></html>"); | |
| 78 | |
| 79 testing::runPendingTasks(); | |
| 80 EXPECT_TRUE(document().getElementById("before")); | |
| 81 EXPECT_FALSE(document().getElementById("after")); | |
| 82 | |
| 83 // Completing the head css shouldn't change anything | |
| 84 cssHeadResource.complete(""); | |
| 85 testing::runPendingTasks(); | |
| 86 EXPECT_TRUE(document().getElementById("before")); | |
| 87 EXPECT_FALSE(document().getElementById("after")); | |
| 88 | |
| 89 // Completing the body resource and pumping the tasks should continue parsing | |
| 90 // and create the "after" div. | |
| 91 cssBodyResource.complete(""); | |
| 92 testing::runPendingTasks(); | |
| 93 EXPECT_TRUE(document().getElementById("before")); | |
| 94 EXPECT_TRUE(document().getElementById("after")); | |
| 95 } | |
| 96 | |
| 97 TEST_F(HTMLDocumentParserLoadingTest, | |
| 98 ShouldPauseParsingForExternalStylesheetsInBodyIncremental) { | |
| 99 SimRequest mainResource("https://example.com/test.html", "text/html"); | |
| 100 SimRequest cssHeadResource("https://example.com/testHead.css", "text/css"); | |
| 101 SimRequest cssBodyResource1("https://example.com/testBody1.css", "text/css"); | |
| 102 SimRequest cssBodyResource2("https://example.com/testBody2.css", "text/css"); | |
| 103 SimRequest cssBodyResource3("https://example.com/testBody3.css", "text/css"); | |
| 104 | |
| 105 loadURL("https://example.com/test.html"); | |
| 106 | |
| 107 mainResource.start(); | |
| 108 mainResource.write( | |
| 109 "<!DOCTYPE html>" | |
| 110 "<html><head>" | |
| 111 "<link rel=stylesheet href=testHead.css>" | |
| 112 "</head><body>" | |
| 113 "<div id=\"before\"></div>" | |
| 114 "<link rel=stylesheet href=testBody1.css>" | |
| 115 "<div id=\"after1\"></div>"); | |
| 116 | |
| 117 testing::runPendingTasks(); | |
| 118 EXPECT_TRUE(document().getElementById("before")); | |
| 119 EXPECT_FALSE(document().getElementById("after1")); | |
| 120 EXPECT_FALSE(document().getElementById("after2")); | |
| 121 EXPECT_FALSE(document().getElementById("after3")); | |
| 122 | |
| 123 mainResource.write( | |
| 124 "<link rel=stylesheet href=testBody2.css>" | |
| 125 "<div id=\"after2\"></div>"); | |
| 126 | |
| 127 testing::runPendingTasks(); | |
| 128 EXPECT_TRUE(document().getElementById("before")); | |
| 129 EXPECT_FALSE(document().getElementById("after1")); | |
| 130 EXPECT_FALSE(document().getElementById("after2")); | |
| 131 EXPECT_FALSE(document().getElementById("after3")); | |
| 132 | |
| 133 mainResource.complete( | |
| 134 "<link rel=stylesheet href=testBody3.css>" | |
| 135 "<div id=\"after3\"></div>" | |
| 136 "</body></html>"); | |
| 137 | |
| 138 testing::runPendingTasks(); | |
| 139 EXPECT_TRUE(document().getElementById("before")); | |
| 140 EXPECT_FALSE(document().getElementById("after1")); | |
| 141 EXPECT_FALSE(document().getElementById("after2")); | |
| 142 EXPECT_FALSE(document().getElementById("after3")); | |
| 143 | |
| 144 // Completing the head css shouldn't change anything | |
| 145 cssHeadResource.complete(""); | |
| 146 testing::runPendingTasks(); | |
| 147 EXPECT_TRUE(document().getElementById("before")); | |
| 148 EXPECT_FALSE(document().getElementById("after1")); | |
| 149 EXPECT_FALSE(document().getElementById("after2")); | |
| 150 EXPECT_FALSE(document().getElementById("after3")); | |
| 151 | |
| 152 // Completing the second css shouldn't change anything | |
| 153 cssBodyResource2.complete(""); | |
| 154 testing::runPendingTasks(); | |
| 155 EXPECT_TRUE(document().getElementById("before")); | |
| 156 EXPECT_FALSE(document().getElementById("after1")); | |
| 157 EXPECT_FALSE(document().getElementById("after2")); | |
| 158 EXPECT_FALSE(document().getElementById("after3")); | |
| 159 | |
| 160 // Completing the first css should allow the parser to continue past it and | |
| 161 // the second css which was already completed and then pause again before the | |
| 162 // third css. | |
| 163 cssBodyResource1.complete(""); | |
| 164 testing::runPendingTasks(); | |
| 165 EXPECT_TRUE(document().getElementById("before")); | |
| 166 EXPECT_TRUE(document().getElementById("after1")); | |
| 167 EXPECT_TRUE(document().getElementById("after2")); | |
| 168 EXPECT_FALSE(document().getElementById("after3")); | |
| 169 | |
| 170 // Completing the third css should let it continue to the end. | |
| 171 cssBodyResource3.complete(""); | |
| 172 testing::runPendingTasks(); | |
| 173 EXPECT_TRUE(document().getElementById("before")); | |
| 174 EXPECT_TRUE(document().getElementById("after1")); | |
| 175 EXPECT_TRUE(document().getElementById("after2")); | |
| 176 EXPECT_TRUE(document().getElementById("after3")); | |
| 177 } | |
| 178 | |
| 179 TEST_F(HTMLDocumentParserLoadingTest, | |
| 180 ShouldNotPauseParsingForExternalNonMatchingStylesheetsInBody) { | |
| 181 SimRequest mainResource("https://example.com/test.html", "text/html"); | |
| 182 SimRequest cssHeadResource("https://example.com/testHead.css", "text/css"); | |
| 183 | |
| 184 loadURL("https://example.com/test.html"); | |
| 185 | |
| 186 mainResource.complete( | |
| 187 "<!DOCTYPE html>" | |
| 188 "<html><head>" | |
| 189 "<link rel=stylesheet href=testHead.css>" | |
| 190 "</head><body>" | |
| 191 "<div id=\"before\"></div>" | |
| 192 "<link rel=stylesheet href=testBody.css type='print'>" | |
| 193 "<div id=\"after\"></div>" | |
| 194 "</body></html>"); | |
| 195 | |
| 196 testing::runPendingTasks(); | |
| 197 EXPECT_TRUE(document().getElementById("before")); | |
| 198 EXPECT_TRUE(document().getElementById("after")); | |
| 199 | |
| 200 // Completing the head css shouldn't change anything | |
| 201 cssHeadResource.complete(""); | |
| 202 } | |
| 203 | |
| 204 TEST_F(HTMLDocumentParserLoadingTest, | |
| 205 ShouldPauseParsingForExternalStylesheetsImportedInBody) { | |
| 206 SimRequest mainResource("https://example.com/test.html", "text/html"); | |
| 207 SimRequest cssHeadResource("https://example.com/testHead.css", "text/css"); | |
| 208 SimRequest cssBodyResource("https://example.com/testBody.css", "text/css"); | |
| 209 | |
| 210 loadURL("https://example.com/test.html"); | |
| 211 | |
| 212 mainResource.complete( | |
| 213 "<!DOCTYPE html>" | |
| 214 "<html><head>" | |
| 215 "<link rel=stylesheet href=testHead.css>" | |
| 216 "</head><body>" | |
| 217 "<div id=\"before\"></div>" | |
| 218 "<style>" | |
| 219 "@import 'testBody.css'" | |
| 220 "</style>" | |
| 221 "<div id=\"after\"></div>" | |
| 222 "</body></html>"); | |
| 223 | |
| 224 testing::runPendingTasks(); | |
| 225 EXPECT_TRUE(document().getElementById("before")); | |
| 226 EXPECT_FALSE(document().getElementById("after")); | |
| 227 | |
| 228 // Completing the head css shouldn't change anything | |
| 229 cssHeadResource.complete(""); | |
| 230 testing::runPendingTasks(); | |
| 231 EXPECT_TRUE(document().getElementById("before")); | |
| 232 EXPECT_FALSE(document().getElementById("after")); | |
| 233 | |
| 234 // Completing the body resource and pumping the tasks should continue parsing | |
| 235 // and create the "after" div. | |
| 236 cssBodyResource.complete(""); | |
| 237 testing::runPendingTasks(); | |
| 238 EXPECT_TRUE(document().getElementById("before")); | |
| 239 EXPECT_TRUE(document().getElementById("after")); | |
| 240 } | |
| 241 | |
| 242 TEST_F(HTMLDocumentParserLoadingTest, | |
| 243 ShouldPauseParsingForExternalStylesheetsWrittenInBody) { | |
| 244 SimRequest mainResource("https://example.com/test.html", "text/html"); | |
| 245 SimRequest cssHeadResource("https://example.com/testHead.css", "text/css"); | |
| 246 SimRequest cssBodyResource("https://example.com/testBody.css", "text/css"); | |
| 247 | |
| 248 loadURL("https://example.com/test.html"); | |
| 249 | |
| 250 mainResource.complete( | |
| 251 "<!DOCTYPE html>" | |
| 252 "<html><head>" | |
| 253 "<link rel=stylesheet href=testHead.css>" | |
| 254 "</head><body>" | |
| 255 "<div id=\"before\"></div>" | |
| 256 "<script>" | |
| 257 "document.write('<link rel=stylesheet href=testBody.css>');" | |
| 258 "</script>" | |
| 259 "<div id=\"after\"></div>" | |
| 260 "</body></html>"); | |
| 261 | |
| 262 testing::runPendingTasks(); | |
| 263 EXPECT_TRUE(document().getElementById("before")); | |
| 264 EXPECT_FALSE(document().getElementById("after")); | |
| 265 | |
| 266 // Completing the head css shouldn't change anything | |
| 267 cssHeadResource.complete(""); | |
| 268 testing::runPendingTasks(); | |
| 269 EXPECT_TRUE(document().getElementById("before")); | |
| 270 EXPECT_FALSE(document().getElementById("after")); | |
| 271 | |
| 272 // Completing the body resource and pumping the tasks should continue parsing | |
| 273 // and create the "after" div. | |
| 274 cssBodyResource.complete(""); | |
| 275 testing::runPendingTasks(); | |
| 276 EXPECT_TRUE(document().getElementById("before")); | |
| 277 EXPECT_TRUE(document().getElementById("after")); | |
| 278 } | |
| 279 | |
| 280 TEST_F(HTMLDocumentParserLoadingTest, | |
| 281 PendingHeadStylesheetShouldNotBlockParserForBodyInlineStyle) { | |
| 282 SimRequest mainResource("https://example.com/test.html", "text/html"); | |
| 283 SimRequest cssHeadResource("https://example.com/testHead.css", "text/css"); | |
| 284 | |
| 285 loadURL("https://example.com/test.html"); | |
| 286 | |
| 287 mainResource.complete( | |
| 288 "<!DOCTYPE html>" | |
| 289 "<html><head>" | |
| 290 "<link rel=stylesheet href=testHead.css>" | |
| 291 "</head><body>" | |
| 292 "<div id=\"before\"></div>" | |
| 293 "<style>" | |
| 294 "</style>" | |
| 295 "<div id=\"after\"></div>" | |
| 296 "</body></html>"); | |
| 297 | |
| 298 testing::runPendingTasks(); | |
| 299 EXPECT_TRUE(document().getElementById("before")); | |
| 300 EXPECT_TRUE(document().getElementById("after")); | |
| 301 cssHeadResource.complete(""); | |
| 302 } | |
| 303 | |
| 304 TEST_F(HTMLDocumentParserLoadingTest, | |
| 305 PendingHeadStylesheetShouldNotBlockParserForBodyShadowDom) { | |
| 306 SimRequest mainResource("https://example.com/test.html", "text/html"); | |
| 307 SimRequest cssHeadResource("https://example.com/testHead.css", "text/css"); | |
| 308 | |
| 309 loadURL("https://example.com/test.html"); | |
| 310 | |
| 311 // The marquee tag has a shadow DOM that synchronously applies a stylesheet. | |
| 312 mainResource.complete( | |
| 313 "<!DOCTYPE html>" | |
| 314 "<html><head>" | |
| 315 "<link rel=stylesheet href=testHead.css>" | |
| 316 "</head><body>" | |
| 317 "<div id=\"before\"></div>" | |
| 318 "<marquee>Marquee</marquee>" | |
| 319 "<div id=\"after\"></div>" | |
| 320 "</body></html>"); | |
| 321 | |
| 322 testing::runPendingTasks(); | |
| 323 EXPECT_TRUE(document().getElementById("before")); | |
| 324 EXPECT_TRUE(document().getElementById("after")); | |
| 325 cssHeadResource.complete(""); | |
| 326 } | |
| 327 | |
| 328 TEST_F(HTMLDocumentParserLoadingTest, | |
| 329 ShouldNotPauseParsingForExternalStylesheetsAttachedInBody) { | |
| 330 SimRequest mainResource("https://example.com/test.html", "text/html"); | |
| 331 SimRequest cssAsyncResource("https://example.com/testAsync.css", "text/css"); | |
| 332 | |
| 333 loadURL("https://example.com/test.html"); | |
| 334 | |
| 335 mainResource.complete( | |
| 336 "<!DOCTYPE html>" | |
| 337 "<html><head>" | |
| 338 "</head><body>" | |
| 339 "<div id=\"before\"></div>" | |
| 340 "<script>" | |
| 341 "var attach = document.getElementsByTagName('script')[0];" | |
| 342 "var link = document.createElement('link');" | |
| 343 "link.rel = 'stylesheet';" | |
| 344 "link.type = 'text/css';" | |
| 345 "link.href = 'testAsync.css';" | |
| 346 "link.media = 'all';" | |
| 347 "attach.appendChild(link);" | |
| 348 "</script>" | |
| 349 "<div id=\"after\"></div>" | |
| 350 "</body></html>"); | |
| 351 | |
| 352 testing::runPendingTasks(); | |
| 353 EXPECT_TRUE(document().getElementById("before")); | |
| 354 EXPECT_TRUE(document().getElementById("after")); | |
| 355 | |
| 356 cssAsyncResource.complete(""); | |
| 357 } | |
| 358 | |
| 359 } // namespace blink | |
| OLD | NEW |