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 <cmath> |
| 6 |
5 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
6 #include "base/float_util.h" | |
7 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
8 #include "content/common/android/gin_java_bridge_value.h" | 9 #include "content/common/android/gin_java_bridge_value.h" |
9 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
10 | 11 |
11 namespace content { | 12 namespace content { |
12 | 13 |
13 class GinJavaBridgeValueTest : public testing::Test { | 14 class GinJavaBridgeValueTest : public testing::Test { |
14 }; | 15 }; |
15 | 16 |
16 TEST_F(GinJavaBridgeValueTest, BasicValues) { | 17 TEST_F(GinJavaBridgeValueTest, BasicValues) { |
(...skipping 16 matching lines...) Expand all Loading... |
33 GinJavaBridgeValue::CreateNonFiniteValue( | 34 GinJavaBridgeValue::CreateNonFiniteValue( |
34 std::numeric_limits<float>::infinity())); | 35 std::numeric_limits<float>::infinity())); |
35 ASSERT_TRUE(float_infinity.get()); | 36 ASSERT_TRUE(float_infinity.get()); |
36 EXPECT_TRUE( | 37 EXPECT_TRUE( |
37 GinJavaBridgeValue::ContainsGinJavaBridgeValue(float_infinity.get())); | 38 GinJavaBridgeValue::ContainsGinJavaBridgeValue(float_infinity.get())); |
38 scoped_ptr<const GinJavaBridgeValue> float_infinity_value( | 39 scoped_ptr<const GinJavaBridgeValue> float_infinity_value( |
39 GinJavaBridgeValue::FromValue(float_infinity.get())); | 40 GinJavaBridgeValue::FromValue(float_infinity.get())); |
40 ASSERT_TRUE(float_infinity_value.get()); | 41 ASSERT_TRUE(float_infinity_value.get()); |
41 EXPECT_TRUE(float_infinity_value->IsType(GinJavaBridgeValue::TYPE_NONFINITE)); | 42 EXPECT_TRUE(float_infinity_value->IsType(GinJavaBridgeValue::TYPE_NONFINITE)); |
42 EXPECT_TRUE(float_infinity_value->GetAsNonFinite(&native_float)); | 43 EXPECT_TRUE(float_infinity_value->GetAsNonFinite(&native_float)); |
43 EXPECT_FALSE(base::IsFinite(native_float)); | 44 EXPECT_TRUE(std::isinf(native_float)); |
44 EXPECT_FALSE(base::IsNaN(native_float)); | |
45 | 45 |
46 EXPECT_FALSE(undefined_value->GetAsObjectID(&native_object_id)); | 46 EXPECT_FALSE(undefined_value->GetAsObjectID(&native_object_id)); |
47 | 47 |
48 scoped_ptr<base::BinaryValue> double_infinity( | 48 scoped_ptr<base::BinaryValue> double_infinity( |
49 GinJavaBridgeValue::CreateNonFiniteValue( | 49 GinJavaBridgeValue::CreateNonFiniteValue( |
50 std::numeric_limits<double>::infinity())); | 50 std::numeric_limits<double>::infinity())); |
51 ASSERT_TRUE(double_infinity.get()); | 51 ASSERT_TRUE(double_infinity.get()); |
52 EXPECT_TRUE( | 52 EXPECT_TRUE( |
53 GinJavaBridgeValue::ContainsGinJavaBridgeValue(double_infinity.get())); | 53 GinJavaBridgeValue::ContainsGinJavaBridgeValue(double_infinity.get())); |
54 scoped_ptr<const GinJavaBridgeValue> double_infinity_value( | 54 scoped_ptr<const GinJavaBridgeValue> double_infinity_value( |
55 GinJavaBridgeValue::FromValue(double_infinity.get())); | 55 GinJavaBridgeValue::FromValue(double_infinity.get())); |
56 ASSERT_TRUE(double_infinity_value.get()); | 56 ASSERT_TRUE(double_infinity_value.get()); |
57 EXPECT_TRUE( | 57 EXPECT_TRUE( |
58 double_infinity_value->IsType(GinJavaBridgeValue::TYPE_NONFINITE)); | 58 double_infinity_value->IsType(GinJavaBridgeValue::TYPE_NONFINITE)); |
59 EXPECT_TRUE(double_infinity_value->GetAsNonFinite(&native_float)); | 59 EXPECT_TRUE(double_infinity_value->GetAsNonFinite(&native_float)); |
60 EXPECT_FALSE(base::IsFinite(native_float)); | 60 EXPECT_TRUE(std::isinf(native_float)); |
61 EXPECT_FALSE(base::IsNaN(native_float)); | |
62 | 61 |
63 EXPECT_FALSE(undefined_value->GetAsObjectID(&native_object_id)); | 62 EXPECT_FALSE(undefined_value->GetAsObjectID(&native_object_id)); |
64 | 63 |
65 scoped_ptr<base::BinaryValue> object_id( | 64 scoped_ptr<base::BinaryValue> object_id( |
66 GinJavaBridgeValue::CreateObjectIDValue(42)); | 65 GinJavaBridgeValue::CreateObjectIDValue(42)); |
67 ASSERT_TRUE(object_id.get()); | 66 ASSERT_TRUE(object_id.get()); |
68 EXPECT_TRUE(GinJavaBridgeValue::ContainsGinJavaBridgeValue(object_id.get())); | 67 EXPECT_TRUE(GinJavaBridgeValue::ContainsGinJavaBridgeValue(object_id.get())); |
69 scoped_ptr<const GinJavaBridgeValue> object_id_value( | 68 scoped_ptr<const GinJavaBridgeValue> object_id_value( |
70 GinJavaBridgeValue::FromValue(object_id.get())); | 69 GinJavaBridgeValue::FromValue(object_id.get())); |
71 ASSERT_TRUE(object_id_value.get()); | 70 ASSERT_TRUE(object_id_value.get()); |
(...skipping 11 matching lines...) Expand all Loading... |
83 | 82 |
84 const char dummy_data[] = "\000\001\002\003\004\005\006\007\010\011\012\013"; | 83 const char dummy_data[] = "\000\001\002\003\004\005\006\007\010\011\012\013"; |
85 scoped_ptr<base::BinaryValue> broken_binary( | 84 scoped_ptr<base::BinaryValue> broken_binary( |
86 base::BinaryValue::CreateWithCopiedBuffer(dummy_data, | 85 base::BinaryValue::CreateWithCopiedBuffer(dummy_data, |
87 sizeof(dummy_data))); | 86 sizeof(dummy_data))); |
88 EXPECT_FALSE( | 87 EXPECT_FALSE( |
89 GinJavaBridgeValue::ContainsGinJavaBridgeValue(broken_binary.get())); | 88 GinJavaBridgeValue::ContainsGinJavaBridgeValue(broken_binary.get())); |
90 } | 89 } |
91 | 90 |
92 } // namespace | 91 } // namespace |
OLD | NEW |