OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/test/base/module_system_test.h" | |
7 #include "extensions/renderer/module_system.h" | 6 #include "extensions/renderer/module_system.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 // TODO(cduvall/kalman): Put this file in extensions namespace. | 10 namespace extensions { |
11 using extensions::ModuleSystem; | |
12 using extensions::NativeHandler; | |
13 using extensions::ObjectBackedNativeHandler; | |
14 | 11 |
15 class CounterNatives : public ObjectBackedNativeHandler { | 12 class CounterNatives : public ObjectBackedNativeHandler { |
16 public: | 13 public: |
17 explicit CounterNatives(extensions::ChromeV8Context* context) | 14 explicit CounterNatives(ScriptContext* context) |
18 : ObjectBackedNativeHandler(context), counter_(0) { | 15 : ObjectBackedNativeHandler(context), counter_(0) { |
19 RouteFunction("Get", base::Bind(&CounterNatives::Get, | 16 RouteFunction("Get", |
20 base::Unretained(this))); | 17 base::Bind(&CounterNatives::Get, base::Unretained(this))); |
21 RouteFunction("Increment", base::Bind(&CounterNatives::Increment, | 18 RouteFunction( |
22 base::Unretained(this))); | 19 "Increment", |
| 20 base::Bind(&CounterNatives::Increment, base::Unretained(this))); |
23 } | 21 } |
24 | 22 |
25 void Get(const v8::FunctionCallbackInfo<v8::Value>& args) { | 23 void Get(const v8::FunctionCallbackInfo<v8::Value>& args) { |
26 args.GetReturnValue().Set(static_cast<int32_t>(counter_)); | 24 args.GetReturnValue().Set(static_cast<int32_t>(counter_)); |
27 } | 25 } |
28 | 26 |
29 void Increment(const v8::FunctionCallbackInfo<v8::Value>& args) { | 27 void Increment(const v8::FunctionCallbackInfo<v8::Value>& args) { |
30 counter_++; | 28 counter_++; |
31 } | 29 } |
32 | 30 |
33 private: | 31 private: |
34 int counter_; | 32 int counter_; |
35 }; | 33 }; |
36 | 34 |
37 class TestExceptionHandler : public ModuleSystem::ExceptionHandler { | 35 class TestExceptionHandler : public ModuleSystem::ExceptionHandler { |
38 public: | 36 public: |
39 TestExceptionHandler() | 37 TestExceptionHandler() : handled_exception_(false) {} |
40 : handled_exception_(false) { | |
41 } | |
42 | 38 |
43 virtual void HandleUncaughtException(const v8::TryCatch& try_catch) OVERRIDE { | 39 virtual void HandleUncaughtException(const v8::TryCatch& try_catch) OVERRIDE { |
44 handled_exception_ = true; | 40 handled_exception_ = true; |
45 } | 41 } |
46 | 42 |
47 bool handled_exception() const { return handled_exception_; } | 43 bool handled_exception() const { return handled_exception_; } |
48 | 44 |
49 private: | 45 private: |
50 bool handled_exception_; | 46 bool handled_exception_; |
51 }; | 47 }; |
(...skipping 428 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
480 " requireNative('assert').AssertTrue(" | 476 " requireNative('assert').AssertTrue(" |
481 " natives.requireAsync('foo') === undefined);" | 477 " natives.requireAsync('foo') === undefined);" |
482 "});"); | 478 "});"); |
483 scoped_ptr<ModuleSystemTestEnvironment> other_env = CreateEnvironment(); | 479 scoped_ptr<ModuleSystemTestEnvironment> other_env = CreateEnvironment(); |
484 gin::ModuleRegistry::From(env()->context()->v8_context())->AddBuiltinModule( | 480 gin::ModuleRegistry::From(env()->context()->v8_context())->AddBuiltinModule( |
485 env()->isolate(), "natives", other_env->module_system()->NewInstance()); | 481 env()->isolate(), "natives", other_env->module_system()->NewInstance()); |
486 other_env->ShutdownModuleSystem(); | 482 other_env->ShutdownModuleSystem(); |
487 env()->module_system()->Require("test"); | 483 env()->module_system()->Require("test"); |
488 RunResolvedPromises(); | 484 RunResolvedPromises(); |
489 } | 485 } |
| 486 |
| 487 } // namespace extensions |
OLD | NEW |