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 2d184a9e743c12e9375a3942b2dcb31babf9bf04..0a38bf62a6e9af15f037314439981936ee8858ad 100644 |
--- a/extensions/renderer/native_extension_bindings_system_unittest.cc |
+++ b/extensions/renderer/native_extension_bindings_system_unittest.cc |
@@ -501,4 +501,47 @@ TEST_F(NativeExtensionBindingsSystemUnittest, TestEventRegistration) { |
::testing::Mock::VerifyAndClearExpectations(event_change_handler()); |
} |
+TEST_F(NativeExtensionBindingsSystemUnittest, TestLastError) { |
+ scoped_refptr<Extension> extension = |
+ CreateExtension("foo", {"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 |