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

Unified Diff: third_party/WebKit/Source/core/dom/ClassicPendingScriptTest.cpp

Issue 2653923008: Reland of Split PendingScript into PendingScript and ClassicPendingScript (Closed)
Patch Set: Crash fix by adding Dispose() as ClassicPendingScript prefinalizer Created 3 years, 8 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/core/dom/ClassicPendingScriptTest.cpp
diff --git a/third_party/WebKit/Source/core/dom/ClassicPendingScriptTest.cpp b/third_party/WebKit/Source/core/dom/ClassicPendingScriptTest.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..a423e06cab2948b9b15425adbfa8405ac2246527
--- /dev/null
+++ b/third_party/WebKit/Source/core/dom/ClassicPendingScriptTest.cpp
@@ -0,0 +1,84 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "core/dom/ClassicPendingScript.h"
+
+#include "core/dom/MockScriptElementBase.h"
+#include "core/loader/resource/ScriptResource.h"
+#include "testing/gmock/include/gmock/gmock.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace blink {
+
+namespace {
+
+class MockScriptStreamer : public ScriptStreamer {
+ public:
+ static MockScriptStreamer* Create(ScriptResource* resource) {
+ return new testing::StrictMock<MockScriptStreamer>(resource);
+ }
+ MockScriptStreamer(ScriptResource* resource) : resource_(resource) {}
+
+ ~MockScriptStreamer() override {}
+
+ DEFINE_INLINE_VIRTUAL_TRACE() {
+ visitor->Trace(resource_);
+ ScriptStreamer::Trace(visitor);
+ }
+
+ ScriptResource* GetResource() const { return resource_; }
+ MOCK_CONST_METHOD0(IsFinished, bool());
+ MOCK_CONST_METHOD0(StreamingSuppressed, bool());
+
+ MOCK_METHOD1(NotifyAppendData, void(ScriptResource*));
+ MOCK_METHOD1(NotifyFinished, void(Resource*));
+ MOCK_METHOD0(Source, v8::ScriptCompiler::StreamedSource*());
+ MOCK_METHOD0(Cancel, void());
+
+ private:
+ Member<ScriptResource> resource_;
+};
+
+class MockPendingScriptClient
+ : public GarbageCollectedFinalized<MockPendingScriptClient>,
+ public PendingScriptClient {
+ USING_GARBAGE_COLLECTED_MIXIN(MockPendingScriptClient);
+
+ public:
+ static MockPendingScriptClient* Create() {
+ return new testing::StrictMock<MockPendingScriptClient>();
+ }
+
+ virtual ~MockPendingScriptClient() {}
+ MOCK_METHOD1(PendingScriptFinished, void(PendingScript*));
+
+ DEFINE_INLINE_VIRTUAL_TRACE() { PendingScriptClient::Trace(visitor); }
+};
+
+// A test for crbug.com/711703. Should not crash.
+TEST(ClassicPendingScript, Prefinalizer) {
hiroshige 2017/04/19 01:01:40 I added this unit test (this crashes with Patch Se
+ ScriptResource* resource = ScriptResource::Create(
+ ResourceRequest("http://example.com/test.js"), "UTF-8");
+ ClassicPendingScript* pending_script =
+ ClassicPendingScript::Create(MockScriptElementBase::Create(), resource);
+
+ MockScriptStreamer* mock_script_streamer =
+ MockScriptStreamer::Create(resource);
+ pending_script->SetStreamer(mock_script_streamer);
+
+ EXPECT_CALL(*mock_script_streamer, Cancel());
+
+ Persistent<MockPendingScriptClient> mock_client =
+ MockPendingScriptClient::Create();
+ ASSERT_FALSE(pending_script->IsReady());
+ pending_script->WatchForLoad(mock_client);
+
+ ThreadState::Current()->CollectGarbage(BlinkGC::kNoHeapPointersOnStack,
+ BlinkGC::kGCWithSweep,
+ BlinkGC::kForcedGC);
+}
+
+} // namespace
+
+} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698