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

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: woot 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
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 280 matching lines...) Expand 10 before | Expand all | Expand 10 after
291 291
292 // Tests adding a custom hook to an API. 292 // Tests adding a custom hook to an API.
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 v8::Local<v8::Value>* return_value) {
302 *did_call = true; 303 *did_call = true;
303 if (arguments->size() != 2) { // ASSERT* messes with the return type. 304 if (arguments->size() != 2) { // ASSERT* messes with the return type.
304 EXPECT_EQ(2u, arguments->size()); 305 EXPECT_EQ(2u, arguments->size());
305 return APIBindingHooks::RequestResult::HANDLED; 306 return APIBindingHooks::RequestResult::HANDLED;
306 } 307 }
307 std::string argument; 308 std::string argument;
308 EXPECT_EQ("foo", gin::V8ToString(arguments->at(0))); 309 EXPECT_EQ("foo", gin::V8ToString(arguments->at(0)));
309 if (!arguments->at(1)->IsFunction()) { 310 if (!arguments->at(1)->IsFunction()) {
310 EXPECT_TRUE(arguments->at(1)->IsFunction()); 311 EXPECT_TRUE(arguments->at(1)->IsFunction());
311 return APIBindingHooks::RequestResult::HANDLED; 312 return APIBindingHooks::RequestResult::HANDLED;
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
486 context, "idleState")); 487 context, "idleState"));
487 bindings_system()->FireEventInContext("idle.onStateChanged", context, 488 bindings_system()->FireEventInContext("idle.onStateChanged", context,
488 *ListValueFromString("['active']")); 489 *ListValueFromString("['active']"));
489 490
490 EXPECT_EQ("\"active\"", GetStringPropertyFromObject(context->Global(), 491 EXPECT_EQ("\"active\"", GetStringPropertyFromObject(context->Global(),
491 context, "idleState")); 492 context, "idleState"));
492 } 493 }
493 } 494 }
494 495
495 } // namespace extensions 496 } // namespace extensions
OLDNEW
« extensions/renderer/api_binding_hooks.h ('K') | « extensions/renderer/api_binding_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698