1 // Copyright 2016 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 "third_party/blink/renderer/core/html/parser/html_view_source_parser.h"
6 
7 #include "testing/gtest/include/gtest/gtest.h"
8 #include "third_party/blink/renderer/core/dom/document_init.h"
9 #include "third_party/blink/renderer/core/dom/document_parser.h"
10 #include "third_party/blink/renderer/core/html/html_view_source_document.h"
11 #include "third_party/blink/renderer/platform/heap/heap.h"
12 #include "third_party/blink/renderer/platform/wtf/text/wtf_string.h"
13 
14 namespace blink {
15 
16 // This is a regression test for https://crbug.com/664915
TEST(HTMLViewSourceParserTest,DetachThenFinish_ShouldNotCrash)17 TEST(HTMLViewSourceParserTest, DetachThenFinish_ShouldNotCrash) {
18   String mime_type("text/html");
19   auto* document = MakeGarbageCollected<HTMLViewSourceDocument>(
20       DocumentInit::Create().ForTest().WithTypeFrom(mime_type));
21   auto* parser =
22       MakeGarbageCollected<HTMLViewSourceParser>(*document, mime_type);
23   // A client may detach the parser from the document.
24   parser->Detach();
25   // A DocumentWriter may call finish() after detach().
26   static_cast<DocumentParser*>(parser)->Finish();
27   // The test passed if finish did not crash.
28 }
29 
30 }  // namespace blink
31