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

Side by Side Diff: extensions/renderer/api_binding_unittest.cc

Issue 2891123002: [Extensions Bindings] Handle updating context permissions (Closed)
Patch Set: Add TODO Created 3 years, 7 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 unified diff | Download patch
OLDNEW
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_binding.h" 5 #include "extensions/renderer/api_binding.h"
6 #include "base/bind.h" 6 #include "base/bind.h"
7 #include "base/memory/ptr_util.h" 7 #include "base/memory/ptr_util.h"
8 #include "base/stl_util.h" 8 #include "base/stl_util.h"
9 #include "base/strings/stringprintf.h" 9 #include "base/strings/stringprintf.h"
10 #include "base/values.h" 10 #include "base/values.h"
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 " 'name': 'intAndCallback'," 62 " 'name': 'intAndCallback',"
63 " 'parameters': [{" 63 " 'parameters': [{"
64 " 'name': 'int'," 64 " 'name': 'int',"
65 " 'type': 'integer'" 65 " 'type': 'integer'"
66 " }, {" 66 " }, {"
67 " 'name': 'callback'," 67 " 'name': 'callback',"
68 " 'type': 'function'" 68 " 'type': 'function'"
69 " }]" 69 " }]"
70 "}]"; 70 "}]";
71 71
72 bool AllowAllAPIs(const std::string& name) { 72 bool AllowAllFeatures(v8::Local<v8::Context> context, const std::string& name) {
73 return true; 73 return true;
74 } 74 }
75 75
76 void OnEventListenersChanged(const std::string& event_name, 76 void OnEventListenersChanged(const std::string& event_name,
77 binding::EventListenersChanged change, 77 binding::EventListenersChanged change,
78 const base::DictionaryValue* filter, 78 const base::DictionaryValue* filter,
79 bool was_manual, 79 bool was_manual,
80 v8::Local<v8::Context> context) {} 80 v8::Local<v8::Context> context) {}
81 81
82 } // namespace 82 } // namespace
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 void SetHooksDelegate( 141 void SetHooksDelegate(
142 std::unique_ptr<APIBindingHooksDelegate> hooks_delegate) { 142 std::unique_ptr<APIBindingHooksDelegate> hooks_delegate) {
143 binding_hooks_delegate_ = std::move(hooks_delegate); 143 binding_hooks_delegate_ = std::move(hooks_delegate);
144 ASSERT_TRUE(binding_hooks_delegate_); 144 ASSERT_TRUE(binding_hooks_delegate_);
145 } 145 }
146 146
147 void SetCreateCustomType(const APIBinding::CreateCustomType& callback) { 147 void SetCreateCustomType(const APIBinding::CreateCustomType& callback) {
148 create_custom_type_ = callback; 148 create_custom_type_ = callback;
149 } 149 }
150 150
151 void SetAvailabilityCallback(
152 const APIBinding::AvailabilityCallback& callback) {
153 availability_callback_ = callback;
154 }
155
151 void InitializeBinding() { 156 void InitializeBinding() {
152 if (!binding_hooks_) { 157 if (!binding_hooks_) {
153 binding_hooks_ = base::MakeUnique<APIBindingHooks>( 158 binding_hooks_ = base::MakeUnique<APIBindingHooks>(
154 kBindingName, binding::RunJSFunctionSync()); 159 kBindingName, binding::RunJSFunctionSync());
155 } 160 }
156 if (binding_hooks_delegate_) 161 if (binding_hooks_delegate_)
157 binding_hooks_->SetDelegate(std::move(binding_hooks_delegate_)); 162 binding_hooks_->SetDelegate(std::move(binding_hooks_delegate_));
163 if (!availability_callback_)
164 availability_callback_ = base::Bind(&AllowAllFeatures);
158 event_handler_ = base::MakeUnique<APIEventHandler>( 165 event_handler_ = base::MakeUnique<APIEventHandler>(
159 base::Bind(&RunFunctionOnGlobalAndIgnoreResult), 166 base::Bind(&RunFunctionOnGlobalAndIgnoreResult),
160 base::Bind(&OnEventListenersChanged)); 167 base::Bind(&OnEventListenersChanged));
161 binding_ = base::MakeUnique<APIBinding>( 168 binding_ = base::MakeUnique<APIBinding>(
162 kBindingName, binding_functions_.get(), binding_types_.get(), 169 kBindingName, binding_functions_.get(), binding_types_.get(),
163 binding_events_.get(), binding_properties_.get(), create_custom_type_, 170 binding_events_.get(), binding_properties_.get(), create_custom_type_,
164 std::move(binding_hooks_), &type_refs_, request_handler_.get(), 171 availability_callback_, std::move(binding_hooks_), &type_refs_,
165 event_handler_.get()); 172 request_handler_.get(), event_handler_.get());
166 EXPECT_EQ(!binding_types_.get(), type_refs_.empty()); 173 EXPECT_EQ(!binding_types_.get(), type_refs_.empty());
167 } 174 }
168 175
169 void ExpectPass(v8::Local<v8::Object> object, 176 void ExpectPass(v8::Local<v8::Object> object,
170 const std::string& script_source, 177 const std::string& script_source,
171 const std::string& expected_json_arguments_single_quotes, 178 const std::string& expected_json_arguments_single_quotes,
172 bool expect_callback) { 179 bool expect_callback) {
173 ExpectPass(MainContext(), object, script_source, 180 ExpectPass(MainContext(), object, script_source,
174 expected_json_arguments_single_quotes, expect_callback); 181 expected_json_arguments_single_quotes, expect_callback);
175 } 182 }
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 std::unique_ptr<APIRequestHandler> request_handler_; 230 std::unique_ptr<APIRequestHandler> request_handler_;
224 APITypeReferenceMap type_refs_; 231 APITypeReferenceMap type_refs_;
225 232
226 std::unique_ptr<base::ListValue> binding_functions_; 233 std::unique_ptr<base::ListValue> binding_functions_;
227 std::unique_ptr<base::ListValue> binding_events_; 234 std::unique_ptr<base::ListValue> binding_events_;
228 std::unique_ptr<base::ListValue> binding_types_; 235 std::unique_ptr<base::ListValue> binding_types_;
229 std::unique_ptr<base::DictionaryValue> binding_properties_; 236 std::unique_ptr<base::DictionaryValue> binding_properties_;
230 std::unique_ptr<APIBindingHooks> binding_hooks_; 237 std::unique_ptr<APIBindingHooks> binding_hooks_;
231 std::unique_ptr<APIBindingHooksDelegate> binding_hooks_delegate_; 238 std::unique_ptr<APIBindingHooksDelegate> binding_hooks_delegate_;
232 APIBinding::CreateCustomType create_custom_type_; 239 APIBinding::CreateCustomType create_custom_type_;
240 APIBinding::AvailabilityCallback availability_callback_;
233 241
234 DISALLOW_COPY_AND_ASSIGN(APIBindingUnittest); 242 DISALLOW_COPY_AND_ASSIGN(APIBindingUnittest);
235 }; 243 };
236 244
237 void APIBindingUnittest::RunTest(v8::Local<v8::Context> context, 245 void APIBindingUnittest::RunTest(v8::Local<v8::Context> context,
238 v8::Local<v8::Object> object, 246 v8::Local<v8::Object> object,
239 const std::string& script_source, 247 const std::string& script_source,
240 bool should_pass, 248 bool should_pass,
241 const std::string& expected_json_arguments, 249 const std::string& expected_json_arguments,
242 bool expect_callback, 250 bool expect_callback,
(...skipping 21 matching lines...) Expand all
264 272
265 last_request_.reset(); 273 last_request_.reset();
266 } 274 }
267 275
268 TEST_F(APIBindingUnittest, TestEmptyAPI) { 276 TEST_F(APIBindingUnittest, TestEmptyAPI) {
269 InitializeBinding(); 277 InitializeBinding();
270 278
271 v8::HandleScope handle_scope(isolate()); 279 v8::HandleScope handle_scope(isolate());
272 v8::Local<v8::Context> context = MainContext(); 280 v8::Local<v8::Context> context = MainContext();
273 281
274 v8::Local<v8::Object> binding_object = 282 v8::Local<v8::Object> binding_object = binding()->CreateInstance(context);
275 binding()->CreateInstance(context, base::Bind(&AllowAllAPIs));
276 EXPECT_EQ( 283 EXPECT_EQ(
277 0u, 284 0u,
278 binding_object->GetOwnPropertyNames(context).ToLocalChecked()->Length()); 285 binding_object->GetOwnPropertyNames(context).ToLocalChecked()->Length());
279 } 286 }
280 287
281 // Tests the basic call -> request flow of the API binding (ensuring that 288 // Tests the basic call -> request flow of the API binding (ensuring that
282 // functions are set up correctly and correctly enforced). 289 // functions are set up correctly and correctly enforced).
283 TEST_F(APIBindingUnittest, TestBasicAPICalls) { 290 TEST_F(APIBindingUnittest, TestBasicAPICalls) {
284 SetFunctions(kFunctions); 291 SetFunctions(kFunctions);
285 InitializeBinding(); 292 InitializeBinding();
286 293
287 v8::HandleScope handle_scope(isolate()); 294 v8::HandleScope handle_scope(isolate());
288 v8::Local<v8::Context> context = MainContext(); 295 v8::Local<v8::Context> context = MainContext();
289 296
290 v8::Local<v8::Object> binding_object = 297 v8::Local<v8::Object> binding_object = binding()->CreateInstance(context);
291 binding()->CreateInstance(context, base::Bind(&AllowAllAPIs));
292 298
293 // Argument parsing is tested primarily in APISignature and ArgumentSpec 299 // Argument parsing is tested primarily in APISignature and ArgumentSpec
294 // tests, so do a few quick sanity checks... 300 // tests, so do a few quick sanity checks...
295 ExpectPass(binding_object, "obj.oneString('foo');", "['foo']", false); 301 ExpectPass(binding_object, "obj.oneString('foo');", "['foo']", false);
296 ExpectFailure( 302 ExpectFailure(
297 binding_object, "obj.oneString(1);", 303 binding_object, "obj.oneString(1);",
298 InvocationError( 304 InvocationError(
299 "test.oneString", "string str", 305 "test.oneString", "string str",
300 ArgumentError("str", InvalidType(kTypeString, kTypeInteger)))); 306 ArgumentError("str", InvalidType(kTypeString, kTypeInteger))));
301 ExpectPass(binding_object, "obj.stringAndInt('foo', 1)", "['foo',1]", false); 307 ExpectPass(binding_object, "obj.stringAndInt('foo', 1)", "['foo',1]", false);
(...skipping 29 matching lines...) Expand all
331 " 'type': 'string'," 337 " 'type': 'string',"
332 " 'enum': [{'name': 'omega'}]" 338 " 'enum': [{'name': 'omega'}]"
333 "}]"; 339 "}]";
334 340
335 SetTypes(kTypes); 341 SetTypes(kTypes);
336 InitializeBinding(); 342 InitializeBinding();
337 343
338 v8::HandleScope handle_scope(isolate()); 344 v8::HandleScope handle_scope(isolate());
339 v8::Local<v8::Context> context = MainContext(); 345 v8::Local<v8::Context> context = MainContext();
340 346
341 v8::Local<v8::Object> binding_object = 347 v8::Local<v8::Object> binding_object = binding()->CreateInstance(context);
342 binding()->CreateInstance(context, base::Bind(&AllowAllAPIs));
343 348
344 const char kExpected[] = 349 const char kExpected[] =
345 "{'ALPHA':'alpha','CAMEL_CASE':'camelCase','HYPHEN_ATED':'Hyphen-ated'," 350 "{'ALPHA':'alpha','CAMEL_CASE':'camelCase','HYPHEN_ATED':'Hyphen-ated',"
346 "'NUMS123':'nums123','SCREAMING':'SCREAMING','_42NUMS':'42nums'}"; 351 "'NUMS123':'nums123','SCREAMING':'SCREAMING','_42NUMS':'42nums'}";
347 EXPECT_EQ(ReplaceSingleQuotes(kExpected), 352 EXPECT_EQ(ReplaceSingleQuotes(kExpected),
348 GetStringPropertyFromObject(binding_object, context, "first")); 353 GetStringPropertyFromObject(binding_object, context, "first"));
349 EXPECT_EQ(ReplaceSingleQuotes("{'OMEGA':'omega'}"), 354 EXPECT_EQ(ReplaceSingleQuotes("{'OMEGA':'omega'}"),
350 GetStringPropertyFromObject(binding_object, context, "last")); 355 GetStringPropertyFromObject(binding_object, context, "last"));
351 } 356 }
352 357
353 // Test that empty enum entries are (unfortunately) allowed. 358 // Test that empty enum entries are (unfortunately) allowed.
354 TEST_F(APIBindingUnittest, EnumWithEmptyEntry) { 359 TEST_F(APIBindingUnittest, EnumWithEmptyEntry) {
355 const char kTypes[] = 360 const char kTypes[] =
356 "[{" 361 "[{"
357 " 'id': 'enumWithEmpty'," 362 " 'id': 'enumWithEmpty',"
358 " 'type': 'string'," 363 " 'type': 'string',"
359 " 'enum': [{'name': ''}, {'name': 'other'}]" 364 " 'enum': [{'name': ''}, {'name': 'other'}]"
360 "}]"; 365 "}]";
361 366
362 SetTypes(kTypes); 367 SetTypes(kTypes);
363 InitializeBinding(); 368 InitializeBinding();
364 369
365 v8::HandleScope handle_scope(isolate()); 370 v8::HandleScope handle_scope(isolate());
366 v8::Local<v8::Context> context = MainContext(); 371 v8::Local<v8::Context> context = MainContext();
367 372
368 v8::Local<v8::Object> binding_object = 373 v8::Local<v8::Object> binding_object = binding()->CreateInstance(context);
369 binding()->CreateInstance(context, base::Bind(&AllowAllAPIs));
370 374
371 EXPECT_EQ( 375 EXPECT_EQ(
372 "{\"\":\"\",\"OTHER\":\"other\"}", 376 "{\"\":\"\",\"OTHER\":\"other\"}",
373 GetStringPropertyFromObject(binding_object, context, "enumWithEmpty")); 377 GetStringPropertyFromObject(binding_object, context, "enumWithEmpty"));
374 } 378 }
375 379
376 // Test that type references are correctly set up in the API. 380 // Test that type references are correctly set up in the API.
377 TEST_F(APIBindingUnittest, TypeRefsTest) { 381 TEST_F(APIBindingUnittest, TypeRefsTest) {
378 const char kTypes[] = 382 const char kTypes[] =
379 "[{" 383 "[{"
(...skipping 26 matching lines...) Expand all
406 SetFunctions(kRefFunctions); 410 SetFunctions(kRefFunctions);
407 SetTypes(kTypes); 411 SetTypes(kTypes);
408 InitializeBinding(); 412 InitializeBinding();
409 EXPECT_EQ(2u, type_refs().size()); 413 EXPECT_EQ(2u, type_refs().size());
410 EXPECT_TRUE(type_refs().GetSpec("refObj")); 414 EXPECT_TRUE(type_refs().GetSpec("refObj"));
411 EXPECT_TRUE(type_refs().GetSpec("refEnum")); 415 EXPECT_TRUE(type_refs().GetSpec("refEnum"));
412 416
413 v8::HandleScope handle_scope(isolate()); 417 v8::HandleScope handle_scope(isolate());
414 v8::Local<v8::Context> context = MainContext(); 418 v8::Local<v8::Context> context = MainContext();
415 419
416 v8::Local<v8::Object> binding_object = 420 v8::Local<v8::Object> binding_object = binding()->CreateInstance(context);
417 binding()->CreateInstance(context, base::Bind(&AllowAllAPIs));
418 421
419 // Parsing in general is tested in APISignature and ArgumentSpec tests, but 422 // Parsing in general is tested in APISignature and ArgumentSpec tests, but
420 // we test that the binding a) correctly finds the definitions, and b) accepts 423 // we test that the binding a) correctly finds the definitions, and b) accepts
421 // properties from the API object. 424 // properties from the API object.
422 ExpectPass(binding_object, "obj.takesRefObj({prop1: 'foo'})", 425 ExpectPass(binding_object, "obj.takesRefObj({prop1: 'foo'})",
423 "[{'prop1':'foo'}]", false); 426 "[{'prop1':'foo'}]", false);
424 ExpectFailure( 427 ExpectFailure(
425 binding_object, "obj.takesRefObj({prop1: 'foo', prop2: 'a'})", 428 binding_object, "obj.takesRefObj({prop1: 'foo', prop2: 'a'})",
426 InvocationError( 429 InvocationError(
427 "test.takesRefObj", "refObj o", 430 "test.takesRefObj", "refObj o",
(...skipping 21 matching lines...) Expand all
449 " 'name': 'restrictedOne'," 452 " 'name': 'restrictedOne',"
450 " 'parameters': []" 453 " 'parameters': []"
451 "}, {" 454 "}, {"
452 " 'name': 'restrictedTwo'," 455 " 'name': 'restrictedTwo',"
453 " 'parameters': []" 456 " 'parameters': []"
454 "}]"; 457 "}]";
455 SetFunctions(kFunctions); 458 SetFunctions(kFunctions);
456 const char kEvents[] = 459 const char kEvents[] =
457 "[{'name': 'allowedEvent'}, {'name': 'restrictedEvent'}]"; 460 "[{'name': 'allowedEvent'}, {'name': 'restrictedEvent'}]";
458 SetEvents(kEvents); 461 SetEvents(kEvents);
459 InitializeBinding(); 462 auto is_available = [](v8::Local<v8::Context> context,
460 463 const std::string& name) {
461 v8::HandleScope handle_scope(isolate());
462 v8::Local<v8::Context> context = MainContext();
463
464 auto is_available = [](const std::string& name) {
465 std::set<std::string> allowed = {"test.allowedOne", "test.allowedTwo", 464 std::set<std::string> allowed = {"test.allowedOne", "test.allowedTwo",
466 "test.allowedEvent"}; 465 "test.allowedEvent"};
467 std::set<std::string> restricted = { 466 std::set<std::string> restricted = {
468 "test.restrictedOne", "test.restrictedTwo", "test.restrictedEvent"}; 467 "test.restrictedOne", "test.restrictedTwo", "test.restrictedEvent"};
469 EXPECT_TRUE(allowed.count(name) || restricted.count(name)) << name; 468 EXPECT_TRUE(allowed.count(name) || restricted.count(name)) << name;
470 return allowed.count(name) != 0; 469 return allowed.count(name) != 0;
471 }; 470 };
471 SetAvailabilityCallback(base::Bind(is_available));
472 472
473 v8::Local<v8::Object> binding_object = 473 InitializeBinding();
474 binding()->CreateInstance(context, base::Bind(is_available)); 474
475 v8::HandleScope handle_scope(isolate());
476 v8::Local<v8::Context> context = MainContext();
477
478 v8::Local<v8::Object> binding_object = binding()->CreateInstance(context);
475 479
476 auto is_defined = [&binding_object, context](const std::string& name) { 480 auto is_defined = [&binding_object, context](const std::string& name) {
477 v8::Local<v8::Value> val = 481 v8::Local<v8::Value> val =
478 GetPropertyFromObject(binding_object, context, name); 482 GetPropertyFromObject(binding_object, context, name);
479 EXPECT_FALSE(val.IsEmpty()); 483 EXPECT_FALSE(val.IsEmpty());
480 return !val->IsUndefined() && !val->IsNull(); 484 return !val->IsUndefined() && !val->IsNull();
481 }; 485 };
482 486
483 EXPECT_TRUE(is_defined("allowedOne")); 487 EXPECT_TRUE(is_defined("allowedOne"));
484 EXPECT_TRUE(is_defined("allowedTwo")); 488 EXPECT_TRUE(is_defined("allowedTwo"));
485 EXPECT_TRUE(is_defined("allowedEvent")); 489 EXPECT_TRUE(is_defined("allowedEvent"));
486 EXPECT_FALSE(is_defined("restrictedOne")); 490 EXPECT_FALSE(is_defined("restrictedOne"));
487 EXPECT_FALSE(is_defined("restrictedTwo")); 491 EXPECT_FALSE(is_defined("restrictedTwo"));
488 EXPECT_FALSE(is_defined("restrictedEvent")); 492 EXPECT_FALSE(is_defined("restrictedEvent"));
489 } 493 }
490 494
491 // Tests that events specified in the API are created as properties of the API 495 // Tests that events specified in the API are created as properties of the API
492 // object. 496 // object.
493 TEST_F(APIBindingUnittest, TestEventCreation) { 497 TEST_F(APIBindingUnittest, TestEventCreation) {
494 SetEvents("[{'name': 'onFoo'}, {'name': 'onBar'}]"); 498 SetEvents("[{'name': 'onFoo'}, {'name': 'onBar'}]");
495 SetFunctions(kFunctions); 499 SetFunctions(kFunctions);
496 InitializeBinding(); 500 InitializeBinding();
497 501
498 v8::HandleScope handle_scope(isolate()); 502 v8::HandleScope handle_scope(isolate());
499 v8::Local<v8::Context> context = MainContext(); 503 v8::Local<v8::Context> context = MainContext();
500 504
501 v8::Local<v8::Object> binding_object = 505 v8::Local<v8::Object> binding_object = binding()->CreateInstance(context);
502 binding()->CreateInstance(context, base::Bind(&AllowAllAPIs));
503 506
504 // Event behavior is tested in the APIEventHandler unittests as well as the 507 // Event behavior is tested in the APIEventHandler unittests as well as the
505 // APIBindingsSystem tests, so we really only need to check that the events 508 // APIBindingsSystem tests, so we really only need to check that the events
506 // are being initialized on the object. 509 // are being initialized on the object.
507 v8::Maybe<bool> has_on_foo = 510 v8::Maybe<bool> has_on_foo =
508 binding_object->Has(context, gin::StringToV8(isolate(), "onFoo")); 511 binding_object->Has(context, gin::StringToV8(isolate(), "onFoo"));
509 EXPECT_TRUE(has_on_foo.IsJust()); 512 EXPECT_TRUE(has_on_foo.IsJust());
510 EXPECT_TRUE(has_on_foo.FromJust()); 513 EXPECT_TRUE(has_on_foo.FromJust());
511 514
512 v8::Maybe<bool> has_on_bar = 515 v8::Maybe<bool> has_on_bar =
(...skipping 16 matching lines...) Expand all
529 " 'properties': {" 532 " 'properties': {"
530 " 'subprop1': { 'value': 'some value', 'type': 'string' }," 533 " 'subprop1': { 'value': 'some value', 'type': 'string' },"
531 " 'subprop2': { 'value': true, 'type': 'boolean' }" 534 " 'subprop2': { 'value': true, 'type': 'boolean' }"
532 " }" 535 " }"
533 " }" 536 " }"
534 "}"); 537 "}");
535 InitializeBinding(); 538 InitializeBinding();
536 539
537 v8::HandleScope handle_scope(isolate()); 540 v8::HandleScope handle_scope(isolate());
538 v8::Local<v8::Context> context = MainContext(); 541 v8::Local<v8::Context> context = MainContext();
539 v8::Local<v8::Object> binding_object = 542 v8::Local<v8::Object> binding_object = binding()->CreateInstance(context);
540 binding()->CreateInstance(context, base::Bind(&AllowAllAPIs));
541 EXPECT_EQ("17", 543 EXPECT_EQ("17",
542 GetStringPropertyFromObject(binding_object, context, "prop1")); 544 GetStringPropertyFromObject(binding_object, context, "prop1"));
543 EXPECT_EQ(R"({"subprop1":"some value","subprop2":true})", 545 EXPECT_EQ(R"({"subprop1":"some value","subprop2":true})",
544 GetStringPropertyFromObject(binding_object, context, "prop2")); 546 GetStringPropertyFromObject(binding_object, context, "prop2"));
545 } 547 }
546 548
547 TEST_F(APIBindingUnittest, TestRefProperties) { 549 TEST_F(APIBindingUnittest, TestRefProperties) {
548 SetProperties( 550 SetProperties(
549 "{" 551 "{"
550 " 'alpha': {" 552 " 'alpha': {"
(...skipping 30 matching lines...) Expand all
581 } 583 }
582 return result; 584 return result;
583 }; 585 };
584 586
585 SetCreateCustomType(base::Bind(create_custom_type)); 587 SetCreateCustomType(base::Bind(create_custom_type));
586 588
587 InitializeBinding(); 589 InitializeBinding();
588 590
589 v8::HandleScope handle_scope(isolate()); 591 v8::HandleScope handle_scope(isolate());
590 v8::Local<v8::Context> context = MainContext(); 592 v8::Local<v8::Context> context = MainContext();
591 v8::Local<v8::Object> binding_object = 593 v8::Local<v8::Object> binding_object = binding()->CreateInstance(context);
592 binding()->CreateInstance(context, base::Bind(&AllowAllAPIs));
593 EXPECT_EQ(R"({"alphaProp":"alphaVal"})", 594 EXPECT_EQ(R"({"alphaProp":"alphaVal"})",
594 GetStringPropertyFromObject(binding_object, context, "alpha")); 595 GetStringPropertyFromObject(binding_object, context, "alpha"));
595 EXPECT_EQ( 596 EXPECT_EQ(
596 R"({"betaProp":"betaVal"})", 597 R"({"betaProp":"betaVal"})",
597 GetStringPropertyFromObject(binding_object, context, "beta")); 598 GetStringPropertyFromObject(binding_object, context, "beta"));
598 } 599 }
599 600
600 TEST_F(APIBindingUnittest, TestDisposedContext) { 601 TEST_F(APIBindingUnittest, TestDisposedContext) {
601 SetFunctions(kFunctions); 602 SetFunctions(kFunctions);
602 InitializeBinding(); 603 InitializeBinding();
603 604
604 v8::HandleScope handle_scope(isolate()); 605 v8::HandleScope handle_scope(isolate());
605 v8::Local<v8::Context> context = MainContext(); 606 v8::Local<v8::Context> context = MainContext();
606 607
607 v8::Local<v8::Object> binding_object = 608 v8::Local<v8::Object> binding_object = binding()->CreateInstance(context);
608 binding()->CreateInstance(context, base::Bind(&AllowAllAPIs));
609 609
610 v8::Local<v8::Function> func = 610 v8::Local<v8::Function> func =
611 FunctionFromString(context, "(function(obj) { obj.oneString('foo'); })"); 611 FunctionFromString(context, "(function(obj) { obj.oneString('foo'); })");
612 v8::Local<v8::Value> argv[] = {binding_object}; 612 v8::Local<v8::Value> argv[] = {binding_object};
613 DisposeContext(context); 613 DisposeContext(context);
614 RunFunction(func, context, arraysize(argv), argv); 614 RunFunction(func, context, arraysize(argv), argv);
615 EXPECT_FALSE(HandlerWasInvoked()); 615 EXPECT_FALSE(HandlerWasInvoked());
616 // This test passes if this does not crash, even under AddressSanitizer 616 // This test passes if this does not crash, even under AddressSanitizer
617 // builds. 617 // builds.
618 } 618 }
619 619
620 TEST_F(APIBindingUnittest, MultipleContexts) { 620 TEST_F(APIBindingUnittest, MultipleContexts) {
621 v8::HandleScope handle_scope(isolate()); 621 v8::HandleScope handle_scope(isolate());
622 v8::Local<v8::Context> context_a = MainContext(); 622 v8::Local<v8::Context> context_a = MainContext();
623 v8::Local<v8::Context> context_b = AddContext(); 623 v8::Local<v8::Context> context_b = AddContext();
624 624
625 SetFunctions(kFunctions); 625 SetFunctions(kFunctions);
626 InitializeBinding(); 626 InitializeBinding();
627 627
628 v8::Local<v8::Object> binding_object_a = 628 v8::Local<v8::Object> binding_object_a = binding()->CreateInstance(context_a);
629 binding()->CreateInstance(context_a, base::Bind(&AllowAllAPIs)); 629 v8::Local<v8::Object> binding_object_b = binding()->CreateInstance(context_b);
630 v8::Local<v8::Object> binding_object_b =
631 binding()->CreateInstance(context_b, base::Bind(&AllowAllAPIs));
632 630
633 ExpectPass(context_a, binding_object_a, "obj.oneString('foo');", "['foo']", 631 ExpectPass(context_a, binding_object_a, "obj.oneString('foo');", "['foo']",
634 false); 632 false);
635 ExpectPass(context_b, binding_object_b, "obj.oneString('foo');", "['foo']", 633 ExpectPass(context_b, binding_object_b, "obj.oneString('foo');", "['foo']",
636 false); 634 false);
637 DisposeContext(context_a); 635 DisposeContext(context_a);
638 ExpectPass(context_b, binding_object_b, "obj.oneString('foo');", "['foo']", 636 ExpectPass(context_b, binding_object_b, "obj.oneString('foo');", "['foo']",
639 false); 637 false);
640 } 638 }
641 639
(...skipping 19 matching lines...) Expand all
661 return result; 659 return result;
662 }; 660 };
663 hooks->AddHandler("test.oneString", base::Bind(hook, &did_call)); 661 hooks->AddHandler("test.oneString", base::Bind(hook, &did_call));
664 SetHooksDelegate(std::move(hooks)); 662 SetHooksDelegate(std::move(hooks));
665 663
666 InitializeBinding(); 664 InitializeBinding();
667 665
668 v8::HandleScope handle_scope(isolate()); 666 v8::HandleScope handle_scope(isolate());
669 v8::Local<v8::Context> context = MainContext(); 667 v8::Local<v8::Context> context = MainContext();
670 668
671 v8::Local<v8::Object> binding_object = 669 v8::Local<v8::Object> binding_object = binding()->CreateInstance(context);
672 binding()->CreateInstance(context, base::Bind(&AllowAllAPIs));
673 670
674 // First try calling the oneString() method, which has a custom hook 671 // First try calling the oneString() method, which has a custom hook
675 // installed. 672 // installed.
676 v8::Local<v8::Function> func = 673 v8::Local<v8::Function> func =
677 FunctionFromString(context, "(function(obj) { obj.oneString('foo'); })"); 674 FunctionFromString(context, "(function(obj) { obj.oneString('foo'); })");
678 v8::Local<v8::Value> args[] = {binding_object}; 675 v8::Local<v8::Value> args[] = {binding_object};
679 RunFunction(func, context, 1, args); 676 RunFunction(func, context, 1, args);
680 EXPECT_TRUE(did_call); 677 EXPECT_TRUE(did_call);
681 678
682 // Other methods, like stringAndInt(), should behave normally. 679 // Other methods, like stringAndInt(), should behave normally.
(...skipping 19 matching lines...) Expand all
702 v8::Local<v8::Function> function = 699 v8::Local<v8::Function> function =
703 FunctionFromString(context, kRegisterHook); 700 FunctionFromString(context, kRegisterHook);
704 v8::Local<v8::Value> args[] = {js_hooks}; 701 v8::Local<v8::Value> args[] = {js_hooks};
705 RunFunctionOnGlobal(function, context, arraysize(args), args); 702 RunFunctionOnGlobal(function, context, arraysize(args), args);
706 } 703 }
707 704
708 SetFunctions(kFunctions); 705 SetFunctions(kFunctions);
709 SetHooks(std::move(hooks)); 706 SetHooks(std::move(hooks));
710 InitializeBinding(); 707 InitializeBinding();
711 708
712 v8::Local<v8::Object> binding_object = 709 v8::Local<v8::Object> binding_object = binding()->CreateInstance(context);
713 binding()->CreateInstance(context, base::Bind(&AllowAllAPIs));
714 710
715 // First try calling with an invalid invocation. An error should be raised and 711 // First try calling with an invalid invocation. An error should be raised and
716 // the hook should never have been called, since the arguments didn't match. 712 // the hook should never have been called, since the arguments didn't match.
717 ExpectFailure( 713 ExpectFailure(
718 binding_object, "obj.oneString(1);", 714 binding_object, "obj.oneString(1);",
719 InvocationError( 715 InvocationError(
720 "test.oneString", "string str", 716 "test.oneString", "string str",
721 ArgumentError("str", InvalidType(kTypeString, kTypeInteger)))); 717 ArgumentError("str", InvalidType(kTypeString, kTypeInteger))));
722 v8::Local<v8::Value> property = 718 v8::Local<v8::Value> property =
723 GetPropertyFromObject(context->Global(), context, "requestArguments"); 719 GetPropertyFromObject(context->Global(), context, "requestArguments");
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
758 "})"; 754 "})";
759 v8::Local<v8::Object> js_hooks = hooks->GetJSHookInterface(context); 755 v8::Local<v8::Object> js_hooks = hooks->GetJSHookInterface(context);
760 v8::Local<v8::Function> function = FunctionFromString(context, kRegisterHook); 756 v8::Local<v8::Function> function = FunctionFromString(context, kRegisterHook);
761 v8::Local<v8::Value> args[] = {js_hooks}; 757 v8::Local<v8::Value> args[] = {js_hooks};
762 RunFunctionOnGlobal(function, context, arraysize(args), args); 758 RunFunctionOnGlobal(function, context, arraysize(args), args);
763 759
764 SetHooks(std::move(hooks)); 760 SetHooks(std::move(hooks));
765 SetFunctions(kFunctions); 761 SetFunctions(kFunctions);
766 InitializeBinding(); 762 InitializeBinding();
767 763
768 v8::Local<v8::Object> binding_object = 764 v8::Local<v8::Object> binding_object = binding()->CreateInstance(context);
769 binding()->CreateInstance(context, base::Bind(&AllowAllAPIs));
770 765
771 // Call the method with a hook. Since the hook updates arguments before 766 // Call the method with a hook. Since the hook updates arguments before
772 // validation, we should be able to pass in invalid arguments and still 767 // validation, we should be able to pass in invalid arguments and still
773 // have the hook called. 768 // have the hook called.
774 ExpectFailure( 769 ExpectFailure(
775 binding_object, "obj.oneString(false);", 770 binding_object, "obj.oneString(false);",
776 InvocationError( 771 InvocationError(
777 "test.oneString", "string str", 772 "test.oneString", "string str",
778 ArgumentError("str", InvalidType(kTypeString, kTypeBoolean)))); 773 ArgumentError("str", InvalidType(kTypeString, kTypeBoolean))));
779 EXPECT_EQ("[false]", GetStringPropertyFromObject( 774 EXPECT_EQ("[false]", GetStringPropertyFromObject(
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
820 v8::Local<v8::Function> function = 815 v8::Local<v8::Function> function =
821 FunctionFromString(context, kRegisterHook); 816 FunctionFromString(context, kRegisterHook);
822 v8::Local<v8::Value> args[] = {js_hooks}; 817 v8::Local<v8::Value> args[] = {js_hooks};
823 RunFunctionOnGlobal(function, context, arraysize(args), args); 818 RunFunctionOnGlobal(function, context, arraysize(args), args);
824 } 819 }
825 820
826 SetHooks(std::move(hooks)); 821 SetHooks(std::move(hooks));
827 SetFunctions(kFunctions); 822 SetFunctions(kFunctions);
828 InitializeBinding(); 823 InitializeBinding();
829 824
830 v8::Local<v8::Object> binding_object = 825 v8::Local<v8::Object> binding_object = binding()->CreateInstance(context);
831 binding()->CreateInstance(context, base::Bind(&AllowAllAPIs));
832 826
833 v8::Local<v8::Function> function = 827 v8::Local<v8::Function> function =
834 FunctionFromString(context, 828 FunctionFromString(context,
835 "(function(obj) { return obj.oneString('ping'); })"); 829 "(function(obj) { return obj.oneString('ping'); })");
836 v8::Local<v8::Value> args[] = {binding_object}; 830 v8::Local<v8::Value> args[] = {binding_object};
837 RunFunctionAndExpectError(function, context, v8::Undefined(isolate()), 831 RunFunctionAndExpectError(function, context, v8::Undefined(isolate()),
838 arraysize(args), args, 832 arraysize(args), args,
839 "Uncaught Error: Custom Hook Error"); 833 "Uncaught Error: Custom Hook Error");
840 834
841 // Other methods, like stringAndInt(), should behave normally. 835 // Other methods, like stringAndInt(), should behave normally.
(...skipping 20 matching lines...) Expand all
862 v8::Local<v8::Function> function = 856 v8::Local<v8::Function> function =
863 FunctionFromString(context, kRegisterHook); 857 FunctionFromString(context, kRegisterHook);
864 v8::Local<v8::Value> args[] = {js_hooks}; 858 v8::Local<v8::Value> args[] = {js_hooks};
865 RunFunctionOnGlobal(function, context, arraysize(args), args); 859 RunFunctionOnGlobal(function, context, arraysize(args), args);
866 } 860 }
867 861
868 SetHooks(std::move(hooks)); 862 SetHooks(std::move(hooks));
869 SetFunctions(kFunctions); 863 SetFunctions(kFunctions);
870 InitializeBinding(); 864 InitializeBinding();
871 865
872 v8::Local<v8::Object> binding_object = 866 v8::Local<v8::Object> binding_object = binding()->CreateInstance(context);
873 binding()->CreateInstance(context, base::Bind(&AllowAllAPIs));
874 867
875 v8::Local<v8::Function> function = 868 v8::Local<v8::Function> function =
876 FunctionFromString(context, 869 FunctionFromString(context,
877 "(function(obj) { return obj.oneString('ping'); })"); 870 "(function(obj) { return obj.oneString('ping'); })");
878 v8::Local<v8::Value> args[] = {binding_object}; 871 v8::Local<v8::Value> args[] = {binding_object};
879 v8::Local<v8::Value> result = 872 v8::Local<v8::Value> result =
880 RunFunction(function, context, arraysize(args), args); 873 RunFunction(function, context, arraysize(args), args);
881 ASSERT_FALSE(result.IsEmpty()); 874 ASSERT_FALSE(result.IsEmpty());
882 std::unique_ptr<base::Value> json_result = V8ToBaseValue(result, context); 875 std::unique_ptr<base::Value> json_result = V8ToBaseValue(result, context);
883 ASSERT_TRUE(json_result); 876 ASSERT_TRUE(json_result);
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
923 v8::Local<v8::Function> function = 916 v8::Local<v8::Function> function =
924 FunctionFromString(context, kRegisterHook); 917 FunctionFromString(context, kRegisterHook);
925 v8::Local<v8::Value> args[] = {js_hooks}; 918 v8::Local<v8::Value> args[] = {js_hooks};
926 RunFunctionOnGlobal(function, context, arraysize(args), args); 919 RunFunctionOnGlobal(function, context, arraysize(args), args);
927 } 920 }
928 921
929 SetHooks(std::move(hooks)); 922 SetHooks(std::move(hooks));
930 SetFunctions(kFunctions); 923 SetFunctions(kFunctions);
931 InitializeBinding(); 924 InitializeBinding();
932 925
933 v8::Local<v8::Object> binding_object = 926 v8::Local<v8::Object> binding_object = binding()->CreateInstance(context);
934 binding()->CreateInstance(context, base::Bind(&AllowAllAPIs));
935 927
936 v8::Local<v8::Function> function = 928 v8::Local<v8::Function> function =
937 FunctionFromString(context, 929 FunctionFromString(context,
938 "(function(obj) { return obj.oneString('ping'); })"); 930 "(function(obj) { return obj.oneString('ping'); })");
939 v8::Local<v8::Value> args[] = {binding_object}; 931 v8::Local<v8::Value> args[] = {binding_object};
940 RunFunctionAndExpectError(function, context, v8::Undefined(isolate()), 932 RunFunctionAndExpectError(function, context, v8::Undefined(isolate()),
941 arraysize(args), args, 933 arraysize(args), args,
942 "Uncaught Error: Custom Hook Error"); 934 "Uncaught Error: Custom Hook Error");
943 } 935 }
944 936
(...skipping 28 matching lines...) Expand all
973 result.return_value = 965 result.return_value =
974 gin::StringToV8(context->GetIsolate(), arg_value + " pong"); 966 gin::StringToV8(context->GetIsolate(), arg_value + " pong");
975 return result; 967 return result;
976 }; 968 };
977 hooks->AddHandler("test.oneString", base::Bind(hook, &did_call)); 969 hooks->AddHandler("test.oneString", base::Bind(hook, &did_call));
978 970
979 SetHooksDelegate(std::move(hooks)); 971 SetHooksDelegate(std::move(hooks));
980 SetFunctions(kFunctions); 972 SetFunctions(kFunctions);
981 InitializeBinding(); 973 InitializeBinding();
982 974
983 v8::Local<v8::Object> binding_object = 975 v8::Local<v8::Object> binding_object = binding()->CreateInstance(context);
984 binding()->CreateInstance(context, base::Bind(&AllowAllAPIs));
985 976
986 { 977 {
987 // Test an invocation that we expect to throw an exception. 978 // Test an invocation that we expect to throw an exception.
988 v8::Local<v8::Function> function = 979 v8::Local<v8::Function> function =
989 FunctionFromString( 980 FunctionFromString(
990 context, "(function(obj) { return obj.oneString('throw'); })"); 981 context, "(function(obj) { return obj.oneString('throw'); })");
991 v8::Local<v8::Value> args[] = {binding_object}; 982 v8::Local<v8::Value> args[] = {binding_object};
992 RunFunctionAndExpectError(function, context, v8::Undefined(isolate()), 983 RunFunctionAndExpectError(function, context, v8::Undefined(isolate()),
993 arraysize(args), args, 984 arraysize(args), args,
994 "Uncaught Error: Custom Hook Error"); 985 "Uncaught Error: Custom Hook Error");
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
1029 v8::Local<v8::Function> function = 1020 v8::Local<v8::Function> function =
1030 FunctionFromString(context, kRegisterHook); 1021 FunctionFromString(context, kRegisterHook);
1031 v8::Local<v8::Value> args[] = {js_hooks}; 1022 v8::Local<v8::Value> args[] = {js_hooks};
1032 RunFunctionOnGlobal(function, context, arraysize(args), args); 1023 RunFunctionOnGlobal(function, context, arraysize(args), args);
1033 } 1024 }
1034 1025
1035 SetHooks(std::move(hooks)); 1026 SetHooks(std::move(hooks));
1036 SetFunctions(kFunctions); 1027 SetFunctions(kFunctions);
1037 InitializeBinding(); 1028 InitializeBinding();
1038 1029
1039 v8::Local<v8::Object> binding_object = 1030 v8::Local<v8::Object> binding_object = binding()->CreateInstance(context);
1040 binding()->CreateInstance(context, base::Bind(&AllowAllAPIs));
1041 1031
1042 // Try calling the method with an invalid signature. Since it's invalid, we 1032 // Try calling the method with an invalid signature. Since it's invalid, we
1043 // should never enter the hook. 1033 // should never enter the hook.
1044 ExpectFailure( 1034 ExpectFailure(
1045 binding_object, "obj.oneString(false);", 1035 binding_object, "obj.oneString(false);",
1046 InvocationError( 1036 InvocationError(
1047 "test.oneString", "string str", 1037 "test.oneString", "string str",
1048 ArgumentError("str", InvalidType(kTypeString, kTypeBoolean)))); 1038 ArgumentError("str", InvalidType(kTypeString, kTypeBoolean))));
1049 EXPECT_EQ("undefined", GetStringPropertyFromObject( 1039 EXPECT_EQ("undefined", GetStringPropertyFromObject(
1050 context->Global(), context, "requestArguments")); 1040 context->Global(), context, "requestArguments"));
(...skipping 30 matching lines...) Expand all
1081 v8::Local<v8::Function> function = 1071 v8::Local<v8::Function> function =
1082 FunctionFromString(context, kRegisterHook); 1072 FunctionFromString(context, kRegisterHook);
1083 v8::Local<v8::Value> args[] = {js_hooks}; 1073 v8::Local<v8::Value> args[] = {js_hooks};
1084 RunFunctionOnGlobal(function, context, arraysize(args), args); 1074 RunFunctionOnGlobal(function, context, arraysize(args), args);
1085 } 1075 }
1086 1076
1087 SetHooks(std::move(hooks)); 1077 SetHooks(std::move(hooks));
1088 SetFunctions(kFunctions); 1078 SetFunctions(kFunctions);
1089 InitializeBinding(); 1079 InitializeBinding();
1090 1080
1091 v8::Local<v8::Object> binding_object = 1081 v8::Local<v8::Object> binding_object = binding()->CreateInstance(context);
1092 binding()->CreateInstance(context, base::Bind(&AllowAllAPIs));
1093 1082
1094 // Call the method with a valid signature. The hook should be entered and 1083 // Call the method with a valid signature. The hook should be entered and
1095 // manipulate the arguments. 1084 // manipulate the arguments.
1096 ExpectPass(binding_object, "obj.oneString('ping');", "[{}]", false); 1085 ExpectPass(binding_object, "obj.oneString('ping');", "[{}]", false);
1097 } 1086 }
1098 1087
1099 // Test that user gestures are properly recorded when calling APIs. 1088 // Test that user gestures are properly recorded when calling APIs.
1100 TEST_F(APIBindingUnittest, TestUserGestures) { 1089 TEST_F(APIBindingUnittest, TestUserGestures) {
1101 SetFunctions(kFunctions); 1090 SetFunctions(kFunctions);
1102 InitializeBinding(); 1091 InitializeBinding();
1103 1092
1104 v8::HandleScope handle_scope(isolate()); 1093 v8::HandleScope handle_scope(isolate());
1105 v8::Local<v8::Context> context = MainContext(); 1094 v8::Local<v8::Context> context = MainContext();
1106 1095
1107 v8::Local<v8::Object> binding_object = 1096 v8::Local<v8::Object> binding_object = binding()->CreateInstance(context);
1108 binding()->CreateInstance(context, base::Bind(&AllowAllAPIs));
1109 1097
1110 v8::Local<v8::Function> function = 1098 v8::Local<v8::Function> function =
1111 FunctionFromString(context, "(function(obj) { obj.oneString('foo');})"); 1099 FunctionFromString(context, "(function(obj) { obj.oneString('foo');})");
1112 ASSERT_FALSE(function.IsEmpty()); 1100 ASSERT_FALSE(function.IsEmpty());
1113 1101
1114 v8::Local<v8::Value> argv[] = {binding_object}; 1102 v8::Local<v8::Value> argv[] = {binding_object};
1115 RunFunction(function, context, arraysize(argv), argv); 1103 RunFunction(function, context, arraysize(argv), argv);
1116 ASSERT_TRUE(last_request()); 1104 ASSERT_TRUE(last_request());
1117 EXPECT_FALSE(last_request()->has_user_gesture); 1105 EXPECT_FALSE(last_request()->has_user_gesture);
1118 reset_last_request(); 1106 reset_last_request();
(...skipping 29 matching lines...) Expand all
1148 " {'name': 'url', 'type': 'array', 'items': {'type': 'any'}}" 1136 " {'name': 'url', 'type': 'array', 'items': {'type': 'any'}}"
1149 " ]," 1137 " ],"
1150 " 'parameters': []" 1138 " 'parameters': []"
1151 "}]"; 1139 "}]";
1152 SetEvents(kEvents); 1140 SetEvents(kEvents);
1153 InitializeBinding(); 1141 InitializeBinding();
1154 1142
1155 v8::HandleScope handle_scope(isolate()); 1143 v8::HandleScope handle_scope(isolate());
1156 v8::Local<v8::Context> context = MainContext(); 1144 v8::Local<v8::Context> context = MainContext();
1157 1145
1158 v8::Local<v8::Object> binding_object = 1146 v8::Local<v8::Object> binding_object = binding()->CreateInstance(context);
1159 binding()->CreateInstance(context, base::Bind(&AllowAllAPIs));
1160 1147
1161 const char kAddFilteredListener[] = 1148 const char kAddFilteredListener[] =
1162 "(function(evt) {\n" 1149 "(function(evt) {\n"
1163 " evt.addListener(function() {},\n" 1150 " evt.addListener(function() {},\n"
1164 " {url: [{pathContains: 'simple2.html'}]});\n" 1151 " {url: [{pathContains: 'simple2.html'}]});\n"
1165 "})"; 1152 "})";
1166 v8::Local<v8::Function> function = 1153 v8::Local<v8::Function> function =
1167 FunctionFromString(context, kAddFilteredListener); 1154 FunctionFromString(context, kAddFilteredListener);
1168 ASSERT_FALSE(function.IsEmpty()); 1155 ASSERT_FALSE(function.IsEmpty());
1169 1156
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
1202 gin::ConvertToV8(isolate, 42)); 1189 gin::ConvertToV8(isolate, 42));
1203 }; 1190 };
1204 hooks->SetTemplateInitializer(base::Bind(hook)); 1191 hooks->SetTemplateInitializer(base::Bind(hook));
1205 SetHooksDelegate(std::move(hooks)); 1192 SetHooksDelegate(std::move(hooks));
1206 1193
1207 InitializeBinding(); 1194 InitializeBinding();
1208 1195
1209 v8::HandleScope handle_scope(isolate()); 1196 v8::HandleScope handle_scope(isolate());
1210 v8::Local<v8::Context> context = MainContext(); 1197 v8::Local<v8::Context> context = MainContext();
1211 1198
1212 v8::Local<v8::Object> binding_object = 1199 v8::Local<v8::Object> binding_object = binding()->CreateInstance(context);
1213 binding()->CreateInstance(context, base::Bind(&AllowAllAPIs));
1214 1200
1215 // The extra property should be present on the binding object. 1201 // The extra property should be present on the binding object.
1216 EXPECT_EQ("42", GetStringPropertyFromObject(binding_object, context, 1202 EXPECT_EQ("42", GetStringPropertyFromObject(binding_object, context,
1217 "hookedProperty")); 1203 "hookedProperty"));
1218 // Sanity check: other values should still be there. 1204 // Sanity check: other values should still be there.
1219 EXPECT_EQ("function", 1205 EXPECT_EQ("function",
1220 GetStringPropertyFromObject(binding_object, context, "oneString")); 1206 GetStringPropertyFromObject(binding_object, context, "oneString"));
1221 } 1207 }
1222 1208
1223 } // namespace extensions 1209 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698