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

Unified Diff: gin/modules/module_registry_unittest.cc

Issue 373973003: Gin: Allow multiple callers to wait for the same module in ModuleRegistry. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 5 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 side-by-side diff with in-line comments
Download patch
« gin/modules/module_registry.cc ('K') | « gin/modules/module_registry.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: gin/modules/module_registry_unittest.cc
diff --git a/gin/modules/module_registry_unittest.cc b/gin/modules/module_registry_unittest.cc
index 0ffdc0c3dd5242f264a0d826cdeeee803d1121fa..77bf9f1eeca2c141675e369508d205949f29987f 100644
--- a/gin/modules/module_registry_unittest.cc
+++ b/gin/modules/module_registry_unittest.cc
@@ -4,6 +4,7 @@
#include "gin/modules/module_registry.h"
+#include "base/bind.h"
#include "base/message_loop/message_loop.h"
#include "gin/modules/module_registry_observer.h"
#include "gin/modules/module_runner_delegate.h"
@@ -54,6 +55,21 @@ class ModuleRegistryObserverImpl : public ModuleRegistryObserver {
DISALLOW_COPY_AND_ASSIGN(ModuleRegistryObserverImpl);
};
+void NestedCallback(v8::Handle<v8::Value> value) {
+ FAIL() << "Should not be called";
+}
+
+void OnModuleLoaded(TestHelper* helper,
+ v8::Isolate* isolate,
+ int64_t* counter,
+ v8::Handle<v8::Value> value) {
+ ASSERT_TRUE(value->IsNumber());
+ v8::Handle<v8::Integer> int_value = v8::Handle<v8::Integer>::Cast(value);
+ *counter += int_value->Value();
+ ModuleRegistry::From(helper->runner->GetContextHolder()->context())
+ ->LoadModule(isolate, "two", base::Bind(NestedCallback));
+}
+
} // namespace
typedef V8Test ModuleRegistryTest;
@@ -96,4 +112,25 @@ TEST_F(ModuleRegistryTest, ModuleRegistryObserverTest) {
EXPECT_EQ("dep2", observer.dependencies()[1]);
}
+// Verifies that multiple LoadModule calls for the same module are handled
+// correctly.
+TEST_F(ModuleRegistryTest, LoadModuleTest) {
+ TestHelper helper(instance_->isolate());
+ int64_t counter = 0;
+ std::string source =
+ "define('one', [], function() {"
+ " return 1;"
+ "});";
+
+ ModuleRegistry::LoadModuleCallback callback =
+ base::Bind(OnModuleLoaded, &helper, instance_->isolate(), &counter);
+ for (int i = 0; i < 3; i++) {
+ ModuleRegistry::From(helper.runner->GetContextHolder()->context())
+ ->LoadModule(instance_->isolate(), "one", callback);
+ }
+ EXPECT_EQ(0, counter);
+ helper.runner->Run(source, "script");
+ EXPECT_EQ(3, counter);
+}
+
} // namespace gin
« gin/modules/module_registry.cc ('K') | « gin/modules/module_registry.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698