Commit e303b7d8 authored by Daniel Bratell's avatar Daniel Bratell Committed by Commit Bot

Deduplicate some testing helper functions in v8 bindings test.

V8ScriptValueSerializerTest and V8ScriptValueSerializerTestForModules
had a few methods in common. This patch makes those methods be
shared, or in the case or non-identical methods, renamed to not collide
in jumbo builds.

Bug: 745732
Change-Id: Ia51d9f8dba1910902465dc4cffc193031b47ee3f
Reviewed-on: https://chromium-review.googlesource.com/677446Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Commit-Queue: Daniel Bratell <bratell@opera.com>
Cr-Commit-Position: refs/heads/master@{#504379}
parent 2f37bb9a
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
#include "bindings/core/v8/V8StringResource.h" #include "bindings/core/v8/V8StringResource.h"
#include "bindings/core/v8/serialization/UnpackedSerializedScriptValue.h" #include "bindings/core/v8/serialization/UnpackedSerializedScriptValue.h"
#include "bindings/core/v8/serialization/V8ScriptValueDeserializer.h" #include "bindings/core/v8/serialization/V8ScriptValueDeserializer.h"
#include "bindings/core/v8/serialization/V8ScriptValueSerializerTest.h"
#include "build/build_config.h" #include "build/build_config.h"
#include "core/dom/MessagePort.h" #include "core/dom/MessagePort.h"
#include "core/fileapi/Blob.h" #include "core/fileapi/Blob.h"
...@@ -58,14 +59,6 @@ ...@@ -58,14 +59,6 @@
namespace blink { namespace blink {
namespace { namespace {
RefPtr<SerializedScriptValue> SerializedValue(const Vector<uint8_t>& bytes) {
// TODO(jbroman): Fix this once SerializedScriptValue can take bytes without
// endianness swapping.
DCHECK_EQ(bytes.size() % 2, 0u);
return SerializedScriptValue::Create(
String(reinterpret_cast<const UChar*>(&bytes[0]), bytes.size() / 2));
}
v8::Local<v8::Value> RoundTrip( v8::Local<v8::Value> RoundTrip(
v8::Local<v8::Value> value, v8::Local<v8::Value> value,
V8TestingScope& scope, V8TestingScope& scope,
...@@ -121,6 +114,15 @@ String ToJSON(v8::Local<v8::Object> object, const V8TestingScope& scope) { ...@@ -121,6 +114,15 @@ String ToJSON(v8::Local<v8::Object> object, const V8TestingScope& scope) {
v8::JSON::Stringify(scope.GetContext(), object).ToLocalChecked(), v8::JSON::Stringify(scope.GetContext(), object).ToLocalChecked(),
kDoNotExternalize); kDoNotExternalize);
} }
} // namespace
RefPtr<SerializedScriptValue> SerializedValue(const Vector<uint8_t>& bytes) {
// TODO(jbroman): Fix this once SerializedScriptValue can take bytes without
// endianness swapping.
DCHECK_EQ(bytes.size() % 2, 0u);
return SerializedScriptValue::Create(
String(reinterpret_cast<const UChar*>(&bytes[0]), bytes.size() / 2));
}
// Checks for a DOM exception, including a rethrown one. // Checks for a DOM exception, including a rethrown one.
::testing::AssertionResult HadDOMException(const StringView& name, ::testing::AssertionResult HadDOMException(const StringView& name,
...@@ -138,6 +140,8 @@ String ToJSON(v8::Local<v8::Object> object, const V8TestingScope& scope) { ...@@ -138,6 +140,8 @@ String ToJSON(v8::Local<v8::Object> object, const V8TestingScope& scope) {
return ::testing::AssertionSuccess(); return ::testing::AssertionSuccess();
} }
namespace {
TEST(V8ScriptValueSerializerTest, RoundTripJSONLikeValue) { TEST(V8ScriptValueSerializerTest, RoundTripJSONLikeValue) {
// Ensure that simple JavaScript objects work. // Ensure that simple JavaScript objects work.
// There are more exhaustive tests of JavaScript objects in V8. // There are more exhaustive tests of JavaScript objects in V8.
......
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef V8ScriptValueSerializerTest_h
#define V8ScriptValueSerializerTest_h
#include "bindings/core/v8/ExceptionState.h"
#include "platform/bindings/ScriptState.h"
#include "platform/wtf/RefPtr.h"
#include "platform/wtf/Vector.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace blink {
RefPtr<SerializedScriptValue> SerializedValue(const Vector<uint8_t>& bytes);
// Checks for a DOM exception, including a rethrown one.
::testing::AssertionResult HadDOMException(const StringView& name,
ScriptState* script_state,
ExceptionState& exception_state);
} // namespace blink
#endif // V8ScriptValueSerializerTest_h
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include "bindings/core/v8/V8ArrayBuffer.h" #include "bindings/core/v8/V8ArrayBuffer.h"
#include "bindings/core/v8/V8BindingForTesting.h" #include "bindings/core/v8/V8BindingForTesting.h"
#include "bindings/core/v8/V8DOMException.h" #include "bindings/core/v8/V8DOMException.h"
#include "bindings/core/v8/serialization/V8ScriptValueSerializerTest.h"
#include "bindings/modules/v8/V8CryptoKey.h" #include "bindings/modules/v8/V8CryptoKey.h"
#include "bindings/modules/v8/V8DOMFileSystem.h" #include "bindings/modules/v8/V8DOMFileSystem.h"
#include "bindings/modules/v8/V8RTCCertificate.h" #include "bindings/modules/v8/V8RTCCertificate.h"
...@@ -31,15 +32,7 @@ using ::testing::UnorderedElementsAre; ...@@ -31,15 +32,7 @@ using ::testing::UnorderedElementsAre;
namespace blink { namespace blink {
namespace { namespace {
RefPtr<SerializedScriptValue> SerializedValue(const Vector<uint8_t>& bytes) { v8::Local<v8::Value> RoundTripForModules(v8::Local<v8::Value> value,
// TODO(jbroman): Fix this once SerializedScriptValue can take bytes without
// endianness swapping.
DCHECK_EQ(bytes.size() % 2, 0u);
return SerializedScriptValue::Create(
String(reinterpret_cast<const UChar*>(&bytes[0]), bytes.size() / 2));
}
v8::Local<v8::Value> RoundTrip(v8::Local<v8::Value> value,
V8TestingScope& scope) { V8TestingScope& scope) {
RefPtr<ScriptState> script_state = scope.GetScriptState(); RefPtr<ScriptState> script_state = scope.GetScriptState();
ExceptionState& exception_state = scope.GetExceptionState(); ExceptionState& exception_state = scope.GetExceptionState();
...@@ -56,23 +49,6 @@ v8::Local<v8::Value> RoundTrip(v8::Local<v8::Value> value, ...@@ -56,23 +49,6 @@ v8::Local<v8::Value> RoundTrip(v8::Local<v8::Value> value,
.Deserialize(); .Deserialize();
} }
// Checks for a DOM exception, including a rethrown one.
::testing::AssertionResult HadDOMException(const StringView& name,
ScriptState* script_state,
ExceptionState& exception_state) {
if (!exception_state.HadException())
return ::testing::AssertionFailure() << "no exception thrown";
DOMException* dom_exception = V8DOMException::ToImplWithTypeCheck(
script_state->GetIsolate(), exception_state.GetException());
if (!dom_exception) {
return ::testing::AssertionFailure()
<< "exception thrown was not a DOMException";
}
if (dom_exception->name() != name)
return ::testing::AssertionFailure() << "was " << dom_exception->name();
return ::testing::AssertionSuccess();
}
static const char kEcdsaPrivateKey[] = static const char kEcdsaPrivateKey[] =
"-----BEGIN PRIVATE KEY-----\n" "-----BEGIN PRIVATE KEY-----\n"
"MIGHAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBG0wawIBAQQghHwQ1xYtCoEhFk7r\n" "MIGHAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBG0wawIBAQQghHwQ1xYtCoEhFk7r\n"
...@@ -166,7 +142,7 @@ TEST(V8ScriptValueSerializerForModulesTest, RoundTripRTCCertificate) { ...@@ -166,7 +142,7 @@ TEST(V8ScriptValueSerializerForModulesTest, RoundTripRTCCertificate) {
// Round trip test. // Round trip test.
v8::Local<v8::Value> wrapper = v8::Local<v8::Value> wrapper =
ToV8(certificate, scope.GetContext()->Global(), scope.GetIsolate()); ToV8(certificate, scope.GetContext()->Global(), scope.GetIsolate());
v8::Local<v8::Value> result = RoundTrip(wrapper, scope); v8::Local<v8::Value> result = RoundTripForModules(wrapper, scope);
ASSERT_TRUE(V8RTCCertificate::hasInstance(result, scope.GetIsolate())); ASSERT_TRUE(V8RTCCertificate::hasInstance(result, scope.GetIsolate()));
RTCCertificate* new_certificate = RTCCertificate* new_certificate =
V8RTCCertificate::ToImpl(result.As<v8::Object>()); V8RTCCertificate::ToImpl(result.As<v8::Object>());
...@@ -394,7 +370,7 @@ TEST(V8ScriptValueSerializerForModulesTest, RoundTripCryptoKeyAES) { ...@@ -394,7 +370,7 @@ TEST(V8ScriptValueSerializerForModulesTest, RoundTripCryptoKeyAES) {
// Round trip it and check the visible attributes. // Round trip it and check the visible attributes.
v8::Local<v8::Value> wrapper = ToV8(key, scope.GetScriptState()); v8::Local<v8::Value> wrapper = ToV8(key, scope.GetScriptState());
v8::Local<v8::Value> result = RoundTrip(wrapper, scope); v8::Local<v8::Value> result = RoundTripForModules(wrapper, scope);
ASSERT_TRUE(V8CryptoKey::hasInstance(result, scope.GetIsolate())); ASSERT_TRUE(V8CryptoKey::hasInstance(result, scope.GetIsolate()));
CryptoKey* new_key = V8CryptoKey::ToImpl(result.As<v8::Object>()); CryptoKey* new_key = V8CryptoKey::ToImpl(result.As<v8::Object>());
EXPECT_EQ("secret", new_key->type()); EXPECT_EQ("secret", new_key->type());
...@@ -466,7 +442,7 @@ TEST(V8ScriptValueSerializerForModulesTest, RoundTripCryptoKeyHMAC) { ...@@ -466,7 +442,7 @@ TEST(V8ScriptValueSerializerForModulesTest, RoundTripCryptoKeyHMAC) {
// Round trip it and check the visible attributes. // Round trip it and check the visible attributes.
v8::Local<v8::Value> wrapper = ToV8(key, scope.GetScriptState()); v8::Local<v8::Value> wrapper = ToV8(key, scope.GetScriptState());
v8::Local<v8::Value> result = RoundTrip(wrapper, scope); v8::Local<v8::Value> result = RoundTripForModules(wrapper, scope);
ASSERT_TRUE(V8CryptoKey::hasInstance(result, scope.GetIsolate())); ASSERT_TRUE(V8CryptoKey::hasInstance(result, scope.GetIsolate()));
CryptoKey* new_key = V8CryptoKey::ToImpl(result.As<v8::Object>()); CryptoKey* new_key = V8CryptoKey::ToImpl(result.As<v8::Object>());
EXPECT_EQ("secret", new_key->type()); EXPECT_EQ("secret", new_key->type());
...@@ -541,7 +517,7 @@ TEST(V8ScriptValueSerializerForModulesTest, RoundTripCryptoKeyRSAHashed) { ...@@ -541,7 +517,7 @@ TEST(V8ScriptValueSerializerForModulesTest, RoundTripCryptoKeyRSAHashed) {
// Round trip the private key and check the visible attributes. // Round trip the private key and check the visible attributes.
v8::Local<v8::Value> wrapper = ToV8(private_key, scope.GetScriptState()); v8::Local<v8::Value> wrapper = ToV8(private_key, scope.GetScriptState());
v8::Local<v8::Value> result = RoundTrip(wrapper, scope); v8::Local<v8::Value> result = RoundTripForModules(wrapper, scope);
ASSERT_TRUE(V8CryptoKey::hasInstance(result, scope.GetIsolate())); ASSERT_TRUE(V8CryptoKey::hasInstance(result, scope.GetIsolate()));
CryptoKey* new_private_key = V8CryptoKey::ToImpl(result.As<v8::Object>()); CryptoKey* new_private_key = V8CryptoKey::ToImpl(result.As<v8::Object>());
EXPECT_EQ("private", new_private_key->type()); EXPECT_EQ("private", new_private_key->type());
...@@ -632,7 +608,7 @@ TEST(V8ScriptValueSerializerForModulesTest, RoundTripCryptoKeyEC) { ...@@ -632,7 +608,7 @@ TEST(V8ScriptValueSerializerForModulesTest, RoundTripCryptoKeyEC) {
// Round trip the private key and check the visible attributes. // Round trip the private key and check the visible attributes.
v8::Local<v8::Value> wrapper = ToV8(private_key, scope.GetScriptState()); v8::Local<v8::Value> wrapper = ToV8(private_key, scope.GetScriptState());
v8::Local<v8::Value> result = RoundTrip(wrapper, scope); v8::Local<v8::Value> result = RoundTripForModules(wrapper, scope);
ASSERT_TRUE(V8CryptoKey::hasInstance(result, scope.GetIsolate())); ASSERT_TRUE(V8CryptoKey::hasInstance(result, scope.GetIsolate()));
CryptoKey* new_private_key = V8CryptoKey::ToImpl(result.As<v8::Object>()); CryptoKey* new_private_key = V8CryptoKey::ToImpl(result.As<v8::Object>());
EXPECT_EQ("private", new_private_key->type()); EXPECT_EQ("private", new_private_key->type());
...@@ -708,7 +684,7 @@ TEST(V8ScriptValueSerializerForModulesTest, RoundTripCryptoKeyNoParams) { ...@@ -708,7 +684,7 @@ TEST(V8ScriptValueSerializerForModulesTest, RoundTripCryptoKeyNoParams) {
// Round trip the key and check the visible attributes. // Round trip the key and check the visible attributes.
v8::Local<v8::Value> wrapper = ToV8(key, scope.GetScriptState()); v8::Local<v8::Value> wrapper = ToV8(key, scope.GetScriptState());
v8::Local<v8::Value> result = RoundTrip(wrapper, scope); v8::Local<v8::Value> result = RoundTripForModules(wrapper, scope);
ASSERT_TRUE(V8CryptoKey::hasInstance(result, scope.GetIsolate())); ASSERT_TRUE(V8CryptoKey::hasInstance(result, scope.GetIsolate()));
CryptoKey* new_key = V8CryptoKey::ToImpl(result.As<v8::Object>()); CryptoKey* new_key = V8CryptoKey::ToImpl(result.As<v8::Object>());
EXPECT_EQ("secret", new_key->type()); EXPECT_EQ("secret", new_key->type());
...@@ -870,7 +846,7 @@ TEST(V8ScriptValueSerializerForModulesTest, RoundTripDOMFileSystem) { ...@@ -870,7 +846,7 @@ TEST(V8ScriptValueSerializerForModulesTest, RoundTripDOMFileSystem) {
// At time of writing, this can only happen for filesystems from PPAPI. // At time of writing, this can only happen for filesystems from PPAPI.
fs->MakeClonable(); fs->MakeClonable();
v8::Local<v8::Value> wrapper = ToV8(fs, scope.GetScriptState()); v8::Local<v8::Value> wrapper = ToV8(fs, scope.GetScriptState());
v8::Local<v8::Value> result = RoundTrip(wrapper, scope); v8::Local<v8::Value> result = RoundTripForModules(wrapper, scope);
ASSERT_FALSE(result.IsEmpty()); ASSERT_FALSE(result.IsEmpty());
ASSERT_TRUE(V8DOMFileSystem::hasInstance(result, scope.GetIsolate())); ASSERT_TRUE(V8DOMFileSystem::hasInstance(result, scope.GetIsolate()));
DOMFileSystem* new_fs = V8DOMFileSystem::ToImpl(result.As<v8::Object>()); DOMFileSystem* new_fs = V8DOMFileSystem::ToImpl(result.As<v8::Object>());
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment