Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(154)

Side by Side Diff: third_party/WebKit/Source/web/tests/HTMLDocumentParserLoadingTest.cpp

Issue 2674533009: Add SimTests for HTML parser rewinding (Closed)
Patch Set: add <title> test Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "core/html/parser/HTMLDocumentParser.h" 5 #include "core/html/parser/HTMLDocumentParser.h"
6 6
7 #include "core/dom/Document.h" 7 #include "core/dom/Document.h"
8 #include "platform/testing/HistogramTester.h"
8 #include "platform/testing/UnitTestHelpers.h" 9 #include "platform/testing/UnitTestHelpers.h"
9 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
10 #include "web/tests/sim/SimRequest.h" 11 #include "web/tests/sim/SimRequest.h"
11 #include "web/tests/sim/SimTest.h" 12 #include "web/tests/sim/SimTest.h"
12 13
13 namespace blink { 14 namespace blink {
14 15
15 using namespace HTMLNames; 16 using namespace HTMLNames;
16 17
18 class HTMLDocumentParserSimTest : public SimTest {
19 protected:
20 HTMLDocumentParserSimTest() {
21 Document::setThreadedParsingEnabledForTesting(true);
22 }
23 HistogramTester m_histogram;
24 };
25
17 class HTMLDocumentParserLoadingTest 26 class HTMLDocumentParserLoadingTest
18 : public SimTest, 27 : public HTMLDocumentParserSimTest,
19 public ::testing::WithParamInterface<bool> { 28 public ::testing::WithParamInterface<bool> {
20 protected: 29 protected:
21 HTMLDocumentParserLoadingTest() { 30 HTMLDocumentParserLoadingTest() {
22 Document::setThreadedParsingEnabledForTesting(GetParam()); 31 Document::setThreadedParsingEnabledForTesting(GetParam());
23 } 32 }
24 }; 33 };
25 34
26 INSTANTIATE_TEST_CASE_P(Threaded, 35 INSTANTIATE_TEST_CASE_P(Threaded,
27 HTMLDocumentParserLoadingTest, 36 HTMLDocumentParserLoadingTest,
28 ::testing::Values(true)); 37 ::testing::Values(true));
(...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after
367 "<div id=\"after\"></div>" 376 "<div id=\"after\"></div>"
368 "</body></html>"); 377 "</body></html>");
369 378
370 testing::runPendingTasks(); 379 testing::runPendingTasks();
371 EXPECT_TRUE(document().getElementById("before")); 380 EXPECT_TRUE(document().getElementById("before"));
372 EXPECT_TRUE(document().getElementById("after")); 381 EXPECT_TRUE(document().getElementById("after"));
373 382
374 cssAsyncResource.complete(""); 383 cssAsyncResource.complete("");
375 } 384 }
376 385
386 TEST_F(HTMLDocumentParserSimTest, NoRewindNoDocWrite) {
387 SimRequest mainResource("https://example.com/test.html", "text/html");
388 loadURL("https://example.com/test.html");
389
390 mainResource.complete(
391 "<!DOCTYPE html>"
392 "<html><body>no doc write"
393 "</body></html>");
394
395 testing::runPendingTasks();
396 m_histogram.expectTotalCount("Parser.DiscardedTokenCount", 0);
397 }
398
399 TEST_F(HTMLDocumentParserSimTest, RewindBrokenToken) {
400 SimRequest mainResource("https://example.com/test.html", "text/html");
401 loadURL("https://example.com/test.html");
402
403 mainResource.complete(
404 "<!DOCTYPE html>"
405 "<script>"
406 "document.write('<a');"
407 "</script>");
408
409 testing::runPendingTasks();
410 m_histogram.expectTotalCount("Parser.DiscardedTokenCount", 1);
411 }
412
413 TEST_F(HTMLDocumentParserSimTest, RewindDifferentNamespace) {
414 SimRequest mainResource("https://example.com/test.html", "text/html");
415 loadURL("https://example.com/test.html");
416
417 mainResource.complete(
418 "<!DOCTYPE html>"
419 "<script>"
420 "document.write('<svg>');"
421 "</script>");
422
423 testing::runPendingTasks();
424 m_histogram.expectTotalCount("Parser.DiscardedTokenCount", 1);
425 }
426
427 TEST_F(HTMLDocumentParserSimTest, NoRewindSaneDocWrite1) {
428 SimRequest mainResource("https://example.com/test.html", "text/html");
429 loadURL("https://example.com/test.html");
430
431 mainResource.complete(
432 "<!DOCTYPE html>"
433 "<script>"
434 "document.write('<script>console.log(\'hello world\');<\\/script>');"
435 "</script>");
436
437 testing::runPendingTasks();
438 m_histogram.expectTotalCount("Parser.DiscardedTokenCount", 0);
439 }
440
441 TEST_F(HTMLDocumentParserSimTest, NoRewindSaneDocWrite2) {
442 SimRequest mainResource("https://example.com/test.html", "text/html");
443 loadURL("https://example.com/test.html");
444
445 mainResource.complete(
446 "<!DOCTYPE html>"
447 "<script>"
448 "document.write('<p>hello world<\\/p><a>yo');"
449 "</script>");
450
451 testing::runPendingTasks();
452 m_histogram.expectTotalCount("Parser.DiscardedTokenCount", 0);
453 }
454
455 TEST_F(HTMLDocumentParserSimTest, NoRewindSaneDocWriteWithTitle) {
456 SimRequest mainResource("https://example.com/test.html", "text/html");
457 loadURL("https://example.com/test.html");
458
459 mainResource.complete(
460 "<!DOCTYPE html>"
461 "<html>"
462 "<head>"
463 "<title></title>"
464 "<script>document.write('<p>testing');</script>"
465 "</head>"
466 "<body>"
467 "</body>"
468 "</html>");
469
470 testing::runPendingTasks();
471 m_histogram.expectTotalCount("Parser.DiscardedTokenCount", 0);
472 }
473
377 } // namespace blink 474 } // namespace blink
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698