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

Unified Diff: extensions/renderer/native_extension_bindings_system_unittest.cc

Issue 2613093002: [Extension Bindings] Test event listeners throwing exceptions (Closed)
Patch Set: add comment Created 3 years, 11 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
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 705f9cc6f6222e6ef3b08de7a14519920878fcbc..e711611b39f7290b8ad99d3b1ff08ac36703cf0c 100644
--- a/extensions/renderer/native_extension_bindings_system_unittest.cc
+++ b/extensions/renderer/native_extension_bindings_system_unittest.cc
@@ -216,6 +216,48 @@ TEST_F(NativeExtensionBindingsSystemUnittest, Basic) {
EXPECT_TRUE(request_keep_awake->IsFunction());
}
+TEST_F(NativeExtensionBindingsSystemUnittest, Events) {
+ 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);
+
+ {
+ const char kAddStateChangedListeners[] =
+ "(function() {\n"
+ " chrome.idle.onStateChanged.addListener(function() {\n"
+ " this.didThrow = true;\n"
+ " throw new Error('Error!!!');\n"
+ " });\n"
+ " chrome.idle.onStateChanged.addListener(function(newState) {\n"
+ " this.newState = newState;\n"
+ " });\n"
+ "});";
+
+ v8::Local<v8::Function> add_listeners =
+ FunctionFromString(context, kAddStateChangedListeners);
+ RunFunctionOnGlobal(add_listeners, context, 0, nullptr);
+ }
+
+ bindings_system()->DispatchEventInContext(
+ "idle.onStateChanged", ListValueFromString("['idle']").get(),
+ nullptr, script_context);
+ EXPECT_EQ(
+ "\"idle\"",
+ GetStringPropertyFromObject(context->Global(), context, "newState"));
+ EXPECT_EQ(
+ "true",
+ GetStringPropertyFromObject(context->Global(), context, "didThrow"));
+}
+
// Tests that referencing the same API multiple times returns the same object;
// i.e. chrome.foo === chrome.foo.
TEST_F(NativeExtensionBindingsSystemUnittest, APIObjectsAreEqual) {
« extensions/renderer/api_event_handler_unittest.cc ('K') | « extensions/renderer/event_emitter.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698