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

Side by Side Diff: extensions/renderer/api_bindings_system_unittest.cc

Issue 2609553003: [Extensions Bindings] Allow custom hooks to return values, throw (Closed)
Patch Set: rebase Created 3 years, 11 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 unified diff | Download patch
« no previous file with comments | « extensions/renderer/api_binding_unittest.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "extensions/renderer/api_bindings_system.h" 5 #include "extensions/renderer/api_bindings_system.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/macros.h" 8 #include "base/macros.h"
9 #include "base/memory/ptr_util.h" 9 #include "base/memory/ptr_util.h"
10 #include "base/stl_util.h" 10 #include "base/stl_util.h"
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after
293 TEST_F(APIBindingsSystemTest, TestCustomHooks) { 293 TEST_F(APIBindingsSystemTest, TestCustomHooks) {
294 v8::HandleScope handle_scope(isolate()); 294 v8::HandleScope handle_scope(isolate());
295 v8::Local<v8::Context> context = ContextLocal(); 295 v8::Local<v8::Context> context = ContextLocal();
296 296
297 bool did_call = false; 297 bool did_call = false;
298 auto hook = [](bool* did_call, 298 auto hook = [](bool* did_call,
299 const APISignature* signature, v8::Local<v8::Context> context, 299 const APISignature* signature, v8::Local<v8::Context> context,
300 std::vector<v8::Local<v8::Value>>* arguments, 300 std::vector<v8::Local<v8::Value>>* arguments,
301 const ArgumentSpec::RefMap& type_refs) { 301 const ArgumentSpec::RefMap& type_refs) {
302 *did_call = true; 302 *did_call = true;
303 APIBindingHooks::RequestResult result(
304 APIBindingHooks::RequestResult::HANDLED);
303 if (arguments->size() != 2) { // ASSERT* messes with the return type. 305 if (arguments->size() != 2) { // ASSERT* messes with the return type.
304 EXPECT_EQ(2u, arguments->size()); 306 EXPECT_EQ(2u, arguments->size());
305 return APIBindingHooks::RequestResult::HANDLED; 307 return result;
306 } 308 }
307 std::string argument; 309 std::string argument;
308 EXPECT_EQ("foo", gin::V8ToString(arguments->at(0))); 310 EXPECT_EQ("foo", gin::V8ToString(arguments->at(0)));
309 if (!arguments->at(1)->IsFunction()) { 311 if (!arguments->at(1)->IsFunction()) {
310 EXPECT_TRUE(arguments->at(1)->IsFunction()); 312 EXPECT_TRUE(arguments->at(1)->IsFunction());
311 return APIBindingHooks::RequestResult::HANDLED; 313 return result;
312 } 314 }
313 v8::Local<v8::String> response = 315 v8::Local<v8::String> response =
314 gin::StringToV8(context->GetIsolate(), "bar"); 316 gin::StringToV8(context->GetIsolate(), "bar");
315 v8::Local<v8::Value> response_args[] = {response}; 317 v8::Local<v8::Value> response_args[] = {response};
316 RunFunctionOnGlobal(arguments->at(1).As<v8::Function>(), 318 RunFunctionOnGlobal(arguments->at(1).As<v8::Function>(),
317 context, 1, response_args); 319 context, 1, response_args);
318 return APIBindingHooks::RequestResult::HANDLED; 320 return result;
319 }; 321 };
320 322
321 APIBindingHooks* hooks = bindings_system()->GetHooksForAPI(kAlphaAPIName); 323 APIBindingHooks* hooks = bindings_system()->GetHooksForAPI(kAlphaAPIName);
322 ASSERT_TRUE(hooks); 324 ASSERT_TRUE(hooks);
323 hooks->RegisterHandleRequest( 325 hooks->RegisterHandleRequest(
324 "alpha.functionWithCallback", 326 "alpha.functionWithCallback",
325 base::Bind(hook, &did_call)); 327 base::Bind(hook, &did_call));
326 328
327 v8::Local<v8::Object> alpha_api = bindings_system()->CreateAPIInstance( 329 v8::Local<v8::Object> alpha_api = bindings_system()->CreateAPIInstance(
328 kAlphaAPIName, context, isolate(), base::Bind(&AllowAllAPIs), nullptr); 330 kAlphaAPIName, context, isolate(), base::Bind(&AllowAllAPIs), nullptr);
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
486 context, "idleState")); 488 context, "idleState"));
487 bindings_system()->FireEventInContext("idle.onStateChanged", context, 489 bindings_system()->FireEventInContext("idle.onStateChanged", context,
488 *ListValueFromString("['active']")); 490 *ListValueFromString("['active']"));
489 491
490 EXPECT_EQ("\"active\"", GetStringPropertyFromObject(context->Global(), 492 EXPECT_EQ("\"active\"", GetStringPropertyFromObject(context->Global(),
491 context, "idleState")); 493 context, "idleState"));
492 } 494 }
493 } 495 }
494 496
495 } // namespace extensions 497 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/renderer/api_binding_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698