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

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

Issue 1185443004: extensions: Use V8 Maybe APIs in ModuleSystem (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
« no previous file with comments | « extensions/renderer/module_system_test.cc ('k') | extensions/renderer/v8_helpers.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 16 matching lines...) Expand all
27 void Increment(const v8::FunctionCallbackInfo<v8::Value>& args) { 27 void Increment(const v8::FunctionCallbackInfo<v8::Value>& args) {
28 counter_++; 28 counter_++;
29 } 29 }
30 30
31 private: 31 private:
32 int counter_; 32 int counter_;
33 }; 33 };
34 34
35 class TestExceptionHandler : public ModuleSystem::ExceptionHandler { 35 class TestExceptionHandler : public ModuleSystem::ExceptionHandler {
36 public: 36 public:
37 TestExceptionHandler() : handled_exception_(false) {} 37 TestExceptionHandler()
38 : ModuleSystem::ExceptionHandler(nullptr), handled_exception_(false) {}
38 39
39 void HandleUncaughtException(const v8::TryCatch& try_catch) override { 40 void HandleUncaughtException(const v8::TryCatch& try_catch) override {
40 handled_exception_ = true; 41 handled_exception_ = true;
41 } 42 }
42 43
43 bool handled_exception() const { return handled_exception_; } 44 bool handled_exception() const { return handled_exception_; }
44 45
45 private: 46 private:
46 bool handled_exception_; 47 bool handled_exception_;
47 }; 48 };
(...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after
397 " requireNative('assert').AssertTrue(result == 'pong');" 398 " requireNative('assert').AssertTrue(result == 'pong');"
398 " });" 399 " });"
399 "});"); 400 "});");
400 scoped_ptr<ModuleSystemTestEnvironment> other_env = CreateEnvironment(); 401 scoped_ptr<ModuleSystemTestEnvironment> other_env = CreateEnvironment();
401 other_env->RegisterModule("ping", 402 other_env->RegisterModule("ping",
402 "define('ping', ['natives'], function(natives) {" 403 "define('ping', ['natives'], function(natives) {"
403 " return function() {" 404 " return function() {"
404 " return 'pong';" 405 " return 'pong';"
405 " }" 406 " }"
406 "});"); 407 "});");
407 gin::ModuleRegistry::From(env()->context()->v8_context())->AddBuiltinModule( 408 gin::ModuleRegistry::From(env()->context()->v8_context())
408 env()->isolate(), "natives", other_env->module_system()->NewInstance()); 409 ->AddBuiltinModule(
410 env()->isolate(), "natives",
411 other_env->module_system()->NewInstance());
409 gin::ModuleRegistry::From(other_env->context()->v8_context()) 412 gin::ModuleRegistry::From(other_env->context()->v8_context())
410 ->AddBuiltinModule( 413 ->AddBuiltinModule(
411 env()->isolate(), "natives", env()->module_system()->NewInstance()); 414 env()->isolate(), "natives",
415 env()->module_system()->NewInstance());
412 env()->module_system()->Require("test"); 416 env()->module_system()->Require("test");
413 RunResolvedPromises(); 417 RunResolvedPromises();
414 } 418 }
415 419
416 TEST_F(ModuleSystemTest, TestRequireAsyncBetweenContexts) { 420 TEST_F(ModuleSystemTest, TestRequireAsyncBetweenContexts) {
417 ModuleSystem::NativesEnabledScope natives_enabled_scope( 421 ModuleSystem::NativesEnabledScope natives_enabled_scope(
418 env()->module_system()); 422 env()->module_system());
419 env()->RegisterModule("pong", 423 env()->RegisterModule("pong",
420 "define('pong', [], function() {" 424 "define('pong', [], function() {"
421 " return function() { return 'done'; };" 425 " return function() { return 'done'; };"
422 "});"); 426 "});");
423 env()->RegisterModule( 427 env()->RegisterModule(
424 "test", 428 "test",
425 "requireAsync('natives').then(function(natives) {" 429 "requireAsync('natives').then(function(natives) {"
426 " natives.requireAsync('ping').then(function(ping) {" 430 " natives.requireAsync('ping').then(function(ping) {"
427 " return ping();" 431 " return ping();"
428 " }).then(function(pong) {" 432 " }).then(function(pong) {"
429 " return pong();" 433 " return pong();"
430 " }).then(function(result) {" 434 " }).then(function(result) {"
431 " requireNative('assert').AssertTrue(result == 'done');" 435 " requireNative('assert').AssertTrue(result == 'done');"
432 " });" 436 " });"
433 "});"); 437 "});");
434 scoped_ptr<ModuleSystemTestEnvironment> other_env = CreateEnvironment(); 438 scoped_ptr<ModuleSystemTestEnvironment> other_env = CreateEnvironment();
435 other_env->RegisterModule("ping", 439 other_env->RegisterModule("ping",
436 "define('ping', ['natives'], function(natives) {" 440 "define('ping', ['natives'], function(natives) {"
437 " return function() {" 441 " return function() {"
438 " return natives.requireAsync('pong');" 442 " return natives.requireAsync('pong');"
439 " }" 443 " }"
440 "});"); 444 "});");
441 gin::ModuleRegistry::From(env()->context()->v8_context())->AddBuiltinModule( 445 gin::ModuleRegistry::From(env()->context()->v8_context())
442 env()->isolate(), "natives", other_env->module_system()->NewInstance()); 446 ->AddBuiltinModule(
447 env()->isolate(), "natives",
448 other_env->module_system()->NewInstance());
443 gin::ModuleRegistry::From(other_env->context()->v8_context()) 449 gin::ModuleRegistry::From(other_env->context()->v8_context())
444 ->AddBuiltinModule( 450 ->AddBuiltinModule(
445 env()->isolate(), "natives", env()->module_system()->NewInstance()); 451 env()->isolate(), "natives",
452 env()->module_system()->NewInstance());
446 env()->module_system()->Require("test"); 453 env()->module_system()->Require("test");
447 RunResolvedPromises(); 454 RunResolvedPromises();
448 } 455 }
449 456
450 TEST_F(ModuleSystemTest, TestRequireAsyncFromContextWithNoModuleRegistry) { 457 TEST_F(ModuleSystemTest, TestRequireAsyncFromContextWithNoModuleRegistry) {
451 ModuleSystem::NativesEnabledScope natives_enabled_scope( 458 ModuleSystem::NativesEnabledScope natives_enabled_scope(
452 env()->module_system()); 459 env()->module_system());
453 env()->RegisterModule("test", 460 env()->RegisterModule("test",
454 "requireAsync('natives').then(function(natives) {" 461 "requireAsync('natives').then(function(natives) {"
455 " var AssertTrue = requireNative('assert').AssertTrue;" 462 " var AssertTrue = requireNative('assert').AssertTrue;"
456 " natives.requireAsync('foo').then(function() {" 463 " natives.requireAsync('foo').then(function() {"
457 " AssertTrue(false);" 464 " AssertTrue(false);"
458 " }).catch(function(error) {" 465 " }).catch(function(error) {"
459 " AssertTrue(error.message == " 466 " AssertTrue(error.message == "
460 " 'Extension view no longer exists');" 467 " 'Extension view no longer exists');"
461 " });" 468 " });"
462 "});"); 469 "});");
463 scoped_ptr<ModuleSystemTestEnvironment> other_env = CreateEnvironment(); 470 scoped_ptr<ModuleSystemTestEnvironment> other_env = CreateEnvironment();
464 gin::ModuleRegistry::From(env()->context()->v8_context())->AddBuiltinModule( 471 gin::ModuleRegistry::From(env()->context()->v8_context())
465 env()->isolate(), "natives", other_env->module_system()->NewInstance()); 472 ->AddBuiltinModule(
473 env()->isolate(), "natives",
474 other_env->module_system()->NewInstance());
466 other_env->ShutdownGin(); 475 other_env->ShutdownGin();
467 env()->module_system()->Require("test"); 476 env()->module_system()->Require("test");
468 RunResolvedPromises(); 477 RunResolvedPromises();
469 } 478 }
470 479
471 TEST_F(ModuleSystemTest, TestRequireAsyncFromContextWithNoModuleSystem) { 480 TEST_F(ModuleSystemTest, TestRequireAsyncFromContextWithNoModuleSystem) {
472 ModuleSystem::NativesEnabledScope natives_enabled_scope( 481 ModuleSystem::NativesEnabledScope natives_enabled_scope(
473 env()->module_system()); 482 env()->module_system());
474 env()->RegisterModule("test", 483 env()->RegisterModule("test",
475 "requireAsync('natives').then(function(natives) {" 484 "requireAsync('natives').then(function(natives) {"
476 " requireNative('assert').AssertTrue(" 485 " requireNative('assert').AssertTrue("
477 " natives.requireAsync('foo') === undefined);" 486 " natives.requireAsync('foo') === undefined);"
478 "});"); 487 "});");
479 scoped_ptr<ModuleSystemTestEnvironment> other_env = CreateEnvironment(); 488 scoped_ptr<ModuleSystemTestEnvironment> other_env = CreateEnvironment();
480 gin::ModuleRegistry::From(env()->context()->v8_context())->AddBuiltinModule( 489 gin::ModuleRegistry::From(env()->context()->v8_context())
481 env()->isolate(), "natives", other_env->module_system()->NewInstance()); 490 ->AddBuiltinModule(
491 env()->isolate(), "natives",
492 other_env->module_system()->NewInstance());
482 other_env->ShutdownModuleSystem(); 493 other_env->ShutdownModuleSystem();
483 env()->module_system()->Require("test"); 494 env()->module_system()->Require("test");
484 RunResolvedPromises(); 495 RunResolvedPromises();
485 } 496 }
486 497
487 } // namespace extensions 498 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/renderer/module_system_test.cc ('k') | extensions/renderer/v8_helpers.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698