OLD | NEW |
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 "gin/modules/module_registry.h" | 5 #include "gin/modules/module_registry.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
9 #include "gin/modules/module_registry_observer.h" | 9 #include "gin/modules/module_registry_observer.h" |
10 #include "gin/modules/module_runner_delegate.h" | 10 #include "gin/modules/module_runner_delegate.h" |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 const std::vector<std::string>& dependencies() const { return dependencies_; } | 48 const std::vector<std::string>& dependencies() const { return dependencies_; } |
49 | 49 |
50 private: | 50 private: |
51 int did_add_count_; | 51 int did_add_count_; |
52 std::string id_; | 52 std::string id_; |
53 std::vector<std::string> dependencies_; | 53 std::vector<std::string> dependencies_; |
54 | 54 |
55 DISALLOW_COPY_AND_ASSIGN(ModuleRegistryObserverImpl); | 55 DISALLOW_COPY_AND_ASSIGN(ModuleRegistryObserverImpl); |
56 }; | 56 }; |
57 | 57 |
58 void NestedCallback(v8::Handle<v8::Value> value) { | 58 void NestedCallback(v8::Local<v8::Value> value) { |
59 FAIL() << "Should not be called"; | 59 FAIL() << "Should not be called"; |
60 } | 60 } |
61 | 61 |
62 void OnModuleLoaded(TestHelper* helper, | 62 void OnModuleLoaded(TestHelper* helper, |
63 v8::Isolate* isolate, | 63 v8::Isolate* isolate, |
64 int64_t* counter, | 64 int64_t* counter, |
65 v8::Handle<v8::Value> value) { | 65 v8::Local<v8::Value> value) { |
66 ASSERT_TRUE(value->IsNumber()); | 66 ASSERT_TRUE(value->IsNumber()); |
67 v8::Handle<v8::Integer> int_value = v8::Handle<v8::Integer>::Cast(value); | 67 v8::Local<v8::Integer> int_value = v8::Local<v8::Integer>::Cast(value); |
68 *counter += int_value->Value(); | 68 *counter += int_value->Value(); |
69 ModuleRegistry::From(helper->runner->GetContextHolder()->context()) | 69 ModuleRegistry::From(helper->runner->GetContextHolder()->context()) |
70 ->LoadModule(isolate, "two", base::Bind(NestedCallback)); | 70 ->LoadModule(isolate, "two", base::Bind(NestedCallback)); |
71 } | 71 } |
72 | 72 |
73 void OnModuleLoadedNoOp(v8::Handle<v8::Value> value) { | 73 void OnModuleLoadedNoOp(v8::Local<v8::Value> value) { |
74 ASSERT_TRUE(value->IsNumber()); | 74 ASSERT_TRUE(value->IsNumber()); |
75 } | 75 } |
76 | 76 |
77 } // namespace | 77 } // namespace |
78 | 78 |
79 typedef V8Test ModuleRegistryTest; | 79 typedef V8Test ModuleRegistryTest; |
80 | 80 |
81 // Verifies ModuleRegistry is not available after ContextHolder has been | 81 // Verifies ModuleRegistry is not available after ContextHolder has been |
82 // deleted. | 82 // deleted. |
83 TEST_F(ModuleRegistryTest, DestroyedWithContext) { | 83 TEST_F(ModuleRegistryTest, DestroyedWithContext) { |
84 v8::Isolate::Scope isolate_scope(instance_->isolate()); | 84 v8::Isolate::Scope isolate_scope(instance_->isolate()); |
85 v8::HandleScope handle_scope(instance_->isolate()); | 85 v8::HandleScope handle_scope(instance_->isolate()); |
86 v8::Handle<v8::Context> context = v8::Context::New( | 86 v8::Local<v8::Context> context = v8::Context::New( |
87 instance_->isolate(), NULL, v8::Handle<v8::ObjectTemplate>()); | 87 instance_->isolate(), NULL, v8::Local<v8::ObjectTemplate>()); |
88 { | 88 { |
89 ContextHolder context_holder(instance_->isolate()); | 89 ContextHolder context_holder(instance_->isolate()); |
90 context_holder.SetContext(context); | 90 context_holder.SetContext(context); |
91 ModuleRegistry* registry = ModuleRegistry::From(context); | 91 ModuleRegistry* registry = ModuleRegistry::From(context); |
92 EXPECT_TRUE(registry != NULL); | 92 EXPECT_TRUE(registry != NULL); |
93 } | 93 } |
94 ModuleRegistry* registry = ModuleRegistry::From(context); | 94 ModuleRegistry* registry = ModuleRegistry::From(context); |
95 EXPECT_TRUE(registry == NULL); | 95 EXPECT_TRUE(registry == NULL); |
96 } | 96 } |
97 | 97 |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 helper.runner->Run(source, "script"); | 155 helper.runner->Run(source, "script"); |
156 EXPECT_EQ(no_such_module_set, registry->unsatisfied_dependencies()); | 156 EXPECT_EQ(no_such_module_set, registry->unsatisfied_dependencies()); |
157 | 157 |
158 // Should have no effect on the unsatisfied_dependencies set. | 158 // Should have no effect on the unsatisfied_dependencies set. |
159 ModuleRegistry::LoadModuleCallback callback = base::Bind(OnModuleLoadedNoOp); | 159 ModuleRegistry::LoadModuleCallback callback = base::Bind(OnModuleLoadedNoOp); |
160 registry->LoadModule(instance_->isolate(), "one", callback); | 160 registry->LoadModule(instance_->isolate(), "one", callback); |
161 EXPECT_EQ(no_such_module_set, registry->unsatisfied_dependencies()); | 161 EXPECT_EQ(no_such_module_set, registry->unsatisfied_dependencies()); |
162 } | 162 } |
163 | 163 |
164 } // namespace gin | 164 } // namespace gin |
OLD | NEW |