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