| 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 "base/android/jni_android.h" | 9 #include "base/android/jni_android.h" |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 106 } // namespace | 106 } // namespace |
| 107 | 107 |
| 108 TEST_F(GinJavaMethodInvocationHelperTest, RetrievalOfObjectsNoObjects) { | 108 TEST_F(GinJavaMethodInvocationHelperTest, RetrievalOfObjectsNoObjects) { |
| 109 base::ListValue no_objects; | 109 base::ListValue no_objects; |
| 110 for (int i = 0; i < 10; ++i) { | 110 for (int i = 0; i < 10; ++i) { |
| 111 no_objects.AppendInteger(i); | 111 no_objects.AppendInteger(i); |
| 112 } | 112 } |
| 113 | 113 |
| 114 scoped_refptr<GinJavaMethodInvocationHelper> helper = | 114 scoped_refptr<GinJavaMethodInvocationHelper> helper = |
| 115 new GinJavaMethodInvocationHelper( | 115 new GinJavaMethodInvocationHelper( |
| 116 scoped_ptr<GinJavaMethodInvocationHelper::ObjectDelegate>( | 116 std::unique_ptr<GinJavaMethodInvocationHelper::ObjectDelegate>( |
| 117 new NullObjectDelegate()), | 117 new NullObjectDelegate()), |
| 118 "foo", | 118 "foo", no_objects); |
| 119 no_objects); | |
| 120 CountingDispatcherDelegate counter; | 119 CountingDispatcherDelegate counter; |
| 121 helper->Init(&counter); | 120 helper->Init(&counter); |
| 122 counter.AssertInvocationsCount(0, 0); | 121 counter.AssertInvocationsCount(0, 0); |
| 123 } | 122 } |
| 124 | 123 |
| 125 TEST_F(GinJavaMethodInvocationHelperTest, RetrievalOfObjectsHaveObjects) { | 124 TEST_F(GinJavaMethodInvocationHelperTest, RetrievalOfObjectsHaveObjects) { |
| 126 base::ListValue objects; | 125 base::ListValue objects; |
| 127 objects.AppendInteger(100); | 126 objects.AppendInteger(100); |
| 128 objects.Append(GinJavaBridgeValue::CreateObjectIDValue(1).release()); | 127 objects.Append(GinJavaBridgeValue::CreateObjectIDValue(1).release()); |
| 129 base::ListValue* sub_list = new base::ListValue(); | 128 base::ListValue* sub_list = new base::ListValue(); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 140 sub_list_with_dict->Append(sub_sub_dict); | 139 sub_list_with_dict->Append(sub_sub_dict); |
| 141 objects.Append(sub_list_with_dict); | 140 objects.Append(sub_list_with_dict); |
| 142 base::DictionaryValue* sub_dict_with_list = new base::DictionaryValue(); | 141 base::DictionaryValue* sub_dict_with_list = new base::DictionaryValue(); |
| 143 base::ListValue* sub_sub_list = new base::ListValue(); | 142 base::ListValue* sub_sub_list = new base::ListValue(); |
| 144 sub_sub_list->Append(GinJavaBridgeValue::CreateObjectIDValue(5).release()); | 143 sub_sub_list->Append(GinJavaBridgeValue::CreateObjectIDValue(5).release()); |
| 145 sub_dict_with_list->Set("1", sub_sub_list); | 144 sub_dict_with_list->Set("1", sub_sub_list); |
| 146 objects.Append(sub_dict_with_list); | 145 objects.Append(sub_dict_with_list); |
| 147 | 146 |
| 148 scoped_refptr<GinJavaMethodInvocationHelper> helper = | 147 scoped_refptr<GinJavaMethodInvocationHelper> helper = |
| 149 new GinJavaMethodInvocationHelper( | 148 new GinJavaMethodInvocationHelper( |
| 150 scoped_ptr<GinJavaMethodInvocationHelper::ObjectDelegate>( | 149 std::unique_ptr<GinJavaMethodInvocationHelper::ObjectDelegate>( |
| 151 new NullObjectDelegate()), | 150 new NullObjectDelegate()), |
| 152 "foo", | 151 "foo", objects); |
| 153 objects); | |
| 154 CountingDispatcherDelegate counter; | 152 CountingDispatcherDelegate counter; |
| 155 helper->Init(&counter); | 153 helper->Init(&counter); |
| 156 counter.AssertInvocationsCount(1, 6); | 154 counter.AssertInvocationsCount(1, 6); |
| 157 } | 155 } |
| 158 | 156 |
| 159 namespace { | 157 namespace { |
| 160 | 158 |
| 161 class ObjectIsGoneObjectDelegate : public NullObjectDelegate { | 159 class ObjectIsGoneObjectDelegate : public NullObjectDelegate { |
| 162 public: | 160 public: |
| 163 ObjectIsGoneObjectDelegate() : | 161 ObjectIsGoneObjectDelegate() : |
| (...skipping 23 matching lines...) Expand all Loading... |
| 187 const JavaMethod* FindMethod(const std::string& method_name, | 185 const JavaMethod* FindMethod(const std::string& method_name, |
| 188 size_t num_parameters) override { | 186 size_t num_parameters) override { |
| 189 return method_.get(); | 187 return method_.get(); |
| 190 } | 188 } |
| 191 | 189 |
| 192 bool get_local_ref_called() { return get_local_ref_called_; } | 190 bool get_local_ref_called() { return get_local_ref_called_; } |
| 193 | 191 |
| 194 const std::string& get_method_name() { return method_->name(); } | 192 const std::string& get_method_name() { return method_->name(); } |
| 195 | 193 |
| 196 protected: | 194 protected: |
| 197 scoped_ptr<JavaMethod> method_; | 195 std::unique_ptr<JavaMethod> method_; |
| 198 bool get_local_ref_called_; | 196 bool get_local_ref_called_; |
| 199 | 197 |
| 200 private: | 198 private: |
| 201 DISALLOW_COPY_AND_ASSIGN(ObjectIsGoneObjectDelegate); | 199 DISALLOW_COPY_AND_ASSIGN(ObjectIsGoneObjectDelegate); |
| 202 }; | 200 }; |
| 203 | 201 |
| 204 } // namespace | 202 } // namespace |
| 205 | 203 |
| 206 TEST_F(GinJavaMethodInvocationHelperTest, HandleObjectIsGone) { | 204 TEST_F(GinJavaMethodInvocationHelperTest, HandleObjectIsGone) { |
| 207 base::ListValue no_objects; | 205 base::ListValue no_objects; |
| 208 ObjectIsGoneObjectDelegate* object_delegate = | 206 ObjectIsGoneObjectDelegate* object_delegate = |
| 209 new ObjectIsGoneObjectDelegate(); | 207 new ObjectIsGoneObjectDelegate(); |
| 210 scoped_refptr<GinJavaMethodInvocationHelper> helper = | 208 scoped_refptr<GinJavaMethodInvocationHelper> helper = |
| 211 new GinJavaMethodInvocationHelper( | 209 new GinJavaMethodInvocationHelper( |
| 212 scoped_ptr<GinJavaMethodInvocationHelper::ObjectDelegate>( | 210 std::unique_ptr<GinJavaMethodInvocationHelper::ObjectDelegate>( |
| 213 object_delegate), | 211 object_delegate), |
| 214 object_delegate->get_method_name(), | 212 object_delegate->get_method_name(), no_objects); |
| 215 no_objects); | |
| 216 NullDispatcherDelegate dispatcher; | 213 NullDispatcherDelegate dispatcher; |
| 217 helper->Init(&dispatcher); | 214 helper->Init(&dispatcher); |
| 218 EXPECT_FALSE(object_delegate->get_local_ref_called()); | 215 EXPECT_FALSE(object_delegate->get_local_ref_called()); |
| 219 EXPECT_EQ(kGinJavaBridgeNoError, helper->GetInvocationError()); | 216 EXPECT_EQ(kGinJavaBridgeNoError, helper->GetInvocationError()); |
| 220 helper->Invoke(); | 217 helper->Invoke(); |
| 221 EXPECT_TRUE(object_delegate->get_local_ref_called()); | 218 EXPECT_TRUE(object_delegate->get_local_ref_called()); |
| 222 EXPECT_TRUE(helper->HoldsPrimitiveResult()); | 219 EXPECT_TRUE(helper->HoldsPrimitiveResult()); |
| 223 EXPECT_TRUE(helper->GetPrimitiveResult().empty()); | 220 EXPECT_TRUE(helper->GetPrimitiveResult().empty()); |
| 224 EXPECT_EQ(kGinJavaBridgeObjectIsGone, helper->GetInvocationError()); | 221 EXPECT_EQ(kGinJavaBridgeObjectIsGone, helper->GetInvocationError()); |
| 225 } | 222 } |
| (...skipping 27 matching lines...) Expand all Loading... |
| 253 }; | 250 }; |
| 254 | 251 |
| 255 } // namespace | 252 } // namespace |
| 256 | 253 |
| 257 TEST_F(GinJavaMethodInvocationHelperTest, HandleMethodNotFound) { | 254 TEST_F(GinJavaMethodInvocationHelperTest, HandleMethodNotFound) { |
| 258 base::ListValue no_objects; | 255 base::ListValue no_objects; |
| 259 MethodNotFoundObjectDelegate* object_delegate = | 256 MethodNotFoundObjectDelegate* object_delegate = |
| 260 new MethodNotFoundObjectDelegate(); | 257 new MethodNotFoundObjectDelegate(); |
| 261 scoped_refptr<GinJavaMethodInvocationHelper> helper = | 258 scoped_refptr<GinJavaMethodInvocationHelper> helper = |
| 262 new GinJavaMethodInvocationHelper( | 259 new GinJavaMethodInvocationHelper( |
| 263 scoped_ptr<GinJavaMethodInvocationHelper::ObjectDelegate>( | 260 std::unique_ptr<GinJavaMethodInvocationHelper::ObjectDelegate>( |
| 264 object_delegate), | 261 object_delegate), |
| 265 "foo", | 262 "foo", no_objects); |
| 266 no_objects); | |
| 267 NullDispatcherDelegate dispatcher; | 263 NullDispatcherDelegate dispatcher; |
| 268 helper->Init(&dispatcher); | 264 helper->Init(&dispatcher); |
| 269 EXPECT_FALSE(object_delegate->find_method_called()); | 265 EXPECT_FALSE(object_delegate->find_method_called()); |
| 270 EXPECT_EQ(kGinJavaBridgeNoError, helper->GetInvocationError()); | 266 EXPECT_EQ(kGinJavaBridgeNoError, helper->GetInvocationError()); |
| 271 helper->Invoke(); | 267 helper->Invoke(); |
| 272 EXPECT_TRUE(object_delegate->find_method_called()); | 268 EXPECT_TRUE(object_delegate->find_method_called()); |
| 273 EXPECT_TRUE(helper->HoldsPrimitiveResult()); | 269 EXPECT_TRUE(helper->HoldsPrimitiveResult()); |
| 274 EXPECT_TRUE(helper->GetPrimitiveResult().empty()); | 270 EXPECT_TRUE(helper->GetPrimitiveResult().empty()); |
| 275 EXPECT_EQ(kGinJavaBridgeMethodNotFound, helper->GetInvocationError()); | 271 EXPECT_EQ(kGinJavaBridgeMethodNotFound, helper->GetInvocationError()); |
| 276 } | 272 } |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 310 (JavaMethod*)0xdeadbeef; | 306 (JavaMethod*)0xdeadbeef; |
| 311 | 307 |
| 312 } // namespace | 308 } // namespace |
| 313 | 309 |
| 314 TEST_F(GinJavaMethodInvocationHelperTest, HandleGetClassInvocation) { | 310 TEST_F(GinJavaMethodInvocationHelperTest, HandleGetClassInvocation) { |
| 315 base::ListValue no_objects; | 311 base::ListValue no_objects; |
| 316 GetClassObjectDelegate* object_delegate = | 312 GetClassObjectDelegate* object_delegate = |
| 317 new GetClassObjectDelegate(); | 313 new GetClassObjectDelegate(); |
| 318 scoped_refptr<GinJavaMethodInvocationHelper> helper = | 314 scoped_refptr<GinJavaMethodInvocationHelper> helper = |
| 319 new GinJavaMethodInvocationHelper( | 315 new GinJavaMethodInvocationHelper( |
| 320 scoped_ptr<GinJavaMethodInvocationHelper::ObjectDelegate>( | 316 std::unique_ptr<GinJavaMethodInvocationHelper::ObjectDelegate>( |
| 321 object_delegate), | 317 object_delegate), |
| 322 "foo", | 318 "foo", no_objects); |
| 323 no_objects); | |
| 324 NullDispatcherDelegate dispatcher; | 319 NullDispatcherDelegate dispatcher; |
| 325 helper->Init(&dispatcher); | 320 helper->Init(&dispatcher); |
| 326 EXPECT_FALSE(object_delegate->find_method_called()); | 321 EXPECT_FALSE(object_delegate->find_method_called()); |
| 327 EXPECT_FALSE(object_delegate->get_class_called()); | 322 EXPECT_FALSE(object_delegate->get_class_called()); |
| 328 EXPECT_EQ(kGinJavaBridgeNoError, helper->GetInvocationError()); | 323 EXPECT_EQ(kGinJavaBridgeNoError, helper->GetInvocationError()); |
| 329 helper->Invoke(); | 324 helper->Invoke(); |
| 330 EXPECT_TRUE(object_delegate->find_method_called()); | 325 EXPECT_TRUE(object_delegate->find_method_called()); |
| 331 EXPECT_TRUE(object_delegate->get_class_called()); | 326 EXPECT_TRUE(object_delegate->get_class_called()); |
| 332 EXPECT_TRUE(helper->HoldsPrimitiveResult()); | 327 EXPECT_TRUE(helper->HoldsPrimitiveResult()); |
| 333 EXPECT_TRUE(helper->GetPrimitiveResult().empty()); | 328 EXPECT_TRUE(helper->GetPrimitiveResult().empty()); |
| 334 EXPECT_EQ(kGinJavaBridgeAccessToObjectGetClassIsBlocked, | 329 EXPECT_EQ(kGinJavaBridgeAccessToObjectGetClassIsBlocked, |
| 335 helper->GetInvocationError()); | 330 helper->GetInvocationError()); |
| 336 } | 331 } |
| 337 | 332 |
| 338 } // namespace content | 333 } // namespace content |
| OLD | NEW |