Chromium Code Reviews| 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..cdf416e58c89ab93c4261aa438a17cdd9c52b2b6 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" |
|
lazyboy
2017/02/13 21:54:27
nit:replace \n with ;\n
Devlin
2017/02/14 04:57:08
Done.
|
| + " });\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 |