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 "chrome/test/base/module_system_test.h" | 5 #include "chrome/test/base/module_system_test.h" |
6 | 6 |
7 #include "base/callback.h" | 7 #include "base/callback.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/string_piece.h" | 9 #include "base/string_piece.h" |
10 #include "chrome/renderer/extensions/native_handler.h" | 10 #include "chrome/common/extensions/features/feature.h" |
| 11 #include "chrome/renderer/extensions/object_backed_native_handler.h" |
11 #include "ui/base/resource/resource_bundle.h" | 12 #include "ui/base/resource/resource_bundle.h" |
12 | 13 |
13 #include <map> | 14 #include <map> |
14 #include <string> | 15 #include <string> |
15 | 16 |
| 17 using extensions::ChromeV8Context; |
16 using extensions::ModuleSystem; | 18 using extensions::ModuleSystem; |
17 using extensions::NativeHandler; | 19 using extensions::NativeHandler; |
| 20 using extensions::ObjectBackedNativeHandler; |
18 | 21 |
19 // Native JS functions for doing asserts. | 22 // Native JS functions for doing asserts. |
20 class AssertNatives : public NativeHandler { | 23 class AssertNatives : public ObjectBackedNativeHandler { |
21 public: | 24 public: |
22 explicit AssertNatives(v8::Isolate* isolate) | 25 explicit AssertNatives(v8::Isolate* isolate) |
23 : NativeHandler(isolate), | 26 : ObjectBackedNativeHandler(isolate), |
24 assertion_made_(false), | 27 assertion_made_(false), |
25 failed_(false) { | 28 failed_(false) { |
26 RouteFunction("AssertTrue", base::Bind(&AssertNatives::AssertTrue, | 29 RouteFunction("AssertTrue", base::Bind(&AssertNatives::AssertTrue, |
27 base::Unretained(this))); | 30 base::Unretained(this))); |
28 RouteFunction("AssertFalse", base::Bind(&AssertNatives::AssertFalse, | 31 RouteFunction("AssertFalse", base::Bind(&AssertNatives::AssertFalse, |
29 base::Unretained(this))); | 32 base::Unretained(this))); |
30 } | 33 } |
31 | 34 |
32 bool assertion_made() { return assertion_made_; } | 35 bool assertion_made() { return assertion_made_; } |
33 bool failed() { return failed_; } | 36 bool failed() { return failed_; } |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 virtual void HandleUncaughtException() OVERRIDE { | 84 virtual void HandleUncaughtException() OVERRIDE { |
82 FAIL(); | 85 FAIL(); |
83 } | 86 } |
84 }; | 87 }; |
85 | 88 |
86 ModuleSystemTest::ModuleSystemTest() | 89 ModuleSystemTest::ModuleSystemTest() |
87 : context_(v8::Context::New()), | 90 : context_(v8::Context::New()), |
88 source_map_(new StringSourceMap()), | 91 source_map_(new StringSourceMap()), |
89 should_assertions_be_made_(true) { | 92 should_assertions_be_made_(true) { |
90 context_->Enter(); | 93 context_->Enter(); |
| 94 v8_context_.reset( |
| 95 new ChromeV8Context(context_, |
| 96 NULL, |
| 97 NULL, |
| 98 extensions::Feature::WEB_PAGE_CONTEXT)); |
91 assert_natives_ = new AssertNatives(context_->GetIsolate()); | 99 assert_natives_ = new AssertNatives(context_->GetIsolate()); |
92 module_system_.reset(new ModuleSystem(context_, source_map_.get())); | 100 module_system_.reset(new ModuleSystem(v8_context_.get(), source_map_.get())); |
93 module_system_->RegisterNativeHandler("assert", scoped_ptr<NativeHandler>( | 101 module_system_->RegisterNativeHandler("assert", scoped_ptr<NativeHandler>( |
94 assert_natives_)); | 102 assert_natives_)); |
95 module_system_->set_exception_handler( | 103 module_system_->set_exception_handler( |
96 scoped_ptr<ModuleSystem::ExceptionHandler>(new FailsOnException)); | 104 scoped_ptr<ModuleSystem::ExceptionHandler>(new FailsOnException)); |
97 } | 105 } |
98 | 106 |
99 ModuleSystemTest::~ModuleSystemTest() { | 107 ModuleSystemTest::~ModuleSystemTest() { |
100 module_system_.reset(); | 108 module_system_.reset(); |
101 context_->Exit(); | 109 context_->Exit(); |
102 context_.Dispose(context_->GetIsolate()); | 110 context_.Dispose(context_->GetIsolate()); |
(...skipping 28 matching lines...) Expand all Loading... |
131 should_assertions_be_made_ = false; | 139 should_assertions_be_made_ = false; |
132 } | 140 } |
133 | 141 |
134 v8::Handle<v8::Object> ModuleSystemTest::CreateGlobal(const std::string& name) { | 142 v8::Handle<v8::Object> ModuleSystemTest::CreateGlobal(const std::string& name) { |
135 v8::HandleScope handle_scope; | 143 v8::HandleScope handle_scope; |
136 v8::Handle<v8::Object> object = v8::Object::New(); | 144 v8::Handle<v8::Object> object = v8::Object::New(); |
137 v8::Context::GetCurrent()->Global()->Set(v8::String::New(name.c_str()), | 145 v8::Context::GetCurrent()->Global()->Set(v8::String::New(name.c_str()), |
138 object); | 146 object); |
139 return handle_scope.Close(object); | 147 return handle_scope.Close(object); |
140 } | 148 } |
OLD | NEW |