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

Unified Diff: Source/bindings/core/v8/ScriptStreamerTest.cpp

Issue 708093002: Script streaming: remove byte order marks, detect encoding based on them. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: fix: don't persist cached data produced by streaming Created 6 years, 1 month 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
« no previous file with comments | « Source/bindings/core/v8/ScriptStreamer.cpp ('k') | Source/bindings/core/v8/V8ScriptRunner.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/bindings/core/v8/ScriptStreamerTest.cpp
diff --git a/Source/bindings/core/v8/ScriptStreamerTest.cpp b/Source/bindings/core/v8/ScriptStreamerTest.cpp
index 90a00444a712b816e33efb9bc801ad1ad52c45b4..f3ae67a46ed29ff480a80cd1c140d832be797b7f 100644
--- a/Source/bindings/core/v8/ScriptStreamerTest.cpp
+++ b/Source/bindings/core/v8/ScriptStreamerTest.cpp
@@ -86,11 +86,11 @@ protected:
void appendData(const char* data)
{
m_resource->appendData(data, strlen(data));
- // Yield control to the background thread, so that V8 gets a change to
+ // Yield control to the background thread, so that V8 gets a chance to
// process the data before the main thread adds more. Note that we
// cannot fully control in what kind of chunks the data is passed to V8
- // (if the V8 is not requesting more data between two appendData calls,
- // V8 will get both chunks together).
+ // (if V8 is not requesting more data between two appendData calls, it
+ // will get both chunks together).
Platform::current()->yieldCurrentThread();
}
@@ -364,6 +364,34 @@ TEST_P(ScriptStreamingTest, EncodingChanges)
EXPECT_FALSE(tryCatch.HasCaught());
}
+
+TEST_P(ScriptStreamingTest, EncodingFromBOM)
+{
+ // Byte order marks should be removed before giving the data to V8. They
+ // will also affect encoding detection.
+ m_resource->setEncoding("windows-1252"); // This encoding is wrong on purpose.
+
+ ScriptStreamer::startStreaming(pendingScript(), m_settings.get(), m_scope.scriptState(), PendingScript::ParsingBlocking);
+ TestScriptResourceClient client;
+ pendingScript().watchForLoad(&client);
+
+ // \xef\xbb\xbf is the UTF-8 byte order mark. \xec\x92\x81 are the raw bytes
+ // for \uc481.
+ appendData("\xef\xbb\xbf function foo() { var foob\xec\x92\x81r = 13; return foob\xec\x92\x81r; } foo();");
+
+ 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());
+}
+
INSTANTIATE_TEST_CASE_P(ScriptStreamingInstantiation, ScriptStreamingTest, ::testing::Values(false, true));
} // namespace
« no previous file with comments | « Source/bindings/core/v8/ScriptStreamer.cpp ('k') | Source/bindings/core/v8/V8ScriptRunner.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698