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 "content/browser/android/java/gin_java_method_invocation_helper.h" | 5 #include "content/browser/android/java/gin_java_method_invocation_helper.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <utility> | |
10 | |
9 #include "base/android/jni_android.h" | 11 #include "base/android/jni_android.h" |
10 #include "base/macros.h" | 12 #include "base/macros.h" |
13 #include "base/memory/ptr_util.h" | |
jdoerrie
2017/04/12 16:08:55
#include "base/values.h"
vabr (Chromium)
2017/04/12 16:40:53
Done.
| |
11 #include "content/browser/android/java/jni_helper.h" | 14 #include "content/browser/android/java/jni_helper.h" |
12 #include "content/common/android/gin_java_bridge_value.h" | 15 #include "content/common/android/gin_java_bridge_value.h" |
13 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
14 | 17 |
15 namespace content { | 18 namespace content { |
16 | 19 |
17 namespace { | 20 namespace { |
18 | 21 |
19 class NullObjectDelegate | 22 class NullObjectDelegate |
20 : public GinJavaMethodInvocationHelper::ObjectDelegate { | 23 : public GinJavaMethodInvocationHelper::ObjectDelegate { |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
117 new NullObjectDelegate()), | 120 new NullObjectDelegate()), |
118 "foo", no_objects); | 121 "foo", no_objects); |
119 CountingDispatcherDelegate counter; | 122 CountingDispatcherDelegate counter; |
120 helper->Init(&counter); | 123 helper->Init(&counter); |
121 counter.AssertInvocationsCount(0, 0); | 124 counter.AssertInvocationsCount(0, 0); |
122 } | 125 } |
123 | 126 |
124 TEST_F(GinJavaMethodInvocationHelperTest, RetrievalOfObjectsHaveObjects) { | 127 TEST_F(GinJavaMethodInvocationHelperTest, RetrievalOfObjectsHaveObjects) { |
125 base::ListValue objects; | 128 base::ListValue objects; |
126 objects.AppendInteger(100); | 129 objects.AppendInteger(100); |
127 objects.Append(GinJavaBridgeValue::CreateObjectIDValue(1).release()); | 130 objects.Append(GinJavaBridgeValue::CreateObjectIDValue(1)); |
128 base::ListValue* sub_list = new base::ListValue(); | 131 auto sub_list = base::MakeUnique<base::ListValue>(); |
129 sub_list->AppendInteger(200); | 132 sub_list->AppendInteger(200); |
130 sub_list->Append(GinJavaBridgeValue::CreateObjectIDValue(2).release()); | 133 sub_list->Append(GinJavaBridgeValue::CreateObjectIDValue(2)); |
131 objects.Append(sub_list); | 134 objects.Append(std::move(sub_list)); |
132 base::DictionaryValue* sub_dict = new base::DictionaryValue(); | 135 auto sub_dict = base::MakeUnique<base::DictionaryValue>(); |
133 sub_dict->SetInteger("1", 300); | 136 sub_dict->SetInteger("1", 300); |
134 sub_dict->Set("2", GinJavaBridgeValue::CreateObjectIDValue(3).release()); | 137 sub_dict->Set("2", GinJavaBridgeValue::CreateObjectIDValue(3)); |
135 objects.Append(sub_dict); | 138 objects.Append(std::move(sub_dict)); |
136 base::ListValue* sub_list_with_dict = new base::ListValue(); | 139 auto sub_list_with_dict = base::MakeUnique<base::ListValue>(); |
137 base::DictionaryValue* sub_sub_dict = new base::DictionaryValue(); | 140 auto sub_sub_dict = base::MakeUnique<base::DictionaryValue>(); |
138 sub_sub_dict->Set("1", GinJavaBridgeValue::CreateObjectIDValue(4).release()); | 141 sub_sub_dict->Set("1", GinJavaBridgeValue::CreateObjectIDValue(4)); |
139 sub_list_with_dict->Append(sub_sub_dict); | 142 sub_list_with_dict->Append(std::move(sub_sub_dict)); |
140 objects.Append(sub_list_with_dict); | 143 objects.Append(std::move(sub_list_with_dict)); |
141 base::DictionaryValue* sub_dict_with_list = new base::DictionaryValue(); | 144 auto sub_dict_with_list = base::MakeUnique<base::DictionaryValue>(); |
142 base::ListValue* sub_sub_list = new base::ListValue(); | 145 auto sub_sub_list = base::MakeUnique<base::ListValue>(); |
143 sub_sub_list->Append(GinJavaBridgeValue::CreateObjectIDValue(5).release()); | 146 sub_sub_list->Append(GinJavaBridgeValue::CreateObjectIDValue(5)); |
144 sub_dict_with_list->Set("1", sub_sub_list); | 147 sub_dict_with_list->Set("1", std::move(sub_sub_list)); |
145 objects.Append(sub_dict_with_list); | 148 objects.Append(std::move(sub_dict_with_list)); |
146 | 149 |
147 scoped_refptr<GinJavaMethodInvocationHelper> helper = | 150 scoped_refptr<GinJavaMethodInvocationHelper> helper = |
148 new GinJavaMethodInvocationHelper( | 151 new GinJavaMethodInvocationHelper( |
149 std::unique_ptr<GinJavaMethodInvocationHelper::ObjectDelegate>( | 152 std::unique_ptr<GinJavaMethodInvocationHelper::ObjectDelegate>( |
150 new NullObjectDelegate()), | 153 new NullObjectDelegate()), |
151 "foo", objects); | 154 "foo", objects); |
152 CountingDispatcherDelegate counter; | 155 CountingDispatcherDelegate counter; |
153 helper->Init(&counter); | 156 helper->Init(&counter); |
154 counter.AssertInvocationsCount(1, 6); | 157 counter.AssertInvocationsCount(1, 6); |
155 } | 158 } |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
324 helper->Invoke(); | 327 helper->Invoke(); |
325 EXPECT_TRUE(object_delegate->find_method_called()); | 328 EXPECT_TRUE(object_delegate->find_method_called()); |
326 EXPECT_TRUE(object_delegate->get_class_called()); | 329 EXPECT_TRUE(object_delegate->get_class_called()); |
327 EXPECT_TRUE(helper->HoldsPrimitiveResult()); | 330 EXPECT_TRUE(helper->HoldsPrimitiveResult()); |
328 EXPECT_TRUE(helper->GetPrimitiveResult().empty()); | 331 EXPECT_TRUE(helper->GetPrimitiveResult().empty()); |
329 EXPECT_EQ(kGinJavaBridgeAccessToObjectGetClassIsBlocked, | 332 EXPECT_EQ(kGinJavaBridgeAccessToObjectGetClassIsBlocked, |
330 helper->GetInvocationError()); | 333 helper->GetInvocationError()); |
331 } | 334 } |
332 | 335 |
333 } // namespace content | 336 } // namespace content |
OLD | NEW |