| 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" |
| 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 : m_loadingTaskRunner(Platform::current() | 31 : m_loadingTaskRunner(Platform::current() |
| 33 ->currentThread() | 32 ->currentThread() |
| 34 ->scheduler() | 33 ->scheduler() |
| 35 ->loadingTaskRunner()), | 34 ->loadingTaskRunner()), |
| 36 m_settings(Settings::create()), | 35 m_settings(Settings::create()), |
| 37 m_resourceRequest("http://www.streaming-test.com/"), | 36 m_resourceRequest("http://www.streaming-test.com/"), |
| 38 m_resource(ScriptResource::create(m_resourceRequest, "UTF-8")), | 37 m_resource(ScriptResource::create(m_resourceRequest, "UTF-8")), |
| 39 m_pendingScript(PendingScript::createForTesting(m_resource.get())) { | 38 m_pendingScript( |
| 39 ClassicPendingScript::createForTesting(m_resource.get())) { |
| 40 m_resource->setStatus(ResourceStatus::Pending); | 40 m_resource->setStatus(ResourceStatus::Pending); |
| 41 m_pendingScript = PendingScript::createForTesting(m_resource.get()); | 41 m_pendingScript = ClassicPendingScript::createForTesting(m_resource.get()); |
| 42 ScriptStreamer::setSmallScriptThresholdForTesting(0); | 42 ScriptStreamer::setSmallScriptThresholdForTesting(0); |
| 43 } | 43 } |
| 44 | 44 |
| 45 ~ScriptStreamingTest() { | 45 ~ScriptStreamingTest() { |
| 46 if (m_pendingScript) | 46 if (m_pendingScript) |
| 47 m_pendingScript->dispose(); | 47 m_pendingScript->dispose(); |
| 48 } | 48 } |
| 49 | 49 |
| 50 PendingScript* getPendingScript() const { return m_pendingScript.get(); } | 50 ClassicPendingScript* getPendingScript() const { |
| 51 return m_pendingScript.get(); |
| 52 } |
| 51 | 53 |
| 52 protected: | 54 protected: |
| 53 void appendData(const char* data) { | 55 void appendData(const char* data) { |
| 54 m_resource->appendData(data, strlen(data)); | 56 m_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 Loading... |
| 83 testing::runPendingTasks(); | 85 testing::runPendingTasks(); |
| 84 } | 86 } |
| 85 | 87 |
| 86 RefPtr<WebTaskRunner> m_loadingTaskRunner; | 88 RefPtr<WebTaskRunner> m_loadingTaskRunner; |
| 87 std::unique_ptr<Settings> m_settings; | 89 std::unique_ptr<Settings> m_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 m_resourceRequest; | 93 ResourceRequest m_resourceRequest; |
| 92 Persistent<ScriptResource> m_resource; | 94 Persistent<ScriptResource> m_resource; |
| 93 Persistent<PendingScript> m_pendingScript; | 95 Persistent<ClassicPendingScript> m_pendingScript; |
| 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() : m_finished(false) {} | 104 TestPendingScriptClient() : m_finished(false) {} |
| 103 void pendingScriptFinished(PendingScript*) override { m_finished = true; } | 105 void pendingScriptFinished(PendingScript*) override { m_finished = true; } |
| (...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 397 EXPECT_TRUE(V8ScriptRunner::compileScript(sourceCode, scope.isolate(), | 399 EXPECT_TRUE(V8ScriptRunner::compileScript(sourceCode, scope.isolate(), |
| 398 SharableCrossOrigin, | 400 SharableCrossOrigin, |
| 399 V8CacheOptionsDefault) | 401 V8CacheOptionsDefault) |
| 400 .ToLocal(&script)); | 402 .ToLocal(&script)); |
| 401 EXPECT_FALSE(tryCatch.HasCaught()); | 403 EXPECT_FALSE(tryCatch.HasCaught()); |
| 402 } | 404 } |
| 403 | 405 |
| 404 } // namespace | 406 } // namespace |
| 405 | 407 |
| 406 } // namespace blink | 408 } // namespace blink |
| OLD | NEW |