OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "base/basictypes.h" |
| 6 #include "base/float_util.h" |
| 7 #include "base/memory/scoped_ptr.h" |
| 8 #include "content/common/android/gin_java_bridge_value.h" |
| 9 #include "content/renderer/java/gin_java_bridge_value_converter.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" |
| 11 #include "v8/include/v8.h" |
| 12 |
| 13 namespace content { |
| 14 |
| 15 class GinJavaBridgeValueConverterTest : public testing::Test { |
| 16 public: |
| 17 GinJavaBridgeValueConverterTest() |
| 18 : isolate_(v8::Isolate::GetCurrent()) { |
| 19 } |
| 20 |
| 21 protected: |
| 22 virtual void SetUp() { |
| 23 v8::HandleScope handle_scope(isolate_); |
| 24 v8::Handle<v8::ObjectTemplate> global = v8::ObjectTemplate::New(isolate_); |
| 25 context_.Reset(isolate_, v8::Context::New(isolate_, NULL, global)); |
| 26 } |
| 27 |
| 28 virtual void TearDown() { |
| 29 context_.Reset(); |
| 30 } |
| 31 |
| 32 v8::Isolate* isolate_; |
| 33 |
| 34 // Context for the JavaScript in the test. |
| 35 v8::Persistent<v8::Context> context_; |
| 36 }; |
| 37 |
| 38 TEST_F(GinJavaBridgeValueConverterTest, BasicValues) { |
| 39 v8::HandleScope handle_scope(isolate_); |
| 40 v8::Local<v8::Context> context = |
| 41 v8::Local<v8::Context>::New(isolate_, context_); |
| 42 v8::Context::Scope context_scope(context); |
| 43 |
| 44 scoped_ptr<GinJavaBridgeValueConverter> converter( |
| 45 new GinJavaBridgeValueConverter()); |
| 46 |
| 47 v8::Handle<v8::Primitive> v8_undefined(v8::Undefined(isolate_)); |
| 48 scoped_ptr<base::Value> undefined( |
| 49 converter->FromV8Value(v8_undefined, context)); |
| 50 ASSERT_TRUE(undefined.get()); |
| 51 EXPECT_TRUE(GinJavaBridgeValue::ContainsGinJavaBridgeValue(undefined.get())); |
| 52 scoped_ptr<const GinJavaBridgeValue> undefined_value( |
| 53 GinJavaBridgeValue::FromValue(undefined.get())); |
| 54 ASSERT_TRUE(undefined_value.get()); |
| 55 EXPECT_TRUE(undefined_value->IsType(GinJavaBridgeValue::TYPE_UNDEFINED)); |
| 56 |
| 57 v8::Handle<v8::Number> v8_infinity( |
| 58 v8::Number::New(isolate_, std::numeric_limits<double>::infinity())); |
| 59 scoped_ptr<base::Value> infinity( |
| 60 converter->FromV8Value(v8_infinity, context)); |
| 61 ASSERT_TRUE(infinity.get()); |
| 62 EXPECT_TRUE( |
| 63 GinJavaBridgeValue::ContainsGinJavaBridgeValue(infinity.get())); |
| 64 scoped_ptr<const GinJavaBridgeValue> infinity_value( |
| 65 GinJavaBridgeValue::FromValue(infinity.get())); |
| 66 ASSERT_TRUE(infinity_value.get()); |
| 67 float native_float; |
| 68 EXPECT_TRUE( |
| 69 infinity_value->IsType(GinJavaBridgeValue::TYPE_NONFINITE)); |
| 70 EXPECT_TRUE(infinity_value->GetAsNonFinite(&native_float)); |
| 71 EXPECT_FALSE(base::IsFinite(native_float)); |
| 72 EXPECT_FALSE(base::IsNaN(native_float)); |
| 73 } |
| 74 |
| 75 TEST_F(GinJavaBridgeValueConverterTest, ArrayBuffer) { |
| 76 v8::HandleScope handle_scope(isolate_); |
| 77 v8::Local<v8::Context> context = |
| 78 v8::Local<v8::Context>::New(isolate_, context_); |
| 79 v8::Context::Scope context_scope(context); |
| 80 |
| 81 scoped_ptr<GinJavaBridgeValueConverter> converter( |
| 82 new GinJavaBridgeValueConverter()); |
| 83 |
| 84 v8::Handle<v8::ArrayBuffer> v8_array_buffer( |
| 85 v8::ArrayBuffer::New(isolate_, 0)); |
| 86 scoped_ptr<base::Value> undefined( |
| 87 converter->FromV8Value(v8_array_buffer, context)); |
| 88 ASSERT_TRUE(undefined.get()); |
| 89 EXPECT_TRUE(GinJavaBridgeValue::ContainsGinJavaBridgeValue(undefined.get())); |
| 90 scoped_ptr<const GinJavaBridgeValue> undefined_value( |
| 91 GinJavaBridgeValue::FromValue(undefined.get())); |
| 92 ASSERT_TRUE(undefined_value.get()); |
| 93 EXPECT_TRUE(undefined_value->IsType(GinJavaBridgeValue::TYPE_UNDEFINED)); |
| 94 } |
| 95 |
| 96 } // namespace content |
OLD | NEW |