OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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 <stddef.h> | 5 #include <stddef.h> |
6 | 6 |
7 #include <cmath> | 7 #include <cmath> |
8 | 8 |
9 #include "base/macros.h" | 9 #include "base/macros.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
11 #include "base/strings/stringprintf.h" | 11 #include "base/strings/stringprintf.h" |
12 #include "content/common/android/gin_java_bridge_value.h" | 12 #include "content/common/android/gin_java_bridge_value.h" |
13 #include "content/renderer/java/gin_java_bridge_value_converter.h" | 13 #include "content/renderer/java/gin_java_bridge_value_converter.h" |
14 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
15 #include "third_party/WebKit/public/web/WebScopedMicrotaskSuppression.h" | |
16 #include "v8/include/v8.h" | 15 #include "v8/include/v8.h" |
17 | 16 |
18 namespace content { | 17 namespace content { |
19 | 18 |
20 class GinJavaBridgeValueConverterTest : public testing::Test { | 19 class GinJavaBridgeValueConverterTest : public testing::Test { |
21 public: | 20 public: |
22 GinJavaBridgeValueConverterTest() | 21 GinJavaBridgeValueConverterTest() |
23 : isolate_(v8::Isolate::GetCurrent()) { | 22 : isolate_(v8::Isolate::GetCurrent()) { |
24 } | 23 } |
25 | 24 |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 GinJavaBridgeValue::FromValue(undefined.get())); | 92 GinJavaBridgeValue::FromValue(undefined.get())); |
94 ASSERT_TRUE(undefined_value.get()); | 93 ASSERT_TRUE(undefined_value.get()); |
95 EXPECT_TRUE(undefined_value->IsType(GinJavaBridgeValue::TYPE_UNDEFINED)); | 94 EXPECT_TRUE(undefined_value->IsType(GinJavaBridgeValue::TYPE_UNDEFINED)); |
96 } | 95 } |
97 | 96 |
98 TEST_F(GinJavaBridgeValueConverterTest, TypedArrays) { | 97 TEST_F(GinJavaBridgeValueConverterTest, TypedArrays) { |
99 v8::HandleScope handle_scope(isolate_); | 98 v8::HandleScope handle_scope(isolate_); |
100 v8::Local<v8::Context> context = | 99 v8::Local<v8::Context> context = |
101 v8::Local<v8::Context>::New(isolate_, context_); | 100 v8::Local<v8::Context>::New(isolate_, context_); |
102 v8::Context::Scope context_scope(context); | 101 v8::Context::Scope context_scope(context); |
103 blink::WebScopedMicrotaskSuppression microtasks_scope; | |
104 | 102 |
105 scoped_ptr<GinJavaBridgeValueConverter> converter( | 103 scoped_ptr<GinJavaBridgeValueConverter> converter( |
106 new GinJavaBridgeValueConverter()); | 104 new GinJavaBridgeValueConverter()); |
107 | 105 |
108 const char* source_template = "(function() {" | 106 const char* source_template = "(function() {" |
109 "var array_buffer = new ArrayBuffer(%s);" | 107 "var array_buffer = new ArrayBuffer(%s);" |
110 "var array_view = new %s(array_buffer);" | 108 "var array_view = new %s(array_buffer);" |
111 "array_view[0] = 42;" | 109 "array_view[0] = 42;" |
112 "return array_view;" | 110 "return array_view;" |
113 "})();"; | 111 "})();"; |
(...skipping 17 matching lines...) Expand all Loading... |
131 base::ListValue* list; | 129 base::ListValue* list; |
132 ASSERT_TRUE(list_value->GetAsList(&list)) << typed_array_type; | 130 ASSERT_TRUE(list_value->GetAsList(&list)) << typed_array_type; |
133 EXPECT_EQ(1u, list->GetSize()) << typed_array_type; | 131 EXPECT_EQ(1u, list->GetSize()) << typed_array_type; |
134 double first_element; | 132 double first_element; |
135 ASSERT_TRUE(list->GetDouble(0, &first_element)) << typed_array_type; | 133 ASSERT_TRUE(list->GetDouble(0, &first_element)) << typed_array_type; |
136 EXPECT_EQ(42.0, first_element) << typed_array_type; | 134 EXPECT_EQ(42.0, first_element) << typed_array_type; |
137 } | 135 } |
138 } | 136 } |
139 | 137 |
140 } // namespace content | 138 } // namespace content |
OLD | NEW |