| 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 "extensions/renderer/api_test_base.h" | 5 #include "extensions/renderer/api_test_base.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/location.h" | 10 #include "base/location.h" |
| 11 #include "base/run_loop.h" | 11 #include "base/run_loop.h" |
| 12 #include "base/single_thread_task_runner.h" | 12 #include "base/single_thread_task_runner.h" |
| 13 #include "base/threading/thread_task_runner_handle.h" | 13 #include "base/threading/thread_task_runner_handle.h" |
| 14 #include "extensions/common/extension_urls.h" | 14 #include "extensions/common/extension_urls.h" |
| 15 #include "extensions/renderer/dispatcher.h" | 15 #include "extensions/renderer/dispatcher.h" |
| 16 #include "extensions/renderer/process_info_native_handler.h" | 16 #include "extensions/renderer/process_info_native_handler.h" |
| 17 #include "gin/converter.h" | 17 #include "gin/converter.h" |
| 18 #include "gin/dictionary.h" | 18 #include "gin/dictionary.h" |
| 19 #include "mojo/edk/js/core.h" | 19 #include "third_party/WebKit/public/web/WebMojoBindings.h" |
| 20 #include "mojo/edk/js/handle.h" | 20 |
| 21 #include "mojo/edk/js/support.h" | 21 namespace gin { |
| 22 #include "mojo/public/cpp/bindings/interface_request.h" | 22 template <> |
| 23 #include "mojo/public/cpp/system/core.h" | 23 struct Converter<mojo::Handle> { |
| 24 static v8::Handle<v8::Value> ToV8(v8::Isolate* isolate, mojo::Handle val) { |
| 25 return blink::WebMojoBindings::wrap(isolate->GetCurrentContext(), |
| 26 mojo::MakeScopedHandle(val)); |
| 27 } |
| 28 }; |
| 29 } // namespace gin |
| 24 | 30 |
| 25 namespace extensions { | 31 namespace extensions { |
| 26 namespace { | 32 namespace { |
| 27 | 33 |
| 34 const char kMojoModuleNameCore[] = "mojo/public/js/core"; |
| 35 const char kMojoModuleNameFrameInterfaces[] = |
| 36 "content/public/renderer/frame_interfaces"; |
| 37 |
| 28 // Natives for the implementation of the unit test version of chrome.test. Calls | 38 // Natives for the implementation of the unit test version of chrome.test. Calls |
| 29 // the provided |quit_closure| when either notifyPass or notifyFail is called. | 39 // the provided |quit_closure| when either notifyPass or notifyFail is called. |
| 30 class TestNatives : public gin::Wrappable<TestNatives> { | 40 class TestNatives : public gin::Wrappable<TestNatives> { |
| 31 public: | 41 public: |
| 32 static gin::Handle<TestNatives> Create(v8::Isolate* isolate, | 42 static gin::Handle<TestNatives> Create(v8::Isolate* isolate, |
| 33 const base::Closure& quit_closure) { | 43 const base::Closure& quit_closure) { |
| 34 return gin::CreateHandle(isolate, new TestNatives(quit_closure)); | 44 return gin::CreateHandle(isolate, new TestNatives(quit_closure)); |
| 35 } | 45 } |
| 36 | 46 |
| 37 gin::ObjectTemplateBuilder GetObjectTemplateBuilder( | 47 gin::ObjectTemplateBuilder GetObjectTemplateBuilder( |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 147 "function() { return [] });"); | 157 "function() { return [] });"); |
| 148 env()->OverrideNativeHandler( | 158 env()->OverrideNativeHandler( |
| 149 "event_natives", | 159 "event_natives", |
| 150 "exports.$set('AttachEvent', function() {});" | 160 "exports.$set('AttachEvent', function() {});" |
| 151 "exports.$set('DetachEvent', function() {});" | 161 "exports.$set('DetachEvent', function() {});" |
| 152 "exports.$set('AttachFilteredEvent', function() {});" | 162 "exports.$set('AttachFilteredEvent', function() {});" |
| 153 "exports.$set('AttachFilteredEvent', function() {});" | 163 "exports.$set('AttachFilteredEvent', function() {});" |
| 154 "exports.$set('MatchAgainstEventFilter', function() { return [] });"); | 164 "exports.$set('MatchAgainstEventFilter', function() { return [] });"); |
| 155 | 165 |
| 156 gin::ModuleRegistry::From(env()->context()->v8_context()) | 166 gin::ModuleRegistry::From(env()->context()->v8_context()) |
| 157 ->AddBuiltinModule(env()->isolate(), mojo::edk::js::Core::kModuleName, | 167 ->AddBuiltinModule( |
| 158 mojo::edk::js::Core::GetModule(env()->isolate())); | 168 env()->isolate(), kMojoModuleNameCore, |
| 159 gin::ModuleRegistry::From(env()->context()->v8_context()) | 169 blink::WebMojoBindings::create(env()->context()->v8_context())); |
| 160 ->AddBuiltinModule(env()->isolate(), mojo::edk::js::Support::kModuleName, | |
| 161 mojo::edk::js::Support::GetModule(env()->isolate())); | |
| 162 gin::Handle<TestInterfaceProvider> interface_provider = | 170 gin::Handle<TestInterfaceProvider> interface_provider = |
| 163 TestInterfaceProvider::Create(env()->isolate()); | 171 TestInterfaceProvider::Create(env()->isolate()); |
| 164 interface_provider_ = interface_provider.get(); | 172 interface_provider_ = interface_provider.get(); |
| 165 gin::ModuleRegistry::From(env()->context()->v8_context()) | 173 gin::ModuleRegistry::From(env()->context()->v8_context()) |
| 166 ->AddBuiltinModule(env()->isolate(), | 174 ->AddBuiltinModule(env()->isolate(), kMojoModuleNameFrameInterfaces, |
| 167 "content/public/renderer/frame_interfaces", | |
| 168 interface_provider.ToV8()); | 175 interface_provider.ToV8()); |
| 169 } | 176 } |
| 170 | 177 |
| 171 void ApiTestEnvironment::InitializeEnvironment() { | 178 void ApiTestEnvironment::InitializeEnvironment() { |
| 172 gin::Dictionary global(env()->isolate(), | 179 gin::Dictionary global(env()->isolate(), |
| 173 env()->context()->v8_context()->Global()); | 180 env()->context()->v8_context()->Global()); |
| 174 gin::Dictionary navigator(gin::Dictionary::CreateEmpty(env()->isolate())); | 181 gin::Dictionary navigator(gin::Dictionary::CreateEmpty(env()->isolate())); |
| 175 navigator.Set("appVersion", base::StringPiece("")); | 182 navigator.Set("appVersion", base::StringPiece("")); |
| 176 global.Set("navigator", navigator); | 183 global.Set("navigator", navigator); |
| 177 gin::Dictionary chrome(gin::Dictionary::CreateEmpty(env()->isolate())); | 184 gin::Dictionary chrome(gin::Dictionary::CreateEmpty(env()->isolate())); |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 230 test_env_.reset(new ApiTestEnvironment(env())); | 237 test_env_.reset(new ApiTestEnvironment(env())); |
| 231 } | 238 } |
| 232 | 239 |
| 233 void ApiTestBase::RunTest(const std::string& file_name, | 240 void ApiTestBase::RunTest(const std::string& file_name, |
| 234 const std::string& test_name) { | 241 const std::string& test_name) { |
| 235 ExpectNoAssertionsMade(); | 242 ExpectNoAssertionsMade(); |
| 236 test_env_->RunTest(file_name, test_name); | 243 test_env_->RunTest(file_name, test_name); |
| 237 } | 244 } |
| 238 | 245 |
| 239 } // namespace extensions | 246 } // namespace extensions |
| OLD | NEW |