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 78c498cded7ec25aa532d015df1e02f17502b34b..6bd27884b30abf1511445ea38860a9ad974a7b69 100644 |
--- a/extensions/renderer/native_extension_bindings_system_unittest.cc |
+++ b/extensions/renderer/native_extension_bindings_system_unittest.cc |
@@ -601,4 +601,47 @@ TEST_F(NativeExtensionBindingsSystemUnittest, |
EXPECT_TRUE(last_params().has_callback); |
} |
+TEST_F(NativeExtensionBindingsSystemUnittest, TestLastError) { |
+ scoped_refptr<Extension> extension = |
+ CreateExtension("foo", ItemType::EXTENSION, {"idle", "power"}); |
+ RegisterExtension(extension->id()); |
+ |
+ v8::HandleScope handle_scope(isolate()); |
+ v8::Local<v8::Context> context = ContextLocal(); |
+ |
+ ScriptContext* script_context = CreateScriptContext( |
+ context, extension.get(), Feature::BLESSED_EXTENSION_CONTEXT); |
+ script_context->set_url(extension->url()); |
+ |
+ bindings_system()->UpdateBindingsForContext(script_context); |
+ |
+ { |
+ // Try calling the function with an invalid invocation - an error should be |
+ // thrown. |
+ const char kCallFunction[] = |
+ "(function() {\n" |
+ " chrome.idle.queryState(30, function(state) {\n" |
+ " if (chrome.runtime.lastError)\n" |
+ " this.lastErrorMessage = chrome.runtime.lastError.message;\n" |
+ " });\n" |
+ "});"; |
+ v8::Local<v8::Function> function = |
+ FunctionFromString(context, kCallFunction); |
+ ASSERT_FALSE(function.IsEmpty()); |
+ RunFunctionOnGlobal(function, context, 0, nullptr); |
+ } |
+ |
+ // Validate the params that would be sent to the browser. |
+ EXPECT_EQ(extension->id(), last_params().extension_id); |
+ EXPECT_EQ("idle.queryState", last_params().name); |
+ |
+ // Respond and validate. |
+ bindings_system()->HandleResponse(last_params().request_id, true, |
+ base::ListValue(), "Some API Error"); |
+ |
+ EXPECT_EQ("\"Some API Error\"", |
+ GetStringPropertyFromObject(context->Global(), context, |
+ "lastErrorMessage")); |
+} |
+ |
} // namespace extensions |