| Index: webkit/plugins/ppapi/v8_var_converter_unittest.cc
|
| diff --git a/webkit/plugins/ppapi/v8_var_converter_unittest.cc b/webkit/plugins/ppapi/v8_var_converter_unittest.cc
|
| index a21634825a71faf89b048df94024ff3a4d66f03c..01b2578a8aca7987512b02644a52cb97a0bd7c8c 100644
|
| --- a/webkit/plugins/ppapi/v8_var_converter_unittest.cc
|
| +++ b/webkit/plugins/ppapi/v8_var_converter_unittest.cc
|
| @@ -154,15 +154,14 @@ class V8VarConverterTest : public testing::Test {
|
|
|
| protected:
|
| bool RoundTrip(const PP_Var& var, PP_Var* result) {
|
| - V8VarConverter converter;
|
| v8::Context::Scope context_scope(context_);
|
| v8::HandleScope handle_scope;
|
| v8::Handle<v8::Value> v8_result;
|
| - if (!converter.ToV8Value(var, context_, &v8_result))
|
| + if (!V8VarConverter::ToV8Value(var, context_, &v8_result))
|
| return false;
|
| if (!Equals(var, v8_result))
|
| return false;
|
| - if (!converter.FromV8Value(v8_result, context_, result))
|
| + if (!V8VarConverter::FromV8Value(v8_result, context_, result))
|
| return false;
|
| return true;
|
| }
|
| @@ -269,29 +268,61 @@ TEST_F(V8VarConverterTest, DictionaryArrayRoundTripTest) {
|
| array2->Set(0, PP_MakeInt32(100));
|
| dictionary->SetWithStringKey("9", release_array2.get());
|
| EXPECT_TRUE(RoundTripAndCompare(array->GetPPVar()));
|
| +}
|
| +
|
| +TEST_F(V8VarConverterTest, Cycles) {
|
| + // Check that cycles aren't converted.
|
| + v8::Context::Scope context_scope(context_);
|
| + v8::HandleScope handle_scope;
|
| +
|
| + // Var->V8 conversion.
|
| + {
|
| + scoped_refptr<DictionaryVar> dictionary(new DictionaryVar);
|
| + ScopedPPVar release_dictionary(ScopedPPVar::PassRef(),
|
| + dictionary->GetPPVar());
|
| + scoped_refptr<ArrayVar> array(new ArrayVar);
|
| + ScopedPPVar release_array(ScopedPPVar::PassRef(), array->GetPPVar());
|
| +
|
| + dictionary->SetWithStringKey("1", release_array.get());
|
| + array->Set(0, release_dictionary.get());
|
| +
|
| + v8::Handle<v8::Value> v8_result;
|
|
|
| - // Array <-> dictionary cycle.
|
| - dictionary->SetWithStringKey("10", release_array.get());
|
| - PP_Var result_var;
|
| - EXPECT_TRUE(RoundTrip(release_dictionary.get(), &result_var));
|
| - ScopedPPVar result = ScopedPPVar(ScopedPPVar::PassRef(), result_var);
|
| - EXPECT_TRUE(TestEqual(release_dictionary.get(), result.get()));
|
| - // Break the cycle.
|
| - // TODO(raymes): We need some better machinery for releasing vars with
|
| - // cycles. Remove the code below once we have that.
|
| - dictionary->DeleteWithStringKey("10");
|
| - DictionaryVar* result_dictionary = DictionaryVar::FromPPVar(result.get());
|
| - result_dictionary->DeleteWithStringKey("10");
|
| -
|
| - // Array with self references.
|
| - array->Set(index, release_array.get());
|
| - EXPECT_TRUE(RoundTrip(release_array.get(), &result_var));
|
| - result = ScopedPPVar(ScopedPPVar::PassRef(), result_var);
|
| - EXPECT_TRUE(TestEqual(release_array.get(), result.get()));
|
| - // Break the self reference.
|
| - array->Set(index, PP_MakeUndefined());
|
| - ArrayVar* result_array = ArrayVar::FromPPVar(result.get());
|
| - result_array->Set(index, PP_MakeUndefined());
|
| + // Array <-> dictionary cycle.
|
| + dictionary->SetWithStringKey("1", release_array.get());
|
| + ASSERT_FALSE(V8VarConverter::ToV8Value(release_dictionary.get(),
|
| + context_, &v8_result));
|
| + // Break the cycle.
|
| + // TODO(raymes): We need some better machinery for releasing vars with
|
| + // cycles. Remove the code below once we have that.
|
| + dictionary->DeleteWithStringKey("1");
|
| +
|
| + // Array with self reference.
|
| + array->Set(0, release_array.get());
|
| + ASSERT_FALSE(V8VarConverter::ToV8Value(release_array.get(),
|
| + context_, &v8_result));
|
| + // Break the self reference.
|
| + array->Set(0, PP_MakeUndefined());
|
| + }
|
| +
|
| + // V8->Var conversion.
|
| + {
|
| + v8::Handle<v8::Object> object = v8::Object::New();
|
| + v8::Handle<v8::Array> array = v8::Array::New();
|
| +
|
| + PP_Var var_result;
|
| +
|
| + // Array <-> dictionary cycle.
|
| + std::string key = "1";
|
| + object->Set(v8::String::New(key.c_str(), key.length()), array);
|
| + array->Set(0, object);
|
| +
|
| + ASSERT_FALSE(V8VarConverter::FromV8Value(object, context_, &var_result));
|
| +
|
| + // Array with self reference.
|
| + array->Set(0, array);
|
| + ASSERT_FALSE(V8VarConverter::FromV8Value(array, context_, &var_result));
|
| + }
|
| }
|
|
|
| TEST_F(V8VarConverterTest, StrangeDictionaryKeyTest) {
|
| @@ -323,9 +354,8 @@ TEST_F(V8VarConverterTest, StrangeDictionaryKeyTest) {
|
| v8::Handle<v8::Object> object = script->Run().As<v8::Object>();
|
| ASSERT_FALSE(object.IsEmpty());
|
|
|
| - V8VarConverter converter;
|
| PP_Var actual;
|
| - ASSERT_TRUE(converter.FromV8Value(object, context_, &actual));
|
| + ASSERT_TRUE(V8VarConverter::FromV8Value(object, context_, &actual));
|
| ScopedPPVar release_actual(ScopedPPVar::PassRef(), actual);
|
|
|
| scoped_refptr<DictionaryVar> expected(new DictionaryVar);
|
|
|