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

Unified Diff: extensions/renderer/native_extension_bindings_system_unittest.cc

Issue 2598123002: [Extensions Bindings] Add support for updateArgumentsPreValidate (Closed)
Patch Set: rebase 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
Index: extensions/renderer/native_extension_bindings_system_unittest.cc
diff --git a/extensions/renderer/native_extension_bindings_system_unittest.cc b/extensions/renderer/native_extension_bindings_system_unittest.cc
index 5045c8744ce793bf02ab76a20ffc8f9252a923a9..fdc410d3737a756e09db774dc993797fab348d84 100644
--- a/extensions/renderer/native_extension_bindings_system_unittest.cc
+++ b/extensions/renderer/native_extension_bindings_system_unittest.cc
@@ -285,6 +285,11 @@ TEST_F(NativeExtensionBindingsSystemUnittest, TestBridgingToJSCustomBindings) {
" this.timeArg = time;\n"
" callback('active');\n"
" });\n"
+ " api.apiFunctions.setUpdateArgumentsPreValidate(\n"
+ " 'setDetectionInterval', (interval) => {\n"
+ " this.intervalArg = interval;\n"
+ " return [50];\n"
+ " });\n"
" this.hookedExtensionId = extensionId;\n"
" this.hookedContextType = contextType;\n"
" api.compiledApi.hookedApiProperty = 'someProperty';\n"
@@ -341,6 +346,30 @@ TEST_F(NativeExtensionBindingsSystemUnittest, TestBridgingToJSCustomBindings) {
// ...and second, that the callback was called with the proper result.
EXPECT_EQ("\"active\"",
GetStringPropertyFromObject(global, context, "responseState"));
+
+ // Test the updateArgumentsPreValidate hook.
+ {
+ // Call the function correctly.
+ const char kCallIdleSetInterval[] =
+ "(function() {\n"
+ " chrome.idle.setDetectionInterval(20);\n"
+ "});";
+
+ v8::Local<v8::Function> call_idle_set_interval =
+ FunctionFromString(context, kCallIdleSetInterval);
+ RunFunctionOnGlobal(call_idle_set_interval, context, 0, nullptr);
+ }
+
+ // Since we don't have a custom request handler, the hook should have only
+ // updated the arguments. The request then should have gone to the browser
+ // normally.
+ EXPECT_EQ("20", GetStringPropertyFromObject(global, context, "intervalArg"));
+ EXPECT_EQ(extension->id(), last_params().extension_id);
+ EXPECT_EQ("idle.setDetectionInterval", last_params().name);
+ EXPECT_EQ(extension->url(), last_params().source_url);
+ EXPECT_FALSE(last_params().has_callback);
+ EXPECT_TRUE(
+ last_params().arguments.Equals(ListValueFromString("[50]").get()));
}
} // namespace extensions

Powered by Google App Engine
This is Rietveld 408576698