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

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

Powered by Google App Engine
This is Rietveld 408576698