| OLD | NEW |
| 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 702 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 713 | 713 |
| 714 class V8ValueConverterOverridingStrategyForTesting | 714 class V8ValueConverterOverridingStrategyForTesting |
| 715 : public V8ValueConverter::Strategy { | 715 : public V8ValueConverter::Strategy { |
| 716 public: | 716 public: |
| 717 V8ValueConverterOverridingStrategyForTesting() | 717 V8ValueConverterOverridingStrategyForTesting() |
| 718 : reference_value_(NewReferenceValue()) {} | 718 : reference_value_(NewReferenceValue()) {} |
| 719 virtual bool FromV8Object( | 719 virtual bool FromV8Object( |
| 720 v8::Handle<v8::Object> value, | 720 v8::Handle<v8::Object> value, |
| 721 base::Value** out, | 721 base::Value** out, |
| 722 v8::Isolate* isolate, | 722 v8::Isolate* isolate, |
| 723 const FromV8ValueCallback& callback) const OVERRIDE { | 723 const FromV8ValueCallback& callback) const override { |
| 724 *out = NewReferenceValue(); | 724 *out = NewReferenceValue(); |
| 725 return true; | 725 return true; |
| 726 } | 726 } |
| 727 virtual bool FromV8Array(v8::Handle<v8::Array> value, | 727 virtual bool FromV8Array(v8::Handle<v8::Array> value, |
| 728 base::Value** out, | 728 base::Value** out, |
| 729 v8::Isolate* isolate, | 729 v8::Isolate* isolate, |
| 730 const FromV8ValueCallback& callback) const OVERRIDE { | 730 const FromV8ValueCallback& callback) const override { |
| 731 *out = NewReferenceValue(); | 731 *out = NewReferenceValue(); |
| 732 return true; | 732 return true; |
| 733 } | 733 } |
| 734 virtual bool FromV8ArrayBuffer(v8::Handle<v8::Object> value, | 734 virtual bool FromV8ArrayBuffer(v8::Handle<v8::Object> value, |
| 735 base::Value** out, | 735 base::Value** out, |
| 736 v8::Isolate* isolate) const OVERRIDE { | 736 v8::Isolate* isolate) const override { |
| 737 *out = NewReferenceValue(); | 737 *out = NewReferenceValue(); |
| 738 return true; | 738 return true; |
| 739 } | 739 } |
| 740 virtual bool FromV8Number(v8::Handle<v8::Number> value, | 740 virtual bool FromV8Number(v8::Handle<v8::Number> value, |
| 741 base::Value** out) const OVERRIDE { | 741 base::Value** out) const override { |
| 742 *out = NewReferenceValue(); | 742 *out = NewReferenceValue(); |
| 743 return true; | 743 return true; |
| 744 } | 744 } |
| 745 virtual bool FromV8Undefined(base::Value** out) const OVERRIDE { | 745 virtual bool FromV8Undefined(base::Value** out) const override { |
| 746 *out = NewReferenceValue(); | 746 *out = NewReferenceValue(); |
| 747 return true; | 747 return true; |
| 748 } | 748 } |
| 749 base::Value* reference_value() const { return reference_value_.get(); } | 749 base::Value* reference_value() const { return reference_value_.get(); } |
| 750 | 750 |
| 751 private: | 751 private: |
| 752 static base::Value* NewReferenceValue() { | 752 static base::Value* NewReferenceValue() { |
| 753 return new base::StringValue("strategy"); | 753 return new base::StringValue("strategy"); |
| 754 } | 754 } |
| 755 scoped_ptr<base::Value> reference_value_; | 755 scoped_ptr<base::Value> reference_value_; |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 806 base::Value::Equals(strategy.reference_value(), undefined_value.get())); | 806 base::Value::Equals(strategy.reference_value(), undefined_value.get())); |
| 807 } | 807 } |
| 808 | 808 |
| 809 class V8ValueConverterBypassStrategyForTesting | 809 class V8ValueConverterBypassStrategyForTesting |
| 810 : public V8ValueConverter::Strategy { | 810 : public V8ValueConverter::Strategy { |
| 811 public: | 811 public: |
| 812 virtual bool FromV8Object( | 812 virtual bool FromV8Object( |
| 813 v8::Handle<v8::Object> value, | 813 v8::Handle<v8::Object> value, |
| 814 base::Value** out, | 814 base::Value** out, |
| 815 v8::Isolate* isolate, | 815 v8::Isolate* isolate, |
| 816 const FromV8ValueCallback& callback) const OVERRIDE { | 816 const FromV8ValueCallback& callback) const override { |
| 817 return false; | 817 return false; |
| 818 } | 818 } |
| 819 virtual bool FromV8Array(v8::Handle<v8::Array> value, | 819 virtual bool FromV8Array(v8::Handle<v8::Array> value, |
| 820 base::Value** out, | 820 base::Value** out, |
| 821 v8::Isolate* isolate, | 821 v8::Isolate* isolate, |
| 822 const FromV8ValueCallback& callback) const OVERRIDE { | 822 const FromV8ValueCallback& callback) const override { |
| 823 return false; | 823 return false; |
| 824 } | 824 } |
| 825 virtual bool FromV8ArrayBuffer(v8::Handle<v8::Object> value, | 825 virtual bool FromV8ArrayBuffer(v8::Handle<v8::Object> value, |
| 826 base::Value** out, | 826 base::Value** out, |
| 827 v8::Isolate* isolate) const OVERRIDE { | 827 v8::Isolate* isolate) const override { |
| 828 return false; | 828 return false; |
| 829 } | 829 } |
| 830 virtual bool FromV8Number(v8::Handle<v8::Number> value, | 830 virtual bool FromV8Number(v8::Handle<v8::Number> value, |
| 831 base::Value** out) const OVERRIDE { | 831 base::Value** out) const override { |
| 832 return false; | 832 return false; |
| 833 } | 833 } |
| 834 virtual bool FromV8Undefined(base::Value** out) const OVERRIDE { | 834 virtual bool FromV8Undefined(base::Value** out) const override { |
| 835 return false; | 835 return false; |
| 836 } | 836 } |
| 837 }; | 837 }; |
| 838 | 838 |
| 839 // Verify that having a strategy that fallbacks to default behaviour | 839 // Verify that having a strategy that fallbacks to default behaviour |
| 840 // actually preserves it. | 840 // actually preserves it. |
| 841 TEST_F(V8ValueConverterImplTest, StrategyBypass) { | 841 TEST_F(V8ValueConverterImplTest, StrategyBypass) { |
| 842 v8::HandleScope handle_scope(isolate_); | 842 v8::HandleScope handle_scope(isolate_); |
| 843 v8::Local<v8::Context> context = | 843 v8::Local<v8::Context> context = |
| 844 v8::Local<v8::Context>::New(isolate_, context_); | 844 v8::Local<v8::Context>::New(isolate_, context_); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 872 EXPECT_TRUE( | 872 EXPECT_TRUE( |
| 873 base::Value::Equals(reference_number_value.get(), number_value.get())); | 873 base::Value::Equals(reference_number_value.get(), number_value.get())); |
| 874 | 874 |
| 875 v8::Handle<v8::Primitive> undefined(v8::Undefined(isolate_)); | 875 v8::Handle<v8::Primitive> undefined(v8::Undefined(isolate_)); |
| 876 scoped_ptr<base::Value> undefined_value( | 876 scoped_ptr<base::Value> undefined_value( |
| 877 converter.FromV8Value(undefined, context)); | 877 converter.FromV8Value(undefined, context)); |
| 878 EXPECT_FALSE(undefined_value); | 878 EXPECT_FALSE(undefined_value); |
| 879 } | 879 } |
| 880 | 880 |
| 881 } // namespace content | 881 } // namespace content |
| OLD | NEW |