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

Side by Side Diff: third_party/WebKit/Source/bindings/core/v8/ToV8Test.cpp

Issue 1773813007: blink: Rename modules/ method to prefix with get when they collide. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: clash-modules: rebase-fixes Created 4 years, 9 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 #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 "core/testing/RefCountedScriptWrappable.h" 10 #include "core/testing/RefCountedScriptWrappable.h"
11 #include "platform/heap/Heap.h" 11 #include "platform/heap/Heap.h"
12 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.h"
13 #include "wtf/Vector.h" 13 #include "wtf/Vector.h"
14 #include <limits> 14 #include <limits>
15 15
16 #define TEST_TOV8(expected, value) testToV8(expected, value, __FILE__, __LINE__) 16 #define TEST_TOV8(expected, value) testToV8(expected, value, __FILE__, __LINE__)
17 17
18 namespace blink { 18 namespace blink {
19 19
20 namespace { 20 namespace {
21 21
22 class ToV8Test : public ::testing::Test { 22 class ToV8Test : public ::testing::Test {
23 public: 23 public:
24 ToV8Test() : m_scope(v8::Isolate::GetCurrent()) { } 24 ToV8Test() : m_scope(v8::Isolate::GetCurrent()) { }
25 25
26 template<typename T> 26 template<typename T>
27 void testToV8(const char* expected, T value, const char* path, int lineNumbe r) 27 void testToV8(const char* expected, T value, const char* path, int lineNumbe r)
28 { 28 {
29 v8::Local<v8::Value> actual = toV8(value, m_scope.scriptState()->context ()->Global(), m_scope.isolate()); 29 v8::Local<v8::Value> actual = toV8(value, m_scope.getScriptState()->cont ext()->Global(), m_scope.isolate());
30 if (actual.IsEmpty()) { 30 if (actual.IsEmpty()) {
31 ADD_FAILURE_AT(path, lineNumber) << "toV8 returns an empty value."; 31 ADD_FAILURE_AT(path, lineNumber) << "toV8 returns an empty value.";
32 return; 32 return;
33 } 33 }
34 String actualString = toCoreString(actual->ToString(m_scope.context()).T oLocalChecked()); 34 String actualString = toCoreString(actual->ToString(m_scope.context()).T oLocalChecked());
35 if (String(expected) != actualString) { 35 if (String(expected) != actualString) {
36 ADD_FAILURE_AT(path, lineNumber) << "toV8 returns an incorrect value .\n Actual: " << actualString.utf8().data() << "\nExpected: " << expected; 36 ADD_FAILURE_AT(path, lineNumber) << "toV8 returns an incorrect value .\n Actual: " << actualString.utf8().data() << "\nExpected: " << expected;
37 return; 37 return;
38 } 38 }
39 } 39 }
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 TEST_TOV8("5678", handleValue); 154 TEST_TOV8("5678", handleValue);
155 } 155 }
156 156
157 TEST_F(ToV8Test, undefinedType) 157 TEST_F(ToV8Test, undefinedType)
158 { 158 {
159 TEST_TOV8("undefined", ToV8UndefinedGenerator()); 159 TEST_TOV8("undefined", ToV8UndefinedGenerator());
160 } 160 }
161 161
162 TEST_F(ToV8Test, scriptValue) 162 TEST_F(ToV8Test, scriptValue)
163 { 163 {
164 ScriptValue value(m_scope.scriptState(), v8::Number::New(m_scope.isolate(), 1234)); 164 ScriptValue value(m_scope.getScriptState(), v8::Number::New(m_scope.isolate( ), 1234));
165 165
166 TEST_TOV8("1234", value); 166 TEST_TOV8("1234", value);
167 } 167 }
168 168
169 TEST_F(ToV8Test, vector) 169 TEST_F(ToV8Test, vector)
170 { 170 {
171 Vector<RefPtr<RefCountedScriptWrappable>> v; 171 Vector<RefPtr<RefCountedScriptWrappable>> v;
172 v.append(RefCountedScriptWrappable::create("foo")); 172 v.append(RefCountedScriptWrappable::create("foo"));
173 v.append(RefCountedScriptWrappable::create("bar")); 173 v.append(RefCountedScriptWrappable::create("bar"));
174 174
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
226 boolVector.append(false); 226 boolVector.append(false);
227 TEST_TOV8("true,true,false", boolVector); 227 TEST_TOV8("true,true,false", boolVector);
228 } 228 }
229 229
230 TEST_F(ToV8Test, dictionaryVector) 230 TEST_F(ToV8Test, dictionaryVector)
231 { 231 {
232 Vector<std::pair<String, int>> dictionary; 232 Vector<std::pair<String, int>> dictionary;
233 dictionary.append(std::make_pair("one", 1)); 233 dictionary.append(std::make_pair("one", 1));
234 dictionary.append(std::make_pair("two", 2)); 234 dictionary.append(std::make_pair("two", 2));
235 TEST_TOV8("[object Object]", dictionary); 235 TEST_TOV8("[object Object]", dictionary);
236 v8::Local<v8::Context> context = m_scope.scriptState()->context(); 236 v8::Local<v8::Context> context = m_scope.getScriptState()->context();
237 v8::Local<v8::Object> result = toV8(dictionary, context->Global(), m_scope.i solate())->ToObject(context).ToLocalChecked(); 237 v8::Local<v8::Object> result = toV8(dictionary, context->Global(), m_scope.i solate())->ToObject(context).ToLocalChecked();
238 v8::Local<v8::Value> one = result->Get(context, v8String(m_scope.isolate(), "one")).ToLocalChecked(); 238 v8::Local<v8::Value> one = result->Get(context, v8String(m_scope.isolate(), "one")).ToLocalChecked();
239 EXPECT_EQ(1, one->NumberValue(context).FromJust()); 239 EXPECT_EQ(1, one->NumberValue(context).FromJust());
240 v8::Local<v8::Value> two = result->Get(context, v8String(m_scope.isolate(), "two")).ToLocalChecked(); 240 v8::Local<v8::Value> two = result->Get(context, v8String(m_scope.isolate(), "two")).ToLocalChecked();
241 EXPECT_EQ(2, two->NumberValue(context).FromJust()); 241 EXPECT_EQ(2, two->NumberValue(context).FromJust());
242 } 242 }
243 243
244 TEST_F(ToV8Test, heapVector) 244 TEST_F(ToV8Test, heapVector)
245 { 245 {
246 HeapVector<Member<GarbageCollectedScriptWrappable>> v; 246 HeapVector<Member<GarbageCollectedScriptWrappable>> v;
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
298 298
299 HeapVector<bool> boolVector; 299 HeapVector<bool> boolVector;
300 boolVector.append(true); 300 boolVector.append(true);
301 boolVector.append(true); 301 boolVector.append(true);
302 boolVector.append(false); 302 boolVector.append(false);
303 TEST_TOV8("true,true,false", boolVector); 303 TEST_TOV8("true,true,false", boolVector);
304 } 304 }
305 305
306 TEST_F(ToV8Test, withScriptState) 306 TEST_F(ToV8Test, withScriptState)
307 { 307 {
308 ScriptValue value(m_scope.scriptState(), v8::Number::New(m_scope.isolate(), 1234.0)); 308 ScriptValue value(m_scope.getScriptState(), v8::Number::New(m_scope.isolate( ), 1234.0));
309 309
310 v8::Local<v8::Value> actual = toV8(value, m_scope.scriptState()); 310 v8::Local<v8::Value> actual = toV8(value, m_scope.getScriptState());
311 EXPECT_FALSE(actual.IsEmpty()); 311 EXPECT_FALSE(actual.IsEmpty());
312 312
313 double actualAsNumber = actual.As<v8::Number>()->Value(); 313 double actualAsNumber = actual.As<v8::Number>()->Value();
314 EXPECT_EQ(1234.0, actualAsNumber); 314 EXPECT_EQ(1234.0, actualAsNumber);
315 } 315 }
316 316
317 } // namespace 317 } // namespace
318 318
319 } // namespace blink 319 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698