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

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

Issue 1192763002: extensions: Use V8 Maybe APIs in NativeHandler (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 6 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "base/memory/scoped_ptr.h" 5 #include "base/memory/scoped_ptr.h"
6 #include "extensions/renderer/module_system.h" 6 #include "extensions/renderer/module_system.h"
7 #include "extensions/renderer/module_system_test.h" 7 #include "extensions/renderer/module_system_test.h"
8 #include "gin/modules/module_registry.h" 8 #include "gin/modules/module_registry.h"
9 9
10 namespace extensions { 10 namespace extensions {
(...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after
401 scoped_ptr<ModuleSystemTestEnvironment> other_env = CreateEnvironment(); 401 scoped_ptr<ModuleSystemTestEnvironment> other_env = CreateEnvironment();
402 other_env->RegisterModule("ping", 402 other_env->RegisterModule("ping",
403 "define('ping', ['natives'], function(natives) {" 403 "define('ping', ['natives'], function(natives) {"
404 " return function() {" 404 " return function() {"
405 " return 'pong';" 405 " return 'pong';"
406 " }" 406 " }"
407 "});"); 407 "});");
408 gin::ModuleRegistry::From(env()->context()->v8_context()) 408 gin::ModuleRegistry::From(env()->context()->v8_context())
409 ->AddBuiltinModule( 409 ->AddBuiltinModule(
410 env()->isolate(), "natives", 410 env()->isolate(), "natives",
411 other_env->module_system()->NewInstance()); 411 other_env->module_system()->NewInstance().ToLocalChecked());
412 gin::ModuleRegistry::From(other_env->context()->v8_context()) 412 gin::ModuleRegistry::From(other_env->context()->v8_context())
413 ->AddBuiltinModule( 413 ->AddBuiltinModule(
414 env()->isolate(), "natives", 414 env()->isolate(), "natives",
415 env()->module_system()->NewInstance()); 415 env()->module_system()->NewInstance().ToLocalChecked());
416 env()->module_system()->Require("test"); 416 env()->module_system()->Require("test");
417 RunResolvedPromises(); 417 RunResolvedPromises();
418 } 418 }
419 419
420 TEST_F(ModuleSystemTest, TestRequireAsyncBetweenContexts) { 420 TEST_F(ModuleSystemTest, TestRequireAsyncBetweenContexts) {
421 ModuleSystem::NativesEnabledScope natives_enabled_scope( 421 ModuleSystem::NativesEnabledScope natives_enabled_scope(
422 env()->module_system()); 422 env()->module_system());
423 env()->RegisterModule("pong", 423 env()->RegisterModule("pong",
424 "define('pong', [], function() {" 424 "define('pong', [], function() {"
425 " return function() { return 'done'; };" 425 " return function() { return 'done'; };"
(...skipping 12 matching lines...) Expand all
438 scoped_ptr<ModuleSystemTestEnvironment> other_env = CreateEnvironment(); 438 scoped_ptr<ModuleSystemTestEnvironment> other_env = CreateEnvironment();
439 other_env->RegisterModule("ping", 439 other_env->RegisterModule("ping",
440 "define('ping', ['natives'], function(natives) {" 440 "define('ping', ['natives'], function(natives) {"
441 " return function() {" 441 " return function() {"
442 " return natives.requireAsync('pong');" 442 " return natives.requireAsync('pong');"
443 " }" 443 " }"
444 "});"); 444 "});");
445 gin::ModuleRegistry::From(env()->context()->v8_context()) 445 gin::ModuleRegistry::From(env()->context()->v8_context())
446 ->AddBuiltinModule( 446 ->AddBuiltinModule(
447 env()->isolate(), "natives", 447 env()->isolate(), "natives",
448 other_env->module_system()->NewInstance()); 448 other_env->module_system()->NewInstance().ToLocalChecked());
449 gin::ModuleRegistry::From(other_env->context()->v8_context()) 449 gin::ModuleRegistry::From(other_env->context()->v8_context())
450 ->AddBuiltinModule( 450 ->AddBuiltinModule(
451 env()->isolate(), "natives", 451 env()->isolate(), "natives",
452 env()->module_system()->NewInstance()); 452 env()->module_system()->NewInstance().ToLocalChecked());
453 env()->module_system()->Require("test"); 453 env()->module_system()->Require("test");
454 RunResolvedPromises(); 454 RunResolvedPromises();
455 } 455 }
456 456
457 TEST_F(ModuleSystemTest, TestRequireAsyncFromContextWithNoModuleRegistry) { 457 TEST_F(ModuleSystemTest, TestRequireAsyncFromContextWithNoModuleRegistry) {
458 ModuleSystem::NativesEnabledScope natives_enabled_scope( 458 ModuleSystem::NativesEnabledScope natives_enabled_scope(
459 env()->module_system()); 459 env()->module_system());
460 env()->RegisterModule("test", 460 env()->RegisterModule("test",
461 "requireAsync('natives').then(function(natives) {" 461 "requireAsync('natives').then(function(natives) {"
462 " var AssertTrue = requireNative('assert').AssertTrue;" 462 " var AssertTrue = requireNative('assert').AssertTrue;"
463 " natives.requireAsync('foo').then(function() {" 463 " natives.requireAsync('foo').then(function() {"
464 " AssertTrue(false);" 464 " AssertTrue(false);"
465 " }).catch(function(error) {" 465 " }).catch(function(error) {"
466 " AssertTrue(error.message == " 466 " AssertTrue(error.message == "
467 " 'Extension view no longer exists');" 467 " 'Extension view no longer exists');"
468 " });" 468 " });"
469 "});"); 469 "});");
470 scoped_ptr<ModuleSystemTestEnvironment> other_env = CreateEnvironment(); 470 scoped_ptr<ModuleSystemTestEnvironment> other_env = CreateEnvironment();
471 gin::ModuleRegistry::From(env()->context()->v8_context()) 471 gin::ModuleRegistry::From(env()->context()->v8_context())
472 ->AddBuiltinModule( 472 ->AddBuiltinModule(
473 env()->isolate(), "natives", 473 env()->isolate(), "natives",
474 other_env->module_system()->NewInstance()); 474 other_env->module_system()->NewInstance().ToLocalChecked());
475 other_env->ShutdownGin(); 475 other_env->ShutdownGin();
476 env()->module_system()->Require("test"); 476 env()->module_system()->Require("test");
477 RunResolvedPromises(); 477 RunResolvedPromises();
478 } 478 }
479 479
480 TEST_F(ModuleSystemTest, TestRequireAsyncFromContextWithNoModuleSystem) { 480 TEST_F(ModuleSystemTest, TestRequireAsyncFromContextWithNoModuleSystem) {
481 ModuleSystem::NativesEnabledScope natives_enabled_scope( 481 ModuleSystem::NativesEnabledScope natives_enabled_scope(
482 env()->module_system()); 482 env()->module_system());
483 env()->RegisterModule("test", 483 env()->RegisterModule("test",
484 "requireAsync('natives').then(function(natives) {" 484 "requireAsync('natives').then(function(natives) {"
485 " requireNative('assert').AssertTrue(" 485 " requireNative('assert').AssertTrue("
486 " natives.requireAsync('foo') === undefined);" 486 " natives.requireAsync('foo') === undefined);"
487 "});"); 487 "});");
488 scoped_ptr<ModuleSystemTestEnvironment> other_env = CreateEnvironment(); 488 scoped_ptr<ModuleSystemTestEnvironment> other_env = CreateEnvironment();
489 gin::ModuleRegistry::From(env()->context()->v8_context()) 489 gin::ModuleRegistry::From(env()->context()->v8_context())
490 ->AddBuiltinModule( 490 ->AddBuiltinModule(
491 env()->isolate(), "natives", 491 env()->isolate(), "natives",
492 other_env->module_system()->NewInstance()); 492 other_env->module_system()->NewInstance().ToLocalChecked());
493 other_env->ShutdownModuleSystem(); 493 other_env->ShutdownModuleSystem();
494 env()->module_system()->Require("test"); 494 env()->module_system()->Require("test");
495 RunResolvedPromises(); 495 RunResolvedPromises();
496 } 496 }
497 497
498 } // namespace extensions 498 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698