OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "extensions/renderer/api_bindings_system.h" | 5 #include "extensions/renderer/api_bindings_system.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/macros.h" | 8 #include "base/macros.h" |
9 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
11 #include "base/strings/stringprintf.h" | 11 #include "base/strings/stringprintf.h" |
12 #include "base/values.h" | 12 #include "base/values.h" |
| 13 #include "extensions/common/event_filtering_info.h" |
13 #include "extensions/common/extension_api.h" | 14 #include "extensions/common/extension_api.h" |
14 #include "extensions/renderer/api_binding.h" | 15 #include "extensions/renderer/api_binding.h" |
15 #include "extensions/renderer/api_binding_hooks.h" | 16 #include "extensions/renderer/api_binding_hooks.h" |
16 #include "extensions/renderer/api_binding_test_util.h" | 17 #include "extensions/renderer/api_binding_test_util.h" |
17 #include "extensions/renderer/api_binding_types.h" | 18 #include "extensions/renderer/api_binding_types.h" |
18 #include "extensions/renderer/api_bindings_system_unittest.h" | 19 #include "extensions/renderer/api_bindings_system_unittest.h" |
19 #include "gin/arguments.h" | 20 #include "gin/arguments.h" |
20 #include "gin/converter.h" | 21 #include "gin/converter.h" |
21 #include "gin/try_catch.h" | 22 #include "gin/try_catch.h" |
22 | 23 |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
151 void APIBindingsSystemTest::OnAPIRequest( | 152 void APIBindingsSystemTest::OnAPIRequest( |
152 std::unique_ptr<APIRequestHandler::Request> request, | 153 std::unique_ptr<APIRequestHandler::Request> request, |
153 v8::Local<v8::Context> context) { | 154 v8::Local<v8::Context> context) { |
154 ASSERT_FALSE(last_request_); | 155 ASSERT_FALSE(last_request_); |
155 last_request_ = std::move(request); | 156 last_request_ = std::move(request); |
156 } | 157 } |
157 | 158 |
158 void APIBindingsSystemTest::OnEventListenersChanged( | 159 void APIBindingsSystemTest::OnEventListenersChanged( |
159 const std::string& event_name, | 160 const std::string& event_name, |
160 binding::EventListenersChanged changed, | 161 binding::EventListenersChanged changed, |
| 162 const base::DictionaryValue* filter, |
161 v8::Local<v8::Context> context) {} | 163 v8::Local<v8::Context> context) {} |
162 | 164 |
163 void APIBindingsSystemTest::ValidateLastRequest( | 165 void APIBindingsSystemTest::ValidateLastRequest( |
164 const std::string& expected_name, | 166 const std::string& expected_name, |
165 const std::string& expected_arguments) { | 167 const std::string& expected_arguments) { |
166 ASSERT_TRUE(last_request()); | 168 ASSERT_TRUE(last_request()); |
167 // Note that even if no arguments are provided by the API call, we should | 169 // Note that even if no arguments are provided by the API call, we should |
168 // have an empty list. | 170 // have an empty list. |
169 ASSERT_TRUE(last_request()->arguments); | 171 ASSERT_TRUE(last_request()->arguments); |
170 EXPECT_EQ(expected_name, last_request()->method_name); | 172 EXPECT_EQ(expected_name, last_request()->method_name); |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
260 const char kTestCall[] = | 262 const char kTestCall[] = |
261 "obj.alphaEvent.addListener(function() {\n" | 263 "obj.alphaEvent.addListener(function() {\n" |
262 " this.eventArguments = Array.from(arguments);\n" | 264 " this.eventArguments = Array.from(arguments);\n" |
263 "});\n"; | 265 "});\n"; |
264 CallFunctionOnObject(context, alpha_api, kTestCall); | 266 CallFunctionOnObject(context, alpha_api, kTestCall); |
265 | 267 |
266 const char kResponseArgsJson[] = "['response',1,{'key':42}]"; | 268 const char kResponseArgsJson[] = "['response',1,{'key':42}]"; |
267 std::unique_ptr<base::ListValue> expected_args = | 269 std::unique_ptr<base::ListValue> expected_args = |
268 ListValueFromString(kResponseArgsJson); | 270 ListValueFromString(kResponseArgsJson); |
269 bindings_system()->FireEventInContext("alpha.alphaEvent", context, | 271 bindings_system()->FireEventInContext("alpha.alphaEvent", context, |
270 *expected_args); | 272 *expected_args, EventFilteringInfo()); |
271 | 273 |
272 EXPECT_EQ(ReplaceSingleQuotes(kResponseArgsJson), | 274 EXPECT_EQ(ReplaceSingleQuotes(kResponseArgsJson), |
273 GetStringPropertyFromObject(context->Global(), context, | 275 GetStringPropertyFromObject(context->Global(), context, |
274 "eventArguments")); | 276 "eventArguments")); |
275 } | 277 } |
276 | 278 |
277 { | 279 { |
278 // Test a call -> response on the second API. | 280 // Test a call -> response on the second API. |
279 const char kTestCall[] = "obj.simpleFunc(2)"; | 281 const char kTestCall[] = "obj.simpleFunc(2)"; |
280 CallFunctionOnObject(context, beta_api, kTestCall); | 282 CallFunctionOnObject(context, beta_api, kTestCall); |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
410 { | 412 { |
411 // Test a simple call -> response. | 413 // Test a simple call -> response. |
412 const char kTestCall[] = "obj.functionWithExternalRef({prop1: 'foo'});"; | 414 const char kTestCall[] = "obj.functionWithExternalRef({prop1: 'foo'});"; |
413 CallFunctionOnObject(context, gamma_api, kTestCall); | 415 CallFunctionOnObject(context, gamma_api, kTestCall); |
414 ValidateLastRequest("gamma.functionWithExternalRef", "[{'prop1':'foo'}]"); | 416 ValidateLastRequest("gamma.functionWithExternalRef", "[{'prop1':'foo'}]"); |
415 reset_last_request(); | 417 reset_last_request(); |
416 } | 418 } |
417 } | 419 } |
418 | 420 |
419 } // namespace extensions | 421 } // namespace extensions |
OLD | NEW |