| 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 #include "bindings/core/v8/ToV8.h" | 5 #include "bindings/core/v8/ToV8.h" |
| 6 | 6 |
| 7 #include "bindings/core/v8/V8Binding.h" | 7 #include "bindings/core/v8/V8Binding.h" |
| 8 #include "bindings/core/v8/V8BindingForTesting.h" | 8 #include "bindings/core/v8/V8BindingForTesting.h" |
| 9 #include "core/testing/GarbageCollectedScriptWrappable.h" | 9 #include "core/testing/GarbageCollectedScriptWrappable.h" |
| 10 #include "platform/heap/Heap.h" | 10 #include "platform/heap/Heap.h" |
| 11 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
| 12 #include "wtf/Vector.h" | 12 #include "wtf/Vector.h" |
| 13 #include <limits> | 13 #include <limits> |
| 14 | 14 |
| 15 #define TEST_TOV8(expected, value) testToV8(&scope, expected, value, __FILE__, _
_LINE__) | 15 #define TEST_TOV8(expected, value) testToV8(&scope, expected, value, __FILE__, _
_LINE__) |
| 16 | 16 |
| 17 namespace blink { | 17 namespace blink { |
| 18 | 18 |
| 19 namespace { | 19 namespace { |
| 20 | 20 |
| 21 template<typename T> | 21 template<typename T> |
| 22 void testToV8(V8TestingScope* scope, const char* expected, T value, const char*
path, int lineNumber) | 22 void testToV8(V8TestingScope* scope, const char* expected, T value, const char*
path, int lineNumber) |
| 23 { | 23 { |
| 24 v8::Local<v8::Value> actual = toV8(value, scope->context()->Global(), scope-
>isolate()); | 24 v8::Local<v8::Value> actual = toV8(value, scope->context()->Global(), scope-
>isolate()); |
| 25 if (actual.IsEmpty()) { | |
| 26 ADD_FAILURE_AT(path, lineNumber) << "toV8 returns an empty value."; | |
| 27 return; | |
| 28 } | |
| 29 String actualString = toCoreString(actual->ToString(scope->context()).ToLoca
lChecked()); | 25 String actualString = toCoreString(actual->ToString(scope->context()).ToLoca
lChecked()); |
| 30 if (String(expected) != actualString) { | 26 if (String(expected) != actualString) { |
| 31 ADD_FAILURE_AT(path, lineNumber) << "toV8 returns an incorrect value.\n
Actual: " << actualString.utf8().data() << "\nExpected: " << expected; | 27 ADD_FAILURE_AT(path, lineNumber) << "toV8 returns an incorrect value.\n
Actual: " << actualString.utf8().data() << "\nExpected: " << expected; |
| 32 return; | 28 return; |
| 33 } | 29 } |
| 34 } | 30 } |
| 35 | 31 |
| 36 class GarbageCollectedHolder : public GarbageCollected<GarbageCollectedHolder> { | 32 class GarbageCollectedHolder : public GarbageCollected<GarbageCollectedHolder> { |
| 37 public: | 33 public: |
| 38 GarbageCollectedHolder(GarbageCollectedScriptWrappable* scriptWrappable) | 34 GarbageCollectedHolder(GarbageCollectedScriptWrappable* scriptWrappable) |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 227 | 223 |
| 228 TEST_TOV8("hoge,fuga,", v); | 224 TEST_TOV8("hoge,fuga,", v); |
| 229 } | 225 } |
| 230 | 226 |
| 231 TEST(ToV8Test, withScriptState) | 227 TEST(ToV8Test, withScriptState) |
| 232 { | 228 { |
| 233 V8TestingScope scope; | 229 V8TestingScope scope; |
| 234 ScriptValue value(scope.getScriptState(), v8::Number::New(scope.isolate(), 1
234.0)); | 230 ScriptValue value(scope.getScriptState(), v8::Number::New(scope.isolate(), 1
234.0)); |
| 235 | 231 |
| 236 v8::Local<v8::Value> actual = toV8(value, scope.getScriptState()); | 232 v8::Local<v8::Value> actual = toV8(value, scope.getScriptState()); |
| 237 EXPECT_FALSE(actual.IsEmpty()); | |
| 238 | |
| 239 double actualAsNumber = actual.As<v8::Number>()->Value(); | 233 double actualAsNumber = actual.As<v8::Number>()->Value(); |
| 240 EXPECT_EQ(1234.0, actualAsNumber); | 234 EXPECT_EQ(1234.0, actualAsNumber); |
| 241 } | 235 } |
| 242 | 236 |
| 243 } // namespace | 237 } // namespace |
| 244 | 238 |
| 245 } // namespace blink | 239 } // namespace blink |
| OLD | NEW |