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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: Source/bindings/core/v8/ScriptStreamerTest.cpp
diff --git a/Source/bindings/core/v8/ScriptStreamerTest.cpp b/Source/bindings/core/v8/ScriptStreamerTest.cpp
index 2d007a28945078699358f86c0ae1e238ffdb53e5..ccc814ab96772b0a0a9364bcbd85e4311a62c1c1 100644
--- a/Source/bindings/core/v8/ScriptStreamerTest.cpp
+++ b/Source/bindings/core/v8/ScriptStreamerTest.cpp
@@ -69,7 +69,7 @@ public:
{
m_settings->setV8ScriptStreamingEnabled(true);
m_resource->setLoading(true);
- ScriptStreamer::removeSmallScriptThresholdForTesting();
+ ScriptStreamer::setSmallScriptThresholdForTesting(0);
}
ScriptState* scriptState() const { return m_scope.scriptState(); }
@@ -278,6 +278,59 @@ TEST_F(ScriptStreamingTest, EmptyScripts)
EXPECT_FALSE(sourceCode.streamer());
}
+TEST_F(ScriptStreamingTest, SmallScripts)
+{
+ // Small scripts shouldn't be streamed.
+ ScriptStreamer::setSmallScriptThresholdForTesting(100);
+
+ ScriptStreamer::startStreaming(pendingScript(), m_settings.get(), m_scope.scriptState(), PendingScript::ParsingBlocking);
+ TestScriptResourceClient client;
+ pendingScript().watchForLoad(&client);
+
+ appendData("function foo() { }");
+
+ finish();
+
+ // The finished notification should arrive immediately and not be cycled
+ // through a background thread.
+ EXPECT_TRUE(client.finished());
+
+ bool errorOccurred = false;
+ ScriptSourceCode sourceCode = pendingScript().getSource(KURL(), errorOccurred);
+ EXPECT_FALSE(errorOccurred);
+ EXPECT_FALSE(sourceCode.streamer());
+}
+
+TEST_F(ScriptStreamingTest, ScriptsWithSmallFirstChunk)
+{
+ // If a script is long enough, if should be streamed, even if the first data
+ // chunk is small.
+ ScriptStreamer::setSmallScriptThresholdForTesting(100);
+
+ ScriptStreamer::startStreaming(pendingScript(), m_settings.get(), m_scope.scriptState(), PendingScript::ParsingBlocking);
+ TestScriptResourceClient client;
+ pendingScript().watchForLoad(&client);
+
+ // This is the first data chunk which is small.
+ appendData("function foo() { }");
+ appendPadding();
+ appendPadding();
+ appendPadding();
+
+ finish();
+
+ processTasksUntilStreamingComplete();
+ EXPECT_TRUE(client.finished());
+ bool errorOccurred = false;
+ ScriptSourceCode sourceCode = pendingScript().getSource(KURL(), errorOccurred);
+ EXPECT_FALSE(errorOccurred);
+ EXPECT_TRUE(sourceCode.streamer());
+ v8::TryCatch tryCatch;
+ v8::Handle<v8::Script> script = V8ScriptRunner::compileScript(sourceCode, isolate());
+ EXPECT_FALSE(script.IsEmpty());
+ EXPECT_FALSE(tryCatch.HasCaught());
+}
+
} // namespace
} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698