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

Unified Diff: extensions/renderer/api_binding_unittest.cc

Issue 2583273002: [Extensions Bindings] Allow for argument validation without conversion (Closed)
Patch Set: lazyboy's Created 4 years 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « extensions/renderer/api_binding_hooks.cc ('k') | extensions/renderer/api_bindings_system_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: extensions/renderer/api_binding_unittest.cc
diff --git a/extensions/renderer/api_binding_unittest.cc b/extensions/renderer/api_binding_unittest.cc
index 04c18065ebb5d52272faaadf1fb966adf2f75289..114915c6b91620193f65293d266d0f6fc3fd778d 100644
--- a/extensions/renderer/api_binding_unittest.cc
+++ b/extensions/renderer/api_binding_unittest.cc
@@ -454,12 +454,14 @@ TEST_F(APIBindingUnittest, TestCustomHooks) {
base::Bind(&RunFunctionOnGlobalAndIgnoreResult));
bool did_call = false;
auto hook = [](bool* did_call, const APISignature* signature,
- gin::Arguments* arguments) {
+ gin::Arguments* arguments,
+ const ArgumentSpec::RefMap& ref_map) {
*did_call = true;
EXPECT_EQ(1, arguments->Length());
std::string argument;
EXPECT_TRUE(arguments->GetNext(&argument));
EXPECT_EQ("foo", argument);
+ return APIBindingHooks::RequestResult::HANDLED;
};
hooks->RegisterHandleRequest("test.oneString", base::Bind(hook, &did_call));
@@ -525,8 +527,16 @@ TEST_F(APIBindingUnittest, TestJSCustomHook) {
v8::Local<v8::Object> binding_object = binding.CreateInstance(
context, isolate(), &event_handler, base::Bind(&AllowAllAPIs));
- // First try calling the oneString() method, which has a custom hook
- // installed.
+ // First try calling with an invalid invocation. An error should be raised and
+ // the hook should never have been called, since the arguments didn't match.
+ ExpectFailure(binding_object, "obj.oneString(1);", kError);
+ v8::Local<v8::Value> property =
+ GetPropertyFromObject(context->Global(), context, "requestArguments");
+ ASSERT_FALSE(property.IsEmpty());
+ EXPECT_TRUE(property->IsUndefined());
+
+ // Try calling the oneString() method with valid arguments. The hook should
+ // be called.
v8::Local<v8::Function> func =
FunctionFromString(context, "(function(obj) { obj.oneString('foo'); })");
v8::Local<v8::Value> args[] = {binding_object};
« no previous file with comments | « extensions/renderer/api_binding_hooks.cc ('k') | extensions/renderer/api_bindings_system_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698