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

Side by Side Diff: third_party/WebKit/Source/bindings/core/v8/ScriptStreamerTest.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 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 #include "bindings/core/v8/ScriptStreamer.h" 5 #include "bindings/core/v8/ScriptStreamer.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "bindings/core/v8/ScriptSourceCode.h" 9 #include "bindings/core/v8/ScriptSourceCode.h"
10 #include "bindings/core/v8/ScriptStreamerImpl.h" 10 #include "bindings/core/v8/ScriptStreamerImpl.h"
11 #include "bindings/core/v8/ScriptStreamerThread.h" 11 #include "bindings/core/v8/ScriptStreamerThread.h"
12 #include "bindings/core/v8/V8Binding.h" 12 #include "bindings/core/v8/V8Binding.h"
13 #include "bindings/core/v8/V8BindingForTesting.h" 13 #include "bindings/core/v8/V8BindingForTesting.h"
14 #include "bindings/core/v8/V8ScriptRunner.h" 14 #include "bindings/core/v8/V8ScriptRunner.h"
15 #include "core/dom/ClassicPendingScript.h"
15 #include "core/dom/ClassicScript.h" 16 #include "core/dom/ClassicScript.h"
16 #include "core/dom/PendingScript.h"
17 #include "core/frame/Settings.h" 17 #include "core/frame/Settings.h"
18 #include "platform/heap/Handle.h" 18 #include "platform/heap/Handle.h"
19 #include "platform/testing/UnitTestHelpers.h" 19 #include "platform/testing/UnitTestHelpers.h"
20 #include "public/platform/Platform.h" 20 #include "public/platform/Platform.h"
21 #include "public/platform/WebScheduler.h" 21 #include "public/platform/WebScheduler.h"
22 #include "testing/gtest/include/gtest/gtest.h" 22 #include "testing/gtest/include/gtest/gtest.h"
23 #include "v8/include/v8.h" 23 #include "v8/include/v8.h"
24 24
25 namespace blink { 25 namespace blink {
26 26
27 namespace { 27 namespace {
28 28
29 class ScriptStreamingTest : public ::testing::Test { 29 class ScriptStreamingTest : public ::testing::Test {
30 public: 30 public:
31 ScriptStreamingTest() 31 ScriptStreamingTest()
32 : loading_task_runner_(Platform::Current() 32 : loading_task_runner_(Platform::Current()
33 ->CurrentThread() 33 ->CurrentThread()
34 ->Scheduler() 34 ->Scheduler()
35 ->LoadingTaskRunner()), 35 ->LoadingTaskRunner()),
36 settings_(Settings::Create()), 36 settings_(Settings::Create()),
37 resource_request_("http://www.streaming-test.com/"), 37 resource_request_("http://www.streaming-test.com/"),
38 resource_(ScriptResource::Create(resource_request_, "UTF-8")), 38 resource_(ScriptResource::Create(resource_request_, "UTF-8")),
39 pending_script_(PendingScript::CreateForTesting(resource_.Get())) { 39 pending_script_(
40 ClassicPendingScript::CreateForTesting(resource_.Get())) {
40 resource_->SetStatus(ResourceStatus::kPending); 41 resource_->SetStatus(ResourceStatus::kPending);
41 pending_script_ = PendingScript::CreateForTesting(resource_.Get()); 42 pending_script_ = ClassicPendingScript::CreateForTesting(resource_.Get());
42 ScriptStreamerImpl::SetSmallScriptThresholdForTesting(0); 43 ScriptStreamerImpl::SetSmallScriptThresholdForTesting(0);
43 } 44 }
44 45
45 ~ScriptStreamingTest() { 46 ~ScriptStreamingTest() {
46 if (pending_script_) 47 if (pending_script_)
47 pending_script_->Dispose(); 48 pending_script_->Dispose();
48 } 49 }
49 50
50 PendingScript* GetPendingScript() const { return pending_script_.Get(); } 51 ClassicPendingScript* GetPendingScript() const {
52 return pending_script_.Get();
53 }
51 54
52 protected: 55 protected:
53 void AppendData(const char* data) { 56 void AppendData(const char* data) {
54 resource_->AppendData(data, strlen(data)); 57 resource_->AppendData(data, strlen(data));
55 // Yield control to the background thread, so that V8 gets a chance to 58 // Yield control to the background thread, so that V8 gets a chance to
56 // process the data before the main thread adds more. Note that we 59 // process the data before the main thread adds more. Note that we
57 // cannot fully control in what kind of chunks the data is passed to V8 60 // cannot fully control in what kind of chunks the data is passed to V8
58 // (if V8 is not requesting more data between two appendData calls, it 61 // (if V8 is not requesting more data between two appendData calls, it
59 // will get both chunks together). 62 // will get both chunks together).
60 testing::YieldCurrentThread(); 63 testing::YieldCurrentThread();
(...skipping 22 matching lines...) Expand all
83 testing::RunPendingTasks(); 86 testing::RunPendingTasks();
84 } 87 }
85 88
86 RefPtr<WebTaskRunner> loading_task_runner_; 89 RefPtr<WebTaskRunner> loading_task_runner_;
87 std::unique_ptr<Settings> settings_; 90 std::unique_ptr<Settings> settings_;
88 // The Resource and PendingScript where we stream from. These don't really 91 // 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 92 // fetch any data outside the test; the test controls the data by calling
90 // ScriptResource::appendData. 93 // ScriptResource::appendData.
91 ResourceRequest resource_request_; 94 ResourceRequest resource_request_;
92 Persistent<ScriptResource> resource_; 95 Persistent<ScriptResource> resource_;
93 Persistent<PendingScript> pending_script_; 96 Persistent<ClassicPendingScript> pending_script_;
94 }; 97 };
95 98
96 class TestPendingScriptClient 99 class TestPendingScriptClient
97 : public GarbageCollectedFinalized<TestPendingScriptClient>, 100 : public GarbageCollectedFinalized<TestPendingScriptClient>,
98 public PendingScriptClient { 101 public PendingScriptClient {
99 USING_GARBAGE_COLLECTED_MIXIN(TestPendingScriptClient); 102 USING_GARBAGE_COLLECTED_MIXIN(TestPendingScriptClient);
100 103
101 public: 104 public:
102 TestPendingScriptClient() : finished_(false) {} 105 TestPendingScriptClient() : finished_(false) {}
103 void PendingScriptFinished(PendingScript*) override { finished_ = true; } 106 void PendingScriptFinished(PendingScript*) override { finished_ = true; }
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after
405 EXPECT_TRUE(V8ScriptRunner::CompileScript(source_code, scope.GetIsolate(), 408 EXPECT_TRUE(V8ScriptRunner::CompileScript(source_code, scope.GetIsolate(),
406 kSharableCrossOrigin, 409 kSharableCrossOrigin,
407 kV8CacheOptionsDefault) 410 kV8CacheOptionsDefault)
408 .ToLocal(&script)); 411 .ToLocal(&script));
409 EXPECT_FALSE(try_catch.HasCaught()); 412 EXPECT_FALSE(try_catch.HasCaught());
410 } 413 }
411 414
412 } // namespace 415 } // namespace
413 416
414 } // namespace blink 417 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698