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

Unified Diff: extensions/renderer/native_extension_bindings_system_unittest.cc

Issue 2657613005: [Extensions Bindings] Add chrome.runtime.lastError support (Closed)
Patch Set: . Created 3 years, 10 months 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/native_extension_bindings_system.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
« no previous file with comments | « extensions/renderer/native_extension_bindings_system.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698