| 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..3e5ace9c57862995078b66f604450d88e848b33b 100644
|
| --- a/webkit/plugins/ppapi/v8_var_converter_unittest.cc
|
| +++ b/webkit/plugins/ppapi/v8_var_converter_unittest.cc
|
| @@ -153,8 +153,8 @@ class V8VarConverterTest : public testing::Test {
|
| }
|
|
|
| protected:
|
| - bool RoundTrip(const PP_Var& var, PP_Var* result) {
|
| - V8VarConverter converter;
|
| + bool RoundTrip(const PP_Var& var, PP_Var* result, bool allow_cycles) {
|
| + V8VarConverter converter(allow_cycles);
|
| v8::Context::Scope context_scope(context_);
|
| v8::HandleScope handle_scope;
|
| v8::Handle<v8::Value> v8_result;
|
| @@ -171,7 +171,7 @@ class V8VarConverterTest : public testing::Test {
|
| bool RoundTripAndCompare(const PP_Var& var) {
|
| ScopedPPVar expected(ScopedPPVar::PassRef(), var);
|
| PP_Var actual_var;
|
| - if (!RoundTrip(expected.get(), &actual_var))
|
| + if (!RoundTrip(expected.get(), &actual_var, false))
|
| return false;
|
| ScopedPPVar actual(ScopedPPVar::PassRef(), actual_var);
|
| return TestEqual(expected.get(), actual.get());
|
| @@ -269,29 +269,74 @@ 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) {
|
| + v8::Context::Scope context_scope(context_);
|
| + v8::HandleScope handle_scope;
|
| + 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", PP_MakeUndefined());
|
| + dictionary->SetWithStringKey("2", PP_MakeNull());
|
| + dictionary->SetWithStringKey("3", PP_MakeInt32(-100));
|
| + dictionary->SetWithStringKey("4", PP_MakeBool(PP_TRUE));
|
| + dictionary->SetWithStringKey("5", PP_MakeDouble(-103.52));
|
| + dictionary->SetWithStringKey("6", release_array.get());
|
| +
|
| + array->Set(0, PP_MakeUndefined());
|
| + array->Set(1, PP_MakeNull());
|
| + array->Set(2, PP_MakeInt32(100));
|
| + array->Set(3, PP_MakeBool(PP_FALSE));
|
| + array->Set(4, PP_MakeDouble(0.123));
|
| + array->Set(5, release_dictionary.get());
|
| +
|
| + V8VarConverter converter_with_cycles(true);
|
| + V8VarConverter converter_without_cycles(false);
|
| + PP_Var var_result;
|
| + 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()));
|
| + dictionary->SetWithStringKey("6", release_array.get());
|
| + ASSERT_FALSE(converter_without_cycles.ToV8Value(release_dictionary.get(),
|
| + context_, &v8_result));
|
| + ASSERT_TRUE(converter_with_cycles.ToV8Value(release_dictionary.get(),
|
| + context_, &v8_result));
|
| + ASSERT_TRUE(Equals(release_dictionary.get(), v8_result));
|
| + ASSERT_FALSE(converter_without_cycles.FromV8Value(v8_result,
|
| + context_, &var_result));
|
| + ASSERT_TRUE(converter_with_cycles.FromV8Value(v8_result,
|
| + context_, &var_result));
|
| + ScopedPPVar release_result = ScopedPPVar(ScopedPPVar::PassRef(), var_result);
|
| + EXPECT_TRUE(TestEqual(release_dictionary.get(), release_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");
|
| + dictionary->DeleteWithStringKey("6");
|
| + DictionaryVar* result_dictionary = DictionaryVar::FromPPVar(
|
| + release_result.get());
|
| + result_dictionary->DeleteWithStringKey("6");
|
|
|
| // 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()));
|
| + array->Set(5, release_array.get());
|
| + ASSERT_FALSE(converter_without_cycles.ToV8Value(release_array.get(),
|
| + context_, &v8_result));
|
| + ASSERT_TRUE(converter_with_cycles.ToV8Value(release_array.get(),
|
| + context_, &v8_result));
|
| + ASSERT_TRUE(Equals(release_array.get(), v8_result));
|
| + ASSERT_FALSE(converter_without_cycles.FromV8Value(v8_result,
|
| + context_, &var_result));
|
| + ASSERT_TRUE(converter_with_cycles.FromV8Value(v8_result,
|
| + context_, &var_result));
|
| + release_result = ScopedPPVar(ScopedPPVar::PassRef(), var_result);
|
| + EXPECT_TRUE(TestEqual(release_array.get(), release_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->Set(5, PP_MakeUndefined());
|
| + ArrayVar* result_array = ArrayVar::FromPPVar(release_result.get());
|
| + result_array->Set(5, PP_MakeUndefined());
|
| }
|
|
|
| TEST_F(V8VarConverterTest, StrangeDictionaryKeyTest) {
|
| @@ -323,7 +368,7 @@ TEST_F(V8VarConverterTest, StrangeDictionaryKeyTest) {
|
| v8::Handle<v8::Object> object = script->Run().As<v8::Object>();
|
| ASSERT_FALSE(object.IsEmpty());
|
|
|
| - V8VarConverter converter;
|
| + V8VarConverter converter(false);
|
| PP_Var actual;
|
| ASSERT_TRUE(converter.FromV8Value(object, context_, &actual));
|
| ScopedPPVar release_actual(ScopedPPVar::PassRef(), actual);
|
|
|