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

Side by Side Diff: Source/bindings/core/v8/ScriptStreamerTest.cpp

Issue 655263003: Script streaming: fix small script recognition heuristic. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: . Created 6 years, 2 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 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"
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 public: 62 public:
63 ScriptStreamingTest() 63 ScriptStreamingTest()
64 : m_scope(v8::Isolate::GetCurrent()) 64 : m_scope(v8::Isolate::GetCurrent())
65 , m_settings(Settings::create()) 65 , m_settings(Settings::create())
66 , m_resourceRequest("http://www.streaming-test.com/") 66 , m_resourceRequest("http://www.streaming-test.com/")
67 , m_resource(new ScriptResource(m_resourceRequest, "text/utf-8")) 67 , m_resource(new ScriptResource(m_resourceRequest, "text/utf-8"))
68 , m_pendingScript(PendingScriptWrapper::create(0, m_resource)) // Takes ownership of m_resource. 68 , m_pendingScript(PendingScriptWrapper::create(0, m_resource)) // Takes ownership of m_resource.
69 { 69 {
70 m_settings->setV8ScriptStreamingEnabled(true); 70 m_settings->setV8ScriptStreamingEnabled(true);
71 m_resource->setLoading(true); 71 m_resource->setLoading(true);
72 ScriptStreamer::removeSmallScriptThresholdForTesting(); 72 ScriptStreamer::setSmallScriptThresholdForTesting(0);
73 } 73 }
74 74
75 ScriptState* scriptState() const { return m_scope.scriptState(); } 75 ScriptState* scriptState() const { return m_scope.scriptState(); }
76 v8::Isolate* isolate() const { return m_scope.isolate(); } 76 v8::Isolate* isolate() const { return m_scope.isolate(); }
77 77
78 PendingScript& pendingScript() const { return m_pendingScript->get(); } 78 PendingScript& pendingScript() const { return m_pendingScript->get(); }
79 79
80 protected: 80 protected:
81 void appendData(const char* data) 81 void appendData(const char* data)
82 { 82 {
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
271 // The finished notification should arrive immediately and not be cycled 271 // The finished notification should arrive immediately and not be cycled
272 // through a background thread. 272 // through a background thread.
273 EXPECT_TRUE(client.finished()); 273 EXPECT_TRUE(client.finished());
274 274
275 bool errorOccurred = false; 275 bool errorOccurred = false;
276 ScriptSourceCode sourceCode = pendingScript().getSource(KURL(), errorOccurre d); 276 ScriptSourceCode sourceCode = pendingScript().getSource(KURL(), errorOccurre d);
277 EXPECT_FALSE(errorOccurred); 277 EXPECT_FALSE(errorOccurred);
278 EXPECT_FALSE(sourceCode.streamer()); 278 EXPECT_FALSE(sourceCode.streamer());
279 } 279 }
280 280
281 TEST_F(ScriptStreamingTest, SmallScripts)
282 {
283 // Small scripts shouldn't be streamed.
284 ScriptStreamer::setSmallScriptThresholdForTesting(100);
285
286 ScriptStreamer::startStreaming(pendingScript(), m_settings.get(), m_scope.sc riptState(), PendingScript::ParsingBlocking);
287 TestScriptResourceClient client;
288 pendingScript().watchForLoad(&client);
289
290 appendData("function foo() { }");
291
292 finish();
293
294 // The finished notification should arrive immediately and not be cycled
295 // through a background thread.
296 EXPECT_TRUE(client.finished());
297
298 bool errorOccurred = false;
299 ScriptSourceCode sourceCode = pendingScript().getSource(KURL(), errorOccurre d);
300 EXPECT_FALSE(errorOccurred);
301 EXPECT_FALSE(sourceCode.streamer());
302 }
303
304 TEST_F(ScriptStreamingTest, ScriptsWithSmallFirstChunk)
305 {
306 // If a script is long enough, if should be streamed, even if the first data
307 // chunk is small.
308 ScriptStreamer::setSmallScriptThresholdForTesting(100);
309
310 ScriptStreamer::startStreaming(pendingScript(), m_settings.get(), m_scope.sc riptState(), PendingScript::ParsingBlocking);
311 TestScriptResourceClient client;
312 pendingScript().watchForLoad(&client);
313
314 // This is the first data chunk which is small.
315 appendData("function foo() { }");
316 appendPadding();
317 appendPadding();
318 appendPadding();
319
320 finish();
321
322 processTasksUntilStreamingComplete();
323 EXPECT_TRUE(client.finished());
324 bool errorOccurred = false;
325 ScriptSourceCode sourceCode = pendingScript().getSource(KURL(), errorOccurre d);
326 EXPECT_FALSE(errorOccurred);
327 EXPECT_TRUE(sourceCode.streamer());
328 v8::TryCatch tryCatch;
329 v8::Handle<v8::Script> script = V8ScriptRunner::compileScript(sourceCode, is olate());
330 EXPECT_FALSE(script.IsEmpty());
331 EXPECT_FALSE(tryCatch.HasCaught());
332 }
333
281 } // namespace 334 } // namespace
282 335
283 } // namespace blink 336 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698