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

Unified Diff: extensions/renderer/api_bindings_system_unittest.cc

Issue 2469593002: [Extensions Bindings] Add Events support (Closed)
Patch Set: . Created 4 years, 1 month 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/api_bindings_system_unittest.cc
diff --git a/extensions/renderer/api_bindings_system_unittest.cc b/extensions/renderer/api_bindings_system_unittest.cc
index 40c86f797408a42570ab163b31cf261c6d8de0ad..d301a48d5fa5e6758d6b295f2953925745edab17 100644
--- a/extensions/renderer/api_bindings_system_unittest.cc
+++ b/extensions/renderer/api_bindings_system_unittest.cc
@@ -53,6 +53,9 @@ const char kAlphaAPISpec[] =
" 'name': 'callback',"
" 'type': 'function'"
" }]"
+ " }],"
+ " 'events': [{"
+ " 'name': 'alphaEvent'"
" }]"
"}";
@@ -266,6 +269,26 @@ TEST_F(APIBindingsSystemTest, TestInitializationAndCallbacks) {
}
{
+ // Test an event registration -> event occurrence.
+ const char kTestCall[] =
+ "obj.alphaEvent.addListener(function() {\n"
+ " this.eventArguments = Array.from(arguments);\n"
+ "});\n";
+ CallFunctionOnObject(context, alpha_api, kTestCall);
+
+ const char kResponseArgsJson[] = "['response',1,{'key':42}]";
+ std::unique_ptr<base::ListValue> expected_args =
+ ListValueFromString(kResponseArgsJson);
+ bindings_system()->FireEventInContext("alpha.alphaEvent", context,
+ *expected_args);
+
+ std::unique_ptr<base::Value> result = GetBaseValuePropertyFromObject(
+ context->Global(), context, "eventArguments");
+ ASSERT_TRUE(result);
+ EXPECT_EQ(ReplaceSingleQuotes(kResponseArgsJson), ValueToString(*result));
+ }
+
+ {
// Test a call -> response on the second API.
const char kTestCall[] = "obj.simpleFunc(2)";
CallFunctionOnObject(context, beta_api, kTestCall);
@@ -412,6 +435,24 @@ TEST_F(APIBindingsSystemTestWithRealAPI, RealAPIs) {
EXPECT_FALSE(last_request());
reset_last_request(); // Just to not pollute future results.
}
+
+ {
+ const char kTestCall[] =
+ "chrome.idle.onStateChanged.addListener(state => {\n"
+ " this.idleState = state;\n"
+ "});\n";
+ ExecuteScript(context, kTestCall);
+ v8::Local<v8::Value> v8_result =
+ GetPropertyFromObject(context->Global(), context, "idleState");
+ EXPECT_TRUE(v8_result->IsUndefined());
+ bindings_system()->FireEventInContext("idle.onStateChanged", context,
+ *ListValueFromString("['active']"));
+
+ std::unique_ptr<base::Value> result =
+ GetBaseValuePropertyFromObject(context->Global(), context, "idleState");
+ ASSERT_TRUE(result);
+ EXPECT_EQ("\"active\"", ValueToString(*result));
+ }
}
} // namespace extensions

Powered by Google App Engine
This is Rietveld 408576698