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 {}; | |
| 18 | |
| 19 TEST_F(HTMLDocumentParserLoadingTest, | |
| 20 ShouldNotPauseParsingForExternalStylesheetsInHead) { | |
| 21 Document::setThreadedParsingEnabledForTesting(false); | |
| 22 SimRequest mainResource("https://example.com/test.html", "text/html"); | |
| 23 SimRequest cssHeadResource("https://example.com/testHead.css", "text/css"); | |
| 24 | |
| 25 loadURL("https://example.com/test.html"); | |
| 26 | |
| 27 mainResource.complete( | |
| 28 "<!DOCTYPE html>" | |
| 29 "<html><head>" | |
| 30 "<link rel=stylesheet href=testHead.css>" | |
| 31 "</head><body>" | |
| 32 "<div id=\"bodyDiv\"></div>" | |
| 33 "</body></html>"); | |
| 34 | |
| 35 testing::runPendingTasks(); | |
| 36 EXPECT_TRUE(document().getElementById("bodyDiv")); | |
| 37 cssHeadResource.complete(""); | |
| 38 testing::runPendingTasks(); | |
| 39 EXPECT_TRUE(document().getElementById("bodyDiv")); | |
| 40 } | |
| 41 | |
| 42 TEST_F(HTMLDocumentParserLoadingTest, | |
| 43 ShouldNotPauseParsingForExternalStylesheetsInHeadThreaded) { | |
| 44 Document::setThreadedParsingEnabledForTesting(true); | |
|
kouhei (in TOK)
2017/01/20 10:56:47
Please dedupe test cases.
testing::TestWithParam m
Pat Meenan
2017/01/20 13:21:10
Done.
| |
| 45 SimRequest mainResource("https://example.com/test.html", "text/html"); | |
| 46 SimRequest cssHeadResource("https://example.com/testHead.css", "text/css"); | |
| 47 | |
| 48 loadURL("https://example.com/test.html"); | |
| 49 | |
| 50 mainResource.complete( | |
| 51 "<!DOCTYPE html>" | |
| 52 "<html><head>" | |
| 53 "<link rel=stylesheet href=testHead.css>" | |
| 54 "</head><body>" | |
| 55 "<div id=\"bodyDiv\"></div>" | |
| 56 "</body></html>"); | |
| 57 | |
| 58 testing::runPendingTasks(); | |
| 59 EXPECT_TRUE(document().getElementById("bodyDiv")); | |
| 60 cssHeadResource.complete(""); | |
| 61 testing::runPendingTasks(); | |
| 62 EXPECT_TRUE(document().getElementById("bodyDiv")); | |
| 63 } | |
| 64 | |
| 65 TEST_F(HTMLDocumentParserLoadingTest, | |
| 66 ShouldNotPauseParsingForExternalStylesheetsImportedInHead) { | |
| 67 Document::setThreadedParsingEnabledForTesting(false); | |
| 68 SimRequest mainResource("https://example.com/test.html", "text/html"); | |
| 69 SimRequest cssHeadResource("https://example.com/testHead.css", "text/css"); | |
| 70 | |
| 71 loadURL("https://example.com/test.html"); | |
| 72 | |
| 73 mainResource.complete( | |
| 74 "<!DOCTYPE html>" | |
| 75 "<html><head>" | |
| 76 "<style>" | |
| 77 "@import 'testHead.css'" | |
| 78 "</style>" | |
| 79 "</head><body>" | |
| 80 "<div id=\"bodyDiv\"></div>" | |
| 81 "</body></html>"); | |
| 82 | |
| 83 testing::runPendingTasks(); | |
| 84 EXPECT_TRUE(document().getElementById("bodyDiv")); | |
| 85 cssHeadResource.complete(""); | |
| 86 testing::runPendingTasks(); | |
| 87 EXPECT_TRUE(document().getElementById("bodyDiv")); | |
| 88 } | |
| 89 | |
| 90 TEST_F(HTMLDocumentParserLoadingTest, | |
| 91 ShouldNotPauseParsingForExternalStylesheetsImportedInHeadThreaded) { | |
| 92 Document::setThreadedParsingEnabledForTesting(true); | |
| 93 SimRequest mainResource("https://example.com/test.html", "text/html"); | |
| 94 SimRequest cssHeadResource("https://example.com/testHead.css", "text/css"); | |
| 95 | |
| 96 loadURL("https://example.com/test.html"); | |
| 97 | |
| 98 mainResource.complete( | |
| 99 "<!DOCTYPE html>" | |
| 100 "<html><head>" | |
| 101 "<style>" | |
| 102 "@import 'testHead.css'" | |
| 103 "</style>" | |
| 104 "</head><body>" | |
| 105 "<div id=\"bodyDiv\"></div>" | |
| 106 "</body></html>"); | |
| 107 | |
| 108 testing::runPendingTasks(); | |
| 109 EXPECT_TRUE(document().getElementById("bodyDiv")); | |
| 110 cssHeadResource.complete(""); | |
| 111 testing::runPendingTasks(); | |
| 112 EXPECT_TRUE(document().getElementById("bodyDiv")); | |
| 113 } | |
| 114 | |
| 115 TEST_F(HTMLDocumentParserLoadingTest, | |
| 116 ShouldPauseParsingForExternalStylesheetsInBody) { | |
| 117 Document::setThreadedParsingEnabledForTesting(false); | |
| 118 SimRequest mainResource("https://example.com/test.html", "text/html"); | |
| 119 SimRequest cssHeadResource("https://example.com/testHead.css", "text/css"); | |
| 120 SimRequest cssBodyResource("https://example.com/testBody.css", "text/css"); | |
| 121 | |
| 122 loadURL("https://example.com/test.html"); | |
| 123 | |
| 124 mainResource.complete( | |
| 125 "<!DOCTYPE html>" | |
| 126 "<html><head>" | |
| 127 "<link rel=stylesheet href=testHead.css>" | |
| 128 "</head><body>" | |
| 129 "<div id=\"before\"></div>" | |
| 130 "<link rel=stylesheet href=testBody.css>" | |
| 131 "<div id=\"after\"></div>" | |
| 132 "</body></html>"); | |
| 133 | |
| 134 testing::runPendingTasks(); | |
| 135 EXPECT_TRUE(document().getElementById("before")); | |
| 136 EXPECT_FALSE(document().getElementById("after")); | |
| 137 | |
| 138 // Completing the head css shouldn't change anything | |
| 139 cssHeadResource.complete(""); | |
| 140 testing::runPendingTasks(); | |
| 141 EXPECT_TRUE(document().getElementById("before")); | |
| 142 EXPECT_FALSE(document().getElementById("after")); | |
| 143 | |
| 144 // Completing the body resource and pumping the tasks should continue parsing | |
| 145 // and create the "after" div. | |
| 146 cssBodyResource.complete(""); | |
| 147 testing::runPendingTasks(); | |
| 148 EXPECT_TRUE(document().getElementById("before")); | |
| 149 EXPECT_TRUE(document().getElementById("after")); | |
| 150 } | |
| 151 | |
| 152 TEST_F(HTMLDocumentParserLoadingTest, | |
| 153 ShouldPauseParsingForExternalStylesheetsInBodyThreaded) { | |
| 154 Document::setThreadedParsingEnabledForTesting(true); | |
| 155 SimRequest mainResource("https://example.com/test.html", "text/html"); | |
| 156 SimRequest cssHeadResource("https://example.com/testHead.css", "text/css"); | |
| 157 SimRequest cssBodyResource("https://example.com/testBody.css", "text/css"); | |
| 158 | |
| 159 loadURL("https://example.com/test.html"); | |
| 160 | |
| 161 mainResource.complete( | |
| 162 "<!DOCTYPE html>" | |
| 163 "<html><head>" | |
| 164 "<link rel=stylesheet href=testHead.css>" | |
| 165 "</head><body>" | |
| 166 "<div id=\"before\"></div>" | |
| 167 "<link rel=stylesheet href=testBody.css>" | |
| 168 "<div id=\"after\"></div>" | |
| 169 "</body></html>"); | |
| 170 | |
| 171 testing::runPendingTasks(); | |
| 172 EXPECT_TRUE(document().getElementById("before")); | |
| 173 EXPECT_FALSE(document().getElementById("after")); | |
| 174 | |
| 175 // Completing the head css shouldn't change anything | |
| 176 cssHeadResource.complete(""); | |
| 177 testing::runPendingTasks(); | |
| 178 EXPECT_TRUE(document().getElementById("before")); | |
| 179 EXPECT_FALSE(document().getElementById("after")); | |
| 180 | |
| 181 // Completing the body resource and pumping the tasks should continue parsing | |
| 182 // and create the "after" div. | |
| 183 cssBodyResource.complete(""); | |
| 184 testing::runPendingTasks(); | |
| 185 EXPECT_TRUE(document().getElementById("before")); | |
| 186 EXPECT_TRUE(document().getElementById("after")); | |
| 187 } | |
| 188 | |
| 189 TEST_F(HTMLDocumentParserLoadingTest, | |
| 190 ShouldPauseParsingForExternalStylesheetsInBodyIncremental) { | |
| 191 Document::setThreadedParsingEnabledForTesting(false); | |
| 192 SimRequest mainResource("https://example.com/test.html", "text/html"); | |
| 193 SimRequest cssHeadResource("https://example.com/testHead.css", "text/css"); | |
| 194 SimRequest cssBodyResource1("https://example.com/testBody1.css", "text/css"); | |
| 195 SimRequest cssBodyResource2("https://example.com/testBody2.css", "text/css"); | |
| 196 SimRequest cssBodyResource3("https://example.com/testBody3.css", "text/css"); | |
| 197 | |
| 198 loadURL("https://example.com/test.html"); | |
| 199 | |
| 200 mainResource.start(); | |
| 201 mainResource.write( | |
| 202 "<!DOCTYPE html>" | |
| 203 "<html><head>" | |
| 204 "<link rel=stylesheet href=testHead.css>" | |
| 205 "</head><body>" | |
| 206 "<div id=\"before\"></div>" | |
| 207 "<link rel=stylesheet href=testBody1.css>" | |
| 208 "<div id=\"after1\"></div>"); | |
| 209 | |
| 210 testing::runPendingTasks(); | |
| 211 EXPECT_TRUE(document().getElementById("before")); | |
| 212 EXPECT_FALSE(document().getElementById("after1")); | |
| 213 EXPECT_FALSE(document().getElementById("after2")); | |
| 214 EXPECT_FALSE(document().getElementById("after3")); | |
| 215 | |
| 216 mainResource.write( | |
| 217 "<link rel=stylesheet href=testBody2.css>" | |
| 218 "<div id=\"after2\"></div>"); | |
| 219 | |
| 220 testing::runPendingTasks(); | |
| 221 EXPECT_TRUE(document().getElementById("before")); | |
| 222 EXPECT_FALSE(document().getElementById("after1")); | |
| 223 EXPECT_FALSE(document().getElementById("after2")); | |
| 224 EXPECT_FALSE(document().getElementById("after3")); | |
| 225 | |
| 226 mainResource.complete( | |
| 227 "<link rel=stylesheet href=testBody3.css>" | |
| 228 "<div id=\"after3\"></div>" | |
| 229 "</body></html>"); | |
| 230 | |
| 231 testing::runPendingTasks(); | |
| 232 EXPECT_TRUE(document().getElementById("before")); | |
| 233 EXPECT_FALSE(document().getElementById("after1")); | |
| 234 EXPECT_FALSE(document().getElementById("after2")); | |
| 235 EXPECT_FALSE(document().getElementById("after3")); | |
| 236 | |
| 237 // Completing the head css shouldn't change anything | |
| 238 cssHeadResource.complete(""); | |
| 239 testing::runPendingTasks(); | |
| 240 EXPECT_TRUE(document().getElementById("before")); | |
| 241 EXPECT_FALSE(document().getElementById("after1")); | |
| 242 EXPECT_FALSE(document().getElementById("after2")); | |
| 243 EXPECT_FALSE(document().getElementById("after3")); | |
| 244 | |
| 245 // Completing the second css shouldn't change anything | |
| 246 cssBodyResource2.complete(""); | |
| 247 testing::runPendingTasks(); | |
| 248 EXPECT_TRUE(document().getElementById("before")); | |
| 249 EXPECT_FALSE(document().getElementById("after1")); | |
| 250 EXPECT_FALSE(document().getElementById("after2")); | |
| 251 EXPECT_FALSE(document().getElementById("after3")); | |
| 252 | |
| 253 // Completing the first css should allow the parser to continue past it and | |
| 254 // the second css which was already completed and then pause again before the | |
| 255 // third css. | |
| 256 cssBodyResource1.complete(""); | |
| 257 testing::runPendingTasks(); | |
| 258 EXPECT_TRUE(document().getElementById("before")); | |
| 259 EXPECT_TRUE(document().getElementById("after1")); | |
| 260 EXPECT_TRUE(document().getElementById("after2")); | |
| 261 EXPECT_FALSE(document().getElementById("after3")); | |
| 262 | |
| 263 // Completing the third css should let it continue to the end. | |
| 264 cssBodyResource3.complete(""); | |
| 265 testing::runPendingTasks(); | |
| 266 EXPECT_TRUE(document().getElementById("before")); | |
| 267 EXPECT_TRUE(document().getElementById("after1")); | |
| 268 EXPECT_TRUE(document().getElementById("after2")); | |
| 269 EXPECT_TRUE(document().getElementById("after3")); | |
| 270 } | |
| 271 | |
| 272 TEST_F(HTMLDocumentParserLoadingTest, | |
| 273 ShouldPauseParsingForExternalStylesheetsInBodyIncrementalThreaded) { | |
| 274 Document::setThreadedParsingEnabledForTesting(true); | |
| 275 SimRequest mainResource("https://example.com/test.html", "text/html"); | |
| 276 SimRequest cssHeadResource("https://example.com/testHead.css", "text/css"); | |
| 277 SimRequest cssBodyResource1("https://example.com/testBody1.css", "text/css"); | |
| 278 SimRequest cssBodyResource2("https://example.com/testBody2.css", "text/css"); | |
| 279 SimRequest cssBodyResource3("https://example.com/testBody3.css", "text/css"); | |
| 280 | |
| 281 loadURL("https://example.com/test.html"); | |
| 282 | |
| 283 mainResource.start(); | |
| 284 mainResource.write( | |
| 285 "<!DOCTYPE html>" | |
| 286 "<html><head>" | |
| 287 "<link rel=stylesheet href=testHead.css>" | |
| 288 "</head><body>" | |
| 289 "<div id=\"before\"></div>" | |
| 290 "<link rel=stylesheet href=testBody1.css>" | |
| 291 "<div id=\"after1\"></div>"); | |
| 292 | |
| 293 testing::runPendingTasks(); | |
| 294 EXPECT_TRUE(document().getElementById("before")); | |
| 295 EXPECT_FALSE(document().getElementById("after1")); | |
| 296 EXPECT_FALSE(document().getElementById("after2")); | |
| 297 EXPECT_FALSE(document().getElementById("after3")); | |
| 298 | |
| 299 mainResource.write( | |
| 300 "<link rel=stylesheet href=testBody2.css>" | |
| 301 "<div id=\"after2\"></div>"); | |
| 302 | |
| 303 testing::runPendingTasks(); | |
| 304 EXPECT_TRUE(document().getElementById("before")); | |
| 305 EXPECT_FALSE(document().getElementById("after1")); | |
| 306 EXPECT_FALSE(document().getElementById("after2")); | |
| 307 EXPECT_FALSE(document().getElementById("after3")); | |
| 308 | |
| 309 mainResource.complete( | |
| 310 "<link rel=stylesheet href=testBody3.css>" | |
| 311 "<div id=\"after3\"></div>" | |
| 312 "</body></html>"); | |
| 313 | |
| 314 testing::runPendingTasks(); | |
| 315 EXPECT_TRUE(document().getElementById("before")); | |
| 316 EXPECT_FALSE(document().getElementById("after1")); | |
| 317 EXPECT_FALSE(document().getElementById("after2")); | |
| 318 EXPECT_FALSE(document().getElementById("after3")); | |
| 319 | |
| 320 // Completing the head css shouldn't change anything | |
| 321 cssHeadResource.complete(""); | |
| 322 testing::runPendingTasks(); | |
| 323 EXPECT_TRUE(document().getElementById("before")); | |
| 324 EXPECT_FALSE(document().getElementById("after1")); | |
| 325 EXPECT_FALSE(document().getElementById("after2")); | |
| 326 EXPECT_FALSE(document().getElementById("after3")); | |
| 327 | |
| 328 // Completing the second css shouldn't change anything | |
| 329 cssBodyResource2.complete(""); | |
| 330 testing::runPendingTasks(); | |
| 331 EXPECT_TRUE(document().getElementById("before")); | |
| 332 EXPECT_FALSE(document().getElementById("after1")); | |
| 333 EXPECT_FALSE(document().getElementById("after2")); | |
| 334 EXPECT_FALSE(document().getElementById("after3")); | |
| 335 | |
| 336 // Completing the first css should allow the parser to continue past it and | |
| 337 // the second css which was already completed and then pause again before the | |
| 338 // third css. | |
| 339 cssBodyResource1.complete(""); | |
| 340 testing::runPendingTasks(); | |
| 341 EXPECT_TRUE(document().getElementById("before")); | |
| 342 EXPECT_TRUE(document().getElementById("after1")); | |
| 343 EXPECT_TRUE(document().getElementById("after2")); | |
| 344 EXPECT_FALSE(document().getElementById("after3")); | |
| 345 | |
| 346 // Completing the third css should let it continue to the end. | |
| 347 cssBodyResource3.complete(""); | |
| 348 testing::runPendingTasks(); | |
| 349 EXPECT_TRUE(document().getElementById("before")); | |
| 350 EXPECT_TRUE(document().getElementById("after1")); | |
| 351 EXPECT_TRUE(document().getElementById("after2")); | |
| 352 EXPECT_TRUE(document().getElementById("after3")); | |
| 353 } | |
| 354 | |
| 355 TEST_F(HTMLDocumentParserLoadingTest, | |
| 356 ShouldNotPauseParsingForExternalNonMatchingStylesheetsInBody) { | |
| 357 Document::setThreadedParsingEnabledForTesting(false); | |
| 358 SimRequest mainResource("https://example.com/test.html", "text/html"); | |
| 359 SimRequest cssHeadResource("https://example.com/testHead.css", "text/css"); | |
| 360 | |
| 361 loadURL("https://example.com/test.html"); | |
| 362 | |
| 363 mainResource.complete( | |
| 364 "<!DOCTYPE html>" | |
| 365 "<html><head>" | |
| 366 "<link rel=stylesheet href=testHead.css>" | |
| 367 "</head><body>" | |
| 368 "<div id=\"before\"></div>" | |
| 369 "<link rel=stylesheet href=testBody.css type='print'>" | |
| 370 "<div id=\"after\"></div>" | |
| 371 "</body></html>"); | |
| 372 | |
| 373 testing::runPendingTasks(); | |
| 374 EXPECT_TRUE(document().getElementById("before")); | |
| 375 EXPECT_TRUE(document().getElementById("after")); | |
| 376 | |
| 377 // Completing the head css shouldn't change anything | |
| 378 cssHeadResource.complete(""); | |
| 379 } | |
| 380 | |
| 381 TEST_F(HTMLDocumentParserLoadingTest, | |
| 382 ShouldNotPauseParsingForExternalNonMatchingStylesheetsInBodyThreaded) { | |
| 383 Document::setThreadedParsingEnabledForTesting(true); | |
| 384 SimRequest mainResource("https://example.com/test.html", "text/html"); | |
| 385 SimRequest cssHeadResource("https://example.com/testHead.css", "text/css"); | |
| 386 | |
| 387 loadURL("https://example.com/test.html"); | |
| 388 | |
| 389 mainResource.complete( | |
| 390 "<!DOCTYPE html>" | |
| 391 "<html><head>" | |
| 392 "<link rel=stylesheet href=testHead.css>" | |
| 393 "</head><body>" | |
| 394 "<div id=\"before\"></div>" | |
| 395 "<link rel=stylesheet href=testBody.css type='print'>" | |
| 396 "<div id=\"after\"></div>" | |
| 397 "</body></html>"); | |
| 398 | |
| 399 testing::runPendingTasks(); | |
| 400 EXPECT_TRUE(document().getElementById("before")); | |
| 401 EXPECT_TRUE(document().getElementById("after")); | |
| 402 | |
| 403 // Completing the head css shouldn't change anything | |
| 404 cssHeadResource.complete(""); | |
| 405 } | |
| 406 | |
| 407 TEST_F(HTMLDocumentParserLoadingTest, | |
| 408 ShouldPauseParsingForExternalStylesheetsImportedInBody) { | |
| 409 Document::setThreadedParsingEnabledForTesting(false); | |
| 410 SimRequest mainResource("https://example.com/test.html", "text/html"); | |
| 411 SimRequest cssHeadResource("https://example.com/testHead.css", "text/css"); | |
| 412 SimRequest cssBodyResource("https://example.com/testBody.css", "text/css"); | |
| 413 | |
| 414 loadURL("https://example.com/test.html"); | |
| 415 | |
| 416 mainResource.complete( | |
| 417 "<!DOCTYPE html>" | |
| 418 "<html><head>" | |
| 419 "<link rel=stylesheet href=testHead.css>" | |
| 420 "</head><body>" | |
| 421 "<div id=\"before\"></div>" | |
| 422 "<style>" | |
| 423 "@import 'testBody.css'" | |
| 424 "</style>" | |
| 425 "<div id=\"after\"></div>" | |
| 426 "</body></html>"); | |
| 427 | |
| 428 testing::runPendingTasks(); | |
| 429 EXPECT_TRUE(document().getElementById("before")); | |
| 430 EXPECT_FALSE(document().getElementById("after")); | |
| 431 | |
| 432 // Completing the head css shouldn't change anything | |
| 433 cssHeadResource.complete(""); | |
| 434 testing::runPendingTasks(); | |
| 435 EXPECT_TRUE(document().getElementById("before")); | |
| 436 EXPECT_FALSE(document().getElementById("after")); | |
| 437 | |
| 438 // Completing the body resource and pumping the tasks should continue parsing | |
| 439 // and create the "after" div. | |
| 440 cssBodyResource.complete(""); | |
| 441 testing::runPendingTasks(); | |
| 442 EXPECT_TRUE(document().getElementById("before")); | |
| 443 EXPECT_TRUE(document().getElementById("after")); | |
| 444 } | |
| 445 | |
| 446 TEST_F(HTMLDocumentParserLoadingTest, | |
| 447 ShouldPauseParsingForExternalStylesheetsImportedInBodyThreaded) { | |
| 448 Document::setThreadedParsingEnabledForTesting(true); | |
| 449 SimRequest mainResource("https://example.com/test.html", "text/html"); | |
| 450 SimRequest cssHeadResource("https://example.com/testHead.css", "text/css"); | |
| 451 SimRequest cssBodyResource("https://example.com/testBody.css", "text/css"); | |
| 452 | |
| 453 loadURL("https://example.com/test.html"); | |
| 454 | |
| 455 mainResource.complete( | |
| 456 "<!DOCTYPE html>" | |
| 457 "<html><head>" | |
| 458 "<link rel=stylesheet href=testHead.css>" | |
| 459 "</head><body>" | |
| 460 "<div id=\"before\"></div>" | |
| 461 "<style>" | |
| 462 "@import 'testBody.css'" | |
| 463 "</style>" | |
| 464 "<div id=\"after\"></div>" | |
| 465 "</body></html>"); | |
| 466 | |
| 467 testing::runPendingTasks(); | |
| 468 EXPECT_TRUE(document().getElementById("before")); | |
| 469 EXPECT_FALSE(document().getElementById("after")); | |
| 470 | |
| 471 // Completing the head css shouldn't change anything | |
| 472 cssHeadResource.complete(""); | |
| 473 testing::runPendingTasks(); | |
| 474 EXPECT_TRUE(document().getElementById("before")); | |
| 475 EXPECT_FALSE(document().getElementById("after")); | |
| 476 | |
| 477 // Completing the body resource and pumping the tasks should continue parsing | |
| 478 // and create the "after" div. | |
| 479 cssBodyResource.complete(""); | |
| 480 testing::runPendingTasks(); | |
| 481 EXPECT_TRUE(document().getElementById("before")); | |
| 482 EXPECT_TRUE(document().getElementById("after")); | |
| 483 } | |
| 484 | |
| 485 TEST_F(HTMLDocumentParserLoadingTest, | |
| 486 ShouldPauseParsingForExternalStylesheetsWrittenInBody) { | |
| 487 Document::setThreadedParsingEnabledForTesting(false); | |
| 488 SimRequest mainResource("https://example.com/test.html", "text/html"); | |
| 489 SimRequest cssHeadResource("https://example.com/testHead.css", "text/css"); | |
| 490 SimRequest cssBodyResource("https://example.com/testBody.css", "text/css"); | |
| 491 | |
| 492 loadURL("https://example.com/test.html"); | |
| 493 | |
| 494 mainResource.complete( | |
| 495 "<!DOCTYPE html>" | |
| 496 "<html><head>" | |
| 497 "<link rel=stylesheet href=testHead.css>" | |
| 498 "</head><body>" | |
| 499 "<div id=\"before\"></div>" | |
| 500 "<script>" | |
| 501 "document.write('<link rel=stylesheet href=testBody.css>');" | |
| 502 "</script>" | |
| 503 "<div id=\"after\"></div>" | |
| 504 "</body></html>"); | |
| 505 | |
| 506 testing::runPendingTasks(); | |
| 507 EXPECT_TRUE(document().getElementById("before")); | |
| 508 EXPECT_FALSE(document().getElementById("after")); | |
| 509 | |
| 510 // Completing the head css shouldn't change anything | |
| 511 cssHeadResource.complete(""); | |
| 512 testing::runPendingTasks(); | |
| 513 EXPECT_TRUE(document().getElementById("before")); | |
| 514 EXPECT_FALSE(document().getElementById("after")); | |
| 515 | |
| 516 // Completing the body resource and pumping the tasks should continue parsing | |
| 517 // and create the "after" div. | |
| 518 cssBodyResource.complete(""); | |
| 519 testing::runPendingTasks(); | |
| 520 EXPECT_TRUE(document().getElementById("before")); | |
| 521 EXPECT_TRUE(document().getElementById("after")); | |
| 522 } | |
| 523 | |
| 524 TEST_F(HTMLDocumentParserLoadingTest, | |
| 525 ShouldPauseParsingForExternalStylesheetsWrittenInBodyThreaded) { | |
| 526 Document::setThreadedParsingEnabledForTesting(true); | |
| 527 SimRequest mainResource("https://example.com/test.html", "text/html"); | |
| 528 SimRequest cssHeadResource("https://example.com/testHead.css", "text/css"); | |
| 529 SimRequest cssBodyResource("https://example.com/testBody.css", "text/css"); | |
| 530 | |
| 531 loadURL("https://example.com/test.html"); | |
| 532 | |
| 533 mainResource.complete( | |
| 534 "<!DOCTYPE html>" | |
| 535 "<html><head>" | |
| 536 "<link rel=stylesheet href=testHead.css>" | |
| 537 "</head><body>" | |
| 538 "<div id=\"before\"></div>" | |
| 539 "<script>" | |
| 540 "document.write('<link rel=stylesheet href=testBody.css>');" | |
| 541 "</script>" | |
| 542 "<div id=\"after\"></div>" | |
| 543 "</body></html>"); | |
| 544 | |
| 545 testing::runPendingTasks(); | |
| 546 EXPECT_TRUE(document().getElementById("before")); | |
| 547 EXPECT_FALSE(document().getElementById("after")); | |
| 548 | |
| 549 // Completing the head css shouldn't change anything | |
| 550 cssHeadResource.complete(""); | |
| 551 testing::runPendingTasks(); | |
| 552 EXPECT_TRUE(document().getElementById("before")); | |
| 553 EXPECT_FALSE(document().getElementById("after")); | |
| 554 | |
| 555 // Completing the body resource and pumping the tasks should continue parsing | |
| 556 // and create the "after" div. | |
| 557 cssBodyResource.complete(""); | |
| 558 testing::runPendingTasks(); | |
| 559 EXPECT_TRUE(document().getElementById("before")); | |
| 560 EXPECT_TRUE(document().getElementById("after")); | |
| 561 } | |
| 562 | |
| 563 TEST_F(HTMLDocumentParserLoadingTest, | |
| 564 PendingHeadStylesheetShouldNotBlockParserForBodyInlineStyle) { | |
| 565 Document::setThreadedParsingEnabledForTesting(false); | |
| 566 SimRequest mainResource("https://example.com/test.html", "text/html"); | |
| 567 SimRequest cssHeadResource("https://example.com/testHead.css", "text/css"); | |
| 568 | |
| 569 loadURL("https://example.com/test.html"); | |
| 570 | |
| 571 mainResource.complete( | |
| 572 "<!DOCTYPE html>" | |
| 573 "<html><head>" | |
| 574 "<link rel=stylesheet href=testHead.css>" | |
| 575 "</head><body>" | |
| 576 "<div id=\"before\"></div>" | |
| 577 "<style>" | |
| 578 "</style>" | |
| 579 "<div id=\"after\"></div>" | |
| 580 "</body></html>"); | |
| 581 | |
| 582 testing::runPendingTasks(); | |
| 583 EXPECT_TRUE(document().getElementById("before")); | |
| 584 EXPECT_TRUE(document().getElementById("after")); | |
| 585 cssHeadResource.complete(""); | |
| 586 } | |
| 587 | |
| 588 TEST_F(HTMLDocumentParserLoadingTest, | |
| 589 PendingHeadStylesheetShouldNotBlockParserForBodyInlineStyleThreaded) { | |
| 590 Document::setThreadedParsingEnabledForTesting(true); | |
| 591 SimRequest mainResource("https://example.com/test.html", "text/html"); | |
| 592 SimRequest cssHeadResource("https://example.com/testHead.css", "text/css"); | |
| 593 | |
| 594 loadURL("https://example.com/test.html"); | |
| 595 | |
| 596 mainResource.complete( | |
| 597 "<!DOCTYPE html>" | |
| 598 "<html><head>" | |
| 599 "<link rel=stylesheet href=testHead.css>" | |
| 600 "</head><body>" | |
| 601 "<div id=\"before\"></div>" | |
| 602 "<style>" | |
| 603 "</style>" | |
| 604 "<div id=\"after\"></div>" | |
| 605 "</body></html>"); | |
| 606 | |
| 607 testing::runPendingTasks(); | |
| 608 EXPECT_TRUE(document().getElementById("before")); | |
| 609 EXPECT_TRUE(document().getElementById("after")); | |
| 610 cssHeadResource.complete(""); | |
| 611 } | |
| 612 | |
| 613 TEST_F(HTMLDocumentParserLoadingTest, | |
| 614 PendingHeadStylesheetShouldNotBlockParserForBodyShadowDom) { | |
| 615 Document::setThreadedParsingEnabledForTesting(false); | |
| 616 SimRequest mainResource("https://example.com/test.html", "text/html"); | |
| 617 SimRequest cssHeadResource("https://example.com/testHead.css", "text/css"); | |
| 618 | |
| 619 loadURL("https://example.com/test.html"); | |
| 620 | |
| 621 // The marquee tag has a shadow DOM that synchronously applies a stylesheet. | |
| 622 mainResource.complete( | |
| 623 "<!DOCTYPE html>" | |
| 624 "<html><head>" | |
| 625 "<link rel=stylesheet href=testHead.css>" | |
| 626 "</head><body>" | |
| 627 "<div id=\"before\"></div>" | |
| 628 "<marquee>Marquee</marquee>" | |
| 629 "<div id=\"after\"></div>" | |
| 630 "</body></html>"); | |
| 631 | |
| 632 testing::runPendingTasks(); | |
| 633 EXPECT_TRUE(document().getElementById("before")); | |
| 634 EXPECT_TRUE(document().getElementById("after")); | |
| 635 cssHeadResource.complete(""); | |
| 636 } | |
| 637 | |
| 638 TEST_F(HTMLDocumentParserLoadingTest, | |
| 639 PendingHeadStylesheetShouldNotBlockParserForBodyShadowDomThreaded) { | |
| 640 Document::setThreadedParsingEnabledForTesting(true); | |
| 641 SimRequest mainResource("https://example.com/test.html", "text/html"); | |
| 642 SimRequest cssHeadResource("https://example.com/testHead.css", "text/css"); | |
| 643 | |
| 644 loadURL("https://example.com/test.html"); | |
| 645 | |
| 646 // The marquee tag has a shadow DOM that synchronously applies a stylesheet. | |
| 647 mainResource.complete( | |
| 648 "<!DOCTYPE html>" | |
| 649 "<html><head>" | |
| 650 "<link rel=stylesheet href=testHead.css>" | |
| 651 "</head><body>" | |
| 652 "<div id=\"before\"></div>" | |
| 653 "<marquee>Marquee</marquee>" | |
| 654 "<div id=\"after\"></div>" | |
| 655 "</body></html>"); | |
| 656 | |
| 657 testing::runPendingTasks(); | |
| 658 EXPECT_TRUE(document().getElementById("before")); | |
| 659 EXPECT_TRUE(document().getElementById("after")); | |
| 660 cssHeadResource.complete(""); | |
| 661 } | |
| 662 | |
| 663 TEST_F(HTMLDocumentParserLoadingTest, | |
| 664 ShouldNotPauseParsingForExternalStylesheetsAttachedInBody) { | |
| 665 Document::setThreadedParsingEnabledForTesting(false); | |
| 666 SimRequest mainResource("https://example.com/test.html", "text/html"); | |
| 667 SimRequest cssAsyncResource("https://example.com/testAsync.css", "text/css"); | |
| 668 | |
| 669 loadURL("https://example.com/test.html"); | |
| 670 | |
| 671 mainResource.complete( | |
| 672 "<!DOCTYPE html>" | |
| 673 "<html><head>" | |
| 674 "</head><body>" | |
| 675 "<div id=\"before\"></div>" | |
| 676 "<script>" | |
| 677 "var attach = document.getElementsByTagName('script')[0];" | |
| 678 "var link = document.createElement('link');" | |
| 679 "link.rel = 'stylesheet';" | |
| 680 "link.type = 'text/css';" | |
| 681 "link.href = 'testAsync.css';" | |
| 682 "link.media = 'all';" | |
| 683 "attach.appendChild(link);" | |
| 684 "</script>" | |
| 685 "<div id=\"after\"></div>" | |
| 686 "</body></html>"); | |
| 687 | |
| 688 testing::runPendingTasks(); | |
| 689 EXPECT_TRUE(document().getElementById("before")); | |
| 690 EXPECT_TRUE(document().getElementById("after")); | |
| 691 | |
| 692 cssAsyncResource.complete(""); | |
| 693 } | |
| 694 | |
| 695 TEST_F(HTMLDocumentParserLoadingTest, | |
| 696 ShouldNotPauseParsingForExternalStylesheetsAttachedInBodyThreaded) { | |
| 697 Document::setThreadedParsingEnabledForTesting(true); | |
| 698 SimRequest mainResource("https://example.com/test.html", "text/html"); | |
| 699 SimRequest cssAsyncResource("https://example.com/testAsync.css", "text/css"); | |
| 700 | |
| 701 loadURL("https://example.com/test.html"); | |
| 702 | |
| 703 mainResource.complete( | |
| 704 "<!DOCTYPE html>" | |
| 705 "<html><head>" | |
| 706 "</head><body>" | |
| 707 "<div id=\"before\"></div>" | |
| 708 "<script>" | |
| 709 "var attach = document.getElementsByTagName('script')[0];" | |
| 710 "var link = document.createElement('link');" | |
| 711 "link.rel = 'stylesheet';" | |
| 712 "link.type = 'text/css';" | |
| 713 "link.href = 'testAsync.css';" | |
| 714 "link.media = 'all';" | |
| 715 "attach.appendChild(link);" | |
| 716 "</script>" | |
| 717 "<div id=\"after\"></div>" | |
| 718 "</body></html>"); | |
| 719 | |
| 720 testing::runPendingTasks(); | |
| 721 EXPECT_TRUE(document().getElementById("before")); | |
| 722 EXPECT_TRUE(document().getElementById("after")); | |
| 723 | |
| 724 cssAsyncResource.complete(""); | |
| 725 } | |
| 726 | |
| 727 } // namespace blink | |
| OLD | NEW |