| 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 9e0941bd9d6c7c1b6c01ebe0bc346f35d0056d3b..0969d7e493b8aab88c5d260ce8c27ddc435b2786 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'"
|
| " }]"
|
| "}";
|
|
|
| @@ -270,6 +273,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);
|
| @@ -416,6 +439,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
|
|
|