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 | 5 |
6 #include "config.h" | 6 #include "config.h" |
7 #include "bindings/core/v8/ScriptStreamer.h" | 7 #include "bindings/core/v8/ScriptStreamer.h" |
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/V8ScriptRunner.h" | 12 #include "bindings/core/v8/V8ScriptRunner.h" |
13 #include "core/dom/Element.h" | 13 #include "core/dom/Element.h" |
14 #include "core/dom/PendingScript.h" | 14 #include "core/dom/PendingScript.h" |
15 #include "core/frame/Settings.h" | 15 #include "core/frame/Settings.h" |
| 16 #include "core/testing/UnitTestHelpers.h" |
16 #include "platform/Task.h" | 17 #include "platform/Task.h" |
17 #include "platform/heap/Handle.h" | 18 #include "platform/heap/Handle.h" |
18 #include "public/platform/Platform.h" | 19 #include "public/platform/Platform.h" |
19 | 20 |
20 #include <gtest/gtest.h> | 21 #include <gtest/gtest.h> |
21 #include <v8.h> | 22 #include <v8.h> |
22 | 23 |
23 namespace blink { | 24 namespace blink { |
24 | 25 |
25 namespace { | 26 namespace { |
(...skipping 26 matching lines...) Expand all Loading... |
52 } | 53 } |
53 | 54 |
54 PendingScriptWrapper(Element* element, ScriptResource* resource) | 55 PendingScriptWrapper(Element* element, ScriptResource* resource) |
55 : m_pendingScript(PendingScript(element, resource)) | 56 : m_pendingScript(PendingScript(element, resource)) |
56 { | 57 { |
57 } | 58 } |
58 | 59 |
59 PendingScript m_pendingScript; | 60 PendingScript m_pendingScript; |
60 }; | 61 }; |
61 | 62 |
62 class ScriptStreamingTest : public testing::Test { | 63 class ScriptStreamingTest : public ::testing::Test { |
63 public: | 64 public: |
64 ScriptStreamingTest() | 65 ScriptStreamingTest() |
65 : m_scope(v8::Isolate::GetCurrent()) | 66 : m_scope(v8::Isolate::GetCurrent()) |
66 , m_settings(Settings::create()) | 67 , m_settings(Settings::create()) |
67 , m_resourceRequest("http://www.streaming-test.com/") | 68 , m_resourceRequest("http://www.streaming-test.com/") |
68 , m_resource(ScriptResource::create(m_resourceRequest, "UTF-8").leakPtr(
)) | 69 , m_resource(ScriptResource::create(m_resourceRequest, "UTF-8").leakPtr(
)) |
69 , m_pendingScript(PendingScriptWrapper::create(0, m_resource)) // Takes
ownership of m_resource. | 70 , m_pendingScript(PendingScriptWrapper::create(0, m_resource)) // Takes
ownership of m_resource. |
70 { | 71 { |
71 m_resource->setLoading(true); | 72 m_resource->setLoading(true); |
72 ScriptStreamer::setSmallScriptThresholdForTesting(0); | 73 ScriptStreamer::setSmallScriptThresholdForTesting(0); |
(...skipping 26 matching lines...) Expand all Loading... |
99 } | 100 } |
100 | 101 |
101 void finish() | 102 void finish() |
102 { | 103 { |
103 m_resource->finish(); | 104 m_resource->finish(); |
104 m_resource->setLoading(false); | 105 m_resource->setLoading(false); |
105 } | 106 } |
106 | 107 |
107 void processTasksUntilStreamingComplete() | 108 void processTasksUntilStreamingComplete() |
108 { | 109 { |
109 WebThread* currentThread = blink::Platform::current()->currentThread(); | |
110 while (ScriptStreamerThread::shared()->isRunningTask()) { | 110 while (ScriptStreamerThread::shared()->isRunningTask()) { |
111 currentThread->postTask(FROM_HERE, new Task(WTF::bind(&WebThread::ex
itRunLoop, currentThread))); | 111 testing::runPendingTasks(); |
112 currentThread->enterRunLoop(); | |
113 } | 112 } |
114 // Once more, because the "streaming complete" notification might only | 113 // Once more, because the "streaming complete" notification might only |
115 // now be in the task queue. | 114 // now be in the task queue. |
116 currentThread->postTask(FROM_HERE, new Task(WTF::bind(&WebThread::exitRu
nLoop, currentThread))); | 115 testing::runPendingTasks(); |
117 currentThread->enterRunLoop(); | |
118 } | 116 } |
119 | 117 |
120 V8TestingScope m_scope; | 118 V8TestingScope m_scope; |
121 OwnPtr<Settings> m_settings; | 119 OwnPtr<Settings> m_settings; |
122 // The Resource and PendingScript where we stream from. These don't really | 120 // The Resource and PendingScript where we stream from. These don't really |
123 // fetch any data outside the test; the test controls the data by calling | 121 // fetch any data outside the test; the test controls the data by calling |
124 // ScriptResource::appendData. | 122 // ScriptResource::appendData. |
125 ResourceRequest m_resourceRequest; | 123 ResourceRequest m_resourceRequest; |
126 ScriptResource* m_resource; | 124 ScriptResource* m_resource; |
127 OwnPtrWillBePersistent<PendingScriptWrapper> m_pendingScript; | 125 OwnPtrWillBePersistent<PendingScriptWrapper> m_pendingScript; |
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
385 EXPECT_TRUE(sourceCode.streamer()); | 383 EXPECT_TRUE(sourceCode.streamer()); |
386 v8::TryCatch tryCatch; | 384 v8::TryCatch tryCatch; |
387 v8::Handle<v8::Script> script = V8ScriptRunner::compileScript(sourceCode, is
olate()); | 385 v8::Handle<v8::Script> script = V8ScriptRunner::compileScript(sourceCode, is
olate()); |
388 EXPECT_FALSE(script.IsEmpty()); | 386 EXPECT_FALSE(script.IsEmpty()); |
389 EXPECT_FALSE(tryCatch.HasCaught()); | 387 EXPECT_FALSE(tryCatch.HasCaught()); |
390 } | 388 } |
391 | 389 |
392 } // namespace | 390 } // namespace |
393 | 391 |
394 } // namespace blink | 392 } // namespace blink |
OLD | NEW |