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

Side by Side Diff: trunk/src/content/renderer/v8_value_converter_impl_unittest.cc

Issue 16511004: Revert 205184 "Revert 204057 "Recurse to a maximum depth of 10 i..." (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: Created 7 years, 6 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 | Annotate | Revision Log
« no previous file with comments | « trunk/src/content/renderer/v8_value_converter_impl.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 <cmath> 5 #include <cmath>
6 6
7 #include "base/memory/scoped_ptr.h" 7 #include "base/memory/scoped_ptr.h"
8 #include "base/stl_util.h" 8 #include "base/stl_util.h"
9 #include "base/test/values_test_util.h" 9 #include "base/test/values_test_util.h"
10 #include "base/values.h" 10 #include "base/values.h"
(...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after
440 array->Set(0, v8::String::New("1")); 440 array->Set(0, v8::String::New("1"));
441 array->Set(1, array); 441 array->Set(1, array);
442 442
443 scoped_ptr<base::ListValue> list_result( 443 scoped_ptr<base::ListValue> list_result(
444 static_cast<base::ListValue*>(converter.FromV8Value(array, context_))); 444 static_cast<base::ListValue*>(converter.FromV8Value(array, context_)));
445 ASSERT_TRUE(list_result.get()); 445 ASSERT_TRUE(list_result.get());
446 EXPECT_EQ(2u, list_result->GetSize()); 446 EXPECT_EQ(2u, list_result->GetSize());
447 EXPECT_TRUE(IsNull(list_result.get(), 1)); 447 EXPECT_TRUE(IsNull(list_result.get(), 1));
448 } 448 }
449 449
450 // Do not try and convert any named callbacks including getters.
451 TEST_F(V8ValueConverterImplTest, ObjectGetters) {
452 v8::Context::Scope context_scope(context_);
453 v8::HandleScope handle_scope;
454
455 const char* source = "(function() {"
456 "var a = {};"
457 "a.__defineGetter__('foo', function() { return 'bar'; });"
458 "return a;"
459 "})();";
460
461 v8::Handle<v8::Script> script(v8::Script::New(v8::String::New(source)));
462 v8::Handle<v8::Object> object = script->Run().As<v8::Object>();
463 ASSERT_FALSE(object.IsEmpty());
464
465 V8ValueConverterImpl converter;
466 scoped_ptr<base::DictionaryValue> result(
467 static_cast<base::DictionaryValue*>(
468 converter.FromV8Value(object, context_)));
469 ASSERT_TRUE(result.get());
470 EXPECT_EQ(0u, result->size());
471 }
472
473 // Do not try and convert any named callbacks including getters.
474 TEST_F(V8ValueConverterImplTest, ObjectWithInternalFieldsGetters) {
475 v8::Context::Scope context_scope(context_);
476 v8::HandleScope handle_scope;
477
478 v8::Handle<v8::ObjectTemplate> object_template = v8::ObjectTemplate::New();
479 object_template->SetInternalFieldCount(1);
480 object_template->SetAccessor(v8::String::New("foo"), NamedCallbackGetter);
481 v8::Handle<v8::Object> object = object_template->NewInstance();
482 ASSERT_FALSE(object.IsEmpty());
483 object->Set(v8::String::New("a"), v8::String::New("b"));
484
485 V8ValueConverterImpl converter;
486 scoped_ptr<base::DictionaryValue> result(
487 static_cast<base::DictionaryValue*>(
488 converter.FromV8Value(object, context_)));
489 ASSERT_TRUE(result.get());
490 EXPECT_EQ(1u, result->size());
491 }
492
493 TEST_F(V8ValueConverterImplTest, WeirdProperties) { 450 TEST_F(V8ValueConverterImplTest, WeirdProperties) {
494 v8::Context::Scope context_scope(context_); 451 v8::Context::Scope context_scope(context_);
495 v8::HandleScope handle_scope; 452 v8::HandleScope handle_scope;
496 453
497 const char* source = "(function() {" 454 const char* source = "(function() {"
498 "return {" 455 "return {"
499 "1: 'foo'," 456 "1: 'foo',"
500 "'2': 'bar'," 457 "'2': 'bar',"
501 "true: 'baz'," 458 "true: 'baz',"
502 "false: 'qux'," 459 "false: 'qux',"
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
643 expected_dictionary.Set(key, base::Value::CreateNullValue()); 600 expected_dictionary.Set(key, base::Value::CreateNullValue());
644 601
645 // The actual result. 602 // The actual result.
646 scoped_ptr<base::Value> actual_dictionary( 603 scoped_ptr<base::Value> actual_dictionary(
647 converter.FromV8Value(recursive_object, context_)); 604 converter.FromV8Value(recursive_object, context_));
648 ASSERT_TRUE(actual_dictionary.get()); 605 ASSERT_TRUE(actual_dictionary.get());
649 606
650 EXPECT_TRUE(expected_dictionary.Equals(actual_dictionary.get())); 607 EXPECT_TRUE(expected_dictionary.Equals(actual_dictionary.get()));
651 } 608 }
652 609
610 TEST_F(V8ValueConverterImplTest, MaxRecursionDepth) {
611 v8::Context::Scope context_scope(context_);
612 v8::HandleScope handle_scope;
613
614 // Must larger than kMaxRecursionDepth in v8_value_converter_impl.cc.
615 int kDepth = 100;
616 const char kKey[] = "key";
617
618 v8::Local<v8::Object> deep_object = v8::Object::New();
619
620 v8::Local<v8::Object> leaf = deep_object;
621 for (int i = 0; i < kDepth; ++i) {
622 v8::Local<v8::Object> new_object = v8::Object::New();
623 leaf->Set(v8::String::New(kKey), new_object);
624 leaf = new_object;
625 }
626
627 V8ValueConverterImpl converter;
628 scoped_ptr<base::Value> value(converter.FromV8Value(deep_object, context_));
629 ASSERT_TRUE(value);
630
631 // Expected depth is kMaxRecursionDepth in v8_value_converter_impl.cc.
632 int kExpectedDepth = 10;
633
634 base::Value* current = value.get();
635 for (int i = 1; i < kExpectedDepth; ++i) {
636 base::DictionaryValue* current_as_object = NULL;
637 ASSERT_TRUE(current->GetAsDictionary(&current_as_object)) << i;
638 ASSERT_TRUE(current_as_object->Get(kKey, &current)) << i;
639 }
640
641 // The leaf node shouldn't have any properties.
642 base::DictionaryValue empty;
643 EXPECT_TRUE(Value::Equals(&empty, current)) << *current;
644 }
645
653 } // namespace content 646 } // namespace content
OLDNEW
« no previous file with comments | « trunk/src/content/renderer/v8_value_converter_impl.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698