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

Side by Side Diff: third_party/WebKit/Source/bindings/core/v8/ScriptStreamerTest.cpp

Issue 1667843003: Make Resource RefCountedWillBeGarbageCollectedFinalized, attempt #2 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase + address review comments Created 4 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 5
6 #include "bindings/core/v8/ScriptStreamer.h" 6 #include "bindings/core/v8/ScriptStreamer.h"
7 7
8 #include "bindings/core/v8/ScriptSourceCode.h" 8 #include "bindings/core/v8/ScriptSourceCode.h"
9 #include "bindings/core/v8/ScriptStreamerThread.h" 9 #include "bindings/core/v8/ScriptStreamerThread.h"
10 #include "bindings/core/v8/V8Binding.h" 10 #include "bindings/core/v8/V8Binding.h"
(...skipping 14 matching lines...) Expand all
25 25
26 namespace { 26 namespace {
27 27
28 class ScriptStreamingTest : public ::testing::Test { 28 class ScriptStreamingTest : public ::testing::Test {
29 public: 29 public:
30 ScriptStreamingTest() 30 ScriptStreamingTest()
31 : m_loadingTaskRunner(Platform::current()->currentThread()->scheduler()- >loadingTaskRunner()) 31 : m_loadingTaskRunner(Platform::current()->currentThread()->scheduler()- >loadingTaskRunner())
32 , m_scope(v8::Isolate::GetCurrent()) 32 , m_scope(v8::Isolate::GetCurrent())
33 , m_settings(Settings::create()) 33 , m_settings(Settings::create())
34 , m_resourceRequest("http://www.streaming-test.com/") 34 , m_resourceRequest("http://www.streaming-test.com/")
35 , m_resource(new ScriptResource(m_resourceRequest, "UTF-8")) 35 , m_resource(ScriptResource::create(m_resourceRequest, "UTF-8"))
36 , m_pendingScript(PendingScript::create(0, m_resource.get())) 36 , m_pendingScript(PendingScript::create(0, m_resource.get()))
37 { 37 {
38 m_resource->setLoading(true); 38 m_resource->setLoading(true);
39 m_pendingScript = PendingScript::create(0, m_resource.get()); 39 m_pendingScript = PendingScript::create(0, m_resource.get());
40 ScriptStreamer::setSmallScriptThresholdForTesting(0); 40 ScriptStreamer::setSmallScriptThresholdForTesting(0);
41 } 41 }
42 42
43 ScriptState* scriptState() const { return m_scope.scriptState(); } 43 ScriptState* scriptState() const { return m_scope.scriptState(); }
44 v8::Isolate* isolate() const { return m_scope.isolate(); } 44 v8::Isolate* isolate() const { return m_scope.isolate(); }
45 45
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 testing::runPendingTasks(); 82 testing::runPendingTasks();
83 } 83 }
84 84
85 WebTaskRunner* m_loadingTaskRunner; // NOT OWNED 85 WebTaskRunner* m_loadingTaskRunner; // NOT OWNED
86 V8TestingScope m_scope; 86 V8TestingScope m_scope;
87 OwnPtr<Settings> m_settings; 87 OwnPtr<Settings> m_settings;
88 // The Resource and PendingScript where we stream from. These don't really 88 // The Resource and PendingScript where we stream from. These don't really
89 // fetch any data outside the test; the test controls the data by calling 89 // fetch any data outside the test; the test controls the data by calling
90 // ScriptResource::appendData. 90 // ScriptResource::appendData.
91 ResourceRequest m_resourceRequest; 91 ResourceRequest m_resourceRequest;
92 ResourcePtr<ScriptResource> m_resource; 92 RefPtrWillBePersistent<ScriptResource> m_resource;
93 OwnPtrWillBePersistent<PendingScript> m_pendingScript; 93 OwnPtrWillBePersistent<PendingScript> m_pendingScript;
94 }; 94 };
95 95
96 class TestScriptResourceClient : public ScriptResourceClient { 96 class TestScriptResourceClient : public ScriptResourceClient {
97 public: 97 public:
98 TestScriptResourceClient() 98 TestScriptResourceClient()
99 : m_finished(false) { } 99 : m_finished(false) { }
100 100
101 void notifyFinished(Resource*) override { m_finished = true; } 101 void notifyFinished(Resource*) override { m_finished = true; }
102 String debugName() const override { return "TestScriptResourceClient"; } 102 String debugName() const override { return "TestScriptResourceClient"; }
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 pendingScript()->watchForLoad(&client); 184 pendingScript()->watchForLoad(&client);
185 appendData("function foo() {"); 185 appendData("function foo() {");
186 186
187 // In general, we cannot control what the background thread is doing 187 // In general, we cannot control what the background thread is doing
188 // (whether it's parsing or waiting for more data). In this test, we have 188 // (whether it's parsing or waiting for more data). In this test, we have
189 // given it so little data that it's surely waiting for more. 189 // given it so little data that it's surely waiting for more.
190 190
191 // Simulate cancelling the network load (e.g., because the user navigated 191 // Simulate cancelling the network load (e.g., because the user navigated
192 // away). 192 // away).
193 EXPECT_FALSE(client.finished()); 193 EXPECT_FALSE(client.finished());
194 pendingScript()->stopWatchingForLoad(&client); 194 pendingScript()->stopWatchingForLoad();
195 pendingScript()->releaseElementAndClear(); 195 pendingScript()->releaseElementAndClear();
196 m_pendingScript = nullptr; // This will destroy m_resource. 196 m_pendingScript = nullptr; // This will destroy m_resource.
197 m_resource = 0; 197 m_resource = nullptr;
198 198
199 // The V8 side will complete too. This should not crash. We don't receive 199 // The V8 side will complete too. This should not crash. We don't receive
200 // any results from the streaming and the client doesn't get notified. 200 // any results from the streaming and the client doesn't get notified.
201 processTasksUntilStreamingComplete(); 201 processTasksUntilStreamingComplete();
202 EXPECT_FALSE(client.finished()); 202 EXPECT_FALSE(client.finished());
203 } 203 }
204 204
205 TEST_F(ScriptStreamingTest, SuppressingStreaming) 205 TEST_F(ScriptStreamingTest, SuppressingStreaming)
206 { 206 {
207 // If we notice during streaming that there is a code cache, streaming 207 // If we notice during streaming that there is a code cache, streaming
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
376 EXPECT_TRUE(sourceCode.streamer()); 376 EXPECT_TRUE(sourceCode.streamer());
377 v8::TryCatch tryCatch(isolate()); 377 v8::TryCatch tryCatch(isolate());
378 v8::Local<v8::Script> script; 378 v8::Local<v8::Script> script;
379 EXPECT_TRUE(V8ScriptRunner::compileScript(sourceCode, isolate()).ToLocal(&sc ript)); 379 EXPECT_TRUE(V8ScriptRunner::compileScript(sourceCode, isolate()).ToLocal(&sc ript));
380 EXPECT_FALSE(tryCatch.HasCaught()); 380 EXPECT_FALSE(tryCatch.HasCaught());
381 } 381 }
382 382
383 } // namespace 383 } // namespace
384 384
385 } // namespace blink 385 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698