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

Unified Diff: content/renderer/java/gin_java_bridge_value_converter_unittest.cc

Issue 259033002: [Android] Implement renderer side of Gin Java Bridge (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Comments addressed, test added Created 6 years, 8 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 side-by-side diff with in-line comments
Download patch
Index: content/renderer/java/gin_java_bridge_value_converter_unittest.cc
diff --git a/content/renderer/java/gin_java_bridge_value_converter_unittest.cc b/content/renderer/java/gin_java_bridge_value_converter_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..aefa1c5d7d502872642ffd1017eff0d3d56f031a
--- /dev/null
+++ b/content/renderer/java/gin_java_bridge_value_converter_unittest.cc
@@ -0,0 +1,96 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/basictypes.h"
+#include "base/float_util.h"
+#include "base/memory/scoped_ptr.h"
+#include "content/common/android/gin_java_bridge_value.h"
+#include "content/renderer/java/gin_java_bridge_value_converter.h"
+#include "testing/gtest/include/gtest/gtest.h"
+#include "v8/include/v8.h"
+
+namespace content {
+
+class GinJavaBridgeValueConverterTest : public testing::Test {
+ public:
+ GinJavaBridgeValueConverterTest()
+ : isolate_(v8::Isolate::GetCurrent()) {
+ }
+
+ protected:
+ virtual void SetUp() {
+ v8::HandleScope handle_scope(isolate_);
+ v8::Handle<v8::ObjectTemplate> global = v8::ObjectTemplate::New(isolate_);
+ context_.Reset(isolate_, v8::Context::New(isolate_, NULL, global));
+ }
+
+ virtual void TearDown() {
+ context_.Reset();
+ }
+
+ v8::Isolate* isolate_;
+
+ // Context for the JavaScript in the test.
+ v8::Persistent<v8::Context> context_;
+};
+
+TEST_F(GinJavaBridgeValueConverterTest, BasicValues) {
+ v8::HandleScope handle_scope(isolate_);
+ v8::Local<v8::Context> context =
+ v8::Local<v8::Context>::New(isolate_, context_);
+ v8::Context::Scope context_scope(context);
+
+ scoped_ptr<GinJavaBridgeValueConverter> converter(
+ new GinJavaBridgeValueConverter());
+
+ v8::Handle<v8::Primitive> v8_undefined(v8::Undefined(isolate_));
+ scoped_ptr<base::Value> undefined(
+ converter->FromV8Value(v8_undefined, context));
+ ASSERT_TRUE(undefined.get());
+ EXPECT_TRUE(GinJavaBridgeValue::ContainsGinJavaBridgeValue(undefined.get()));
+ scoped_ptr<const GinJavaBridgeValue> undefined_value(
+ GinJavaBridgeValue::FromValue(undefined.get()));
+ ASSERT_TRUE(undefined_value.get());
+ EXPECT_TRUE(undefined_value->IsType(GinJavaBridgeValue::TYPE_UNDEFINED));
+
+ v8::Handle<v8::Number> v8_infinity(
+ v8::Number::New(isolate_, std::numeric_limits<double>::infinity()));
+ scoped_ptr<base::Value> infinity(
+ converter->FromV8Value(v8_infinity, context));
+ ASSERT_TRUE(infinity.get());
+ EXPECT_TRUE(
+ GinJavaBridgeValue::ContainsGinJavaBridgeValue(infinity.get()));
+ scoped_ptr<const GinJavaBridgeValue> infinity_value(
+ GinJavaBridgeValue::FromValue(infinity.get()));
+ ASSERT_TRUE(infinity_value.get());
+ float native_float;
+ EXPECT_TRUE(
+ infinity_value->IsType(GinJavaBridgeValue::TYPE_NONFINITE));
+ EXPECT_TRUE(infinity_value->GetAsNonFinite(&native_float));
+ EXPECT_FALSE(base::IsFinite(native_float));
+ EXPECT_FALSE(base::IsNaN(native_float));
+}
+
+TEST_F(GinJavaBridgeValueConverterTest, ArrayBuffer) {
+ v8::HandleScope handle_scope(isolate_);
+ v8::Local<v8::Context> context =
+ v8::Local<v8::Context>::New(isolate_, context_);
+ v8::Context::Scope context_scope(context);
+
+ scoped_ptr<GinJavaBridgeValueConverter> converter(
+ new GinJavaBridgeValueConverter());
+
+ v8::Handle<v8::ArrayBuffer> v8_array_buffer(
+ v8::ArrayBuffer::New(isolate_, 0));
+ scoped_ptr<base::Value> undefined(
+ converter->FromV8Value(v8_array_buffer, context));
+ ASSERT_TRUE(undefined.get());
+ EXPECT_TRUE(GinJavaBridgeValue::ContainsGinJavaBridgeValue(undefined.get()));
+ scoped_ptr<const GinJavaBridgeValue> undefined_value(
+ GinJavaBridgeValue::FromValue(undefined.get()));
+ ASSERT_TRUE(undefined_value.get());
+ EXPECT_TRUE(undefined_value->IsType(GinJavaBridgeValue::TYPE_UNDEFINED));
+}
+
+} // namespace content

Powered by Google App Engine
This is Rietveld 408576698