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/dom/ClassicPendingScript.h" | |
6 | |
7 #include "core/dom/MockScriptElementBase.h" | |
8 #include "core/loader/resource/ScriptResource.h" | |
9 #include "testing/gmock/include/gmock/gmock.h" | |
10 #include "testing/gtest/include/gtest/gtest.h" | |
11 | |
12 namespace blink { | |
13 | |
14 namespace { | |
15 | |
16 class MockScriptStreamer : public ScriptStreamer { | |
17 public: | |
18 static MockScriptStreamer* Create(ScriptResource* resource) { | |
19 return new testing::StrictMock<MockScriptStreamer>(resource); | |
20 } | |
21 MockScriptStreamer(ScriptResource* resource) : resource_(resource) {} | |
22 | |
23 ~MockScriptStreamer() override {} | |
24 | |
25 DEFINE_INLINE_VIRTUAL_TRACE() { | |
26 visitor->Trace(resource_); | |
27 ScriptStreamer::Trace(visitor); | |
28 } | |
29 | |
30 ScriptResource* GetResource() const { return resource_; } | |
31 MOCK_CONST_METHOD0(IsFinished, bool()); | |
32 MOCK_CONST_METHOD0(StreamingSuppressed, bool()); | |
33 | |
34 MOCK_METHOD1(NotifyAppendData, void(ScriptResource*)); | |
35 MOCK_METHOD1(NotifyFinished, void(Resource*)); | |
36 MOCK_METHOD0(Source, v8::ScriptCompiler::StreamedSource*()); | |
37 MOCK_METHOD0(Cancel, void()); | |
38 | |
39 private: | |
40 Member<ScriptResource> resource_; | |
41 }; | |
42 | |
43 class MockPendingScriptClient | |
44 : public GarbageCollectedFinalized<MockPendingScriptClient>, | |
45 public PendingScriptClient { | |
46 USING_GARBAGE_COLLECTED_MIXIN(MockPendingScriptClient); | |
47 | |
48 public: | |
49 static MockPendingScriptClient* Create() { | |
50 return new testing::StrictMock<MockPendingScriptClient>(); | |
51 } | |
52 | |
53 virtual ~MockPendingScriptClient() {} | |
54 MOCK_METHOD1(PendingScriptFinished, void(PendingScript*)); | |
55 | |
56 DEFINE_INLINE_VIRTUAL_TRACE() { PendingScriptClient::Trace(visitor); } | |
57 }; | |
58 | |
59 // A test for crbug.com/711703. Should not crash. | |
60 TEST(ClassicPendingScript, Prefinalizer) { | |
hiroshige
2017/04/19 01:01:40
I added this unit test (this crashes with Patch Se
| |
61 ScriptResource* resource = ScriptResource::Create( | |
62 ResourceRequest("http://example.com/test.js"), "UTF-8"); | |
63 ClassicPendingScript* pending_script = | |
64 ClassicPendingScript::Create(MockScriptElementBase::Create(), resource); | |
65 | |
66 MockScriptStreamer* mock_script_streamer = | |
67 MockScriptStreamer::Create(resource); | |
68 pending_script->SetStreamer(mock_script_streamer); | |
69 | |
70 EXPECT_CALL(*mock_script_streamer, Cancel()); | |
71 | |
72 Persistent<MockPendingScriptClient> mock_client = | |
73 MockPendingScriptClient::Create(); | |
74 ASSERT_FALSE(pending_script->IsReady()); | |
75 pending_script->WatchForLoad(mock_client); | |
76 | |
77 ThreadState::Current()->CollectGarbage(BlinkGC::kNoHeapPointersOnStack, | |
78 BlinkGC::kGCWithSweep, | |
79 BlinkGC::kForcedGC); | |
80 } | |
81 | |
82 } // namespace | |
83 | |
84 } // namespace blink | |
OLD | NEW |