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/strings/string_piece.h" | 9 #include "base/strings/string_piece.h" |
10 #include "chrome/renderer/extensions/object_backed_native_handler.h" | 10 #include "chrome/renderer/extensions/object_backed_native_handler.h" |
11 #include "ui/base/resource/resource_bundle.h" | 11 #include "ui/base/resource/resource_bundle.h" |
12 | 12 |
13 #include <map> | 13 #include <map> |
14 #include <string> | 14 #include <string> |
15 | 15 |
16 using extensions::ModuleSystem; | 16 using extensions::ModuleSystem; |
17 using extensions::NativeHandler; | 17 using extensions::NativeHandler; |
18 using extensions::ObjectBackedNativeHandler; | 18 using extensions::ObjectBackedNativeHandler; |
19 | 19 |
20 // Native JS functions for doing asserts. | 20 // Native JS functions for doing asserts. |
21 class AssertNatives : public ObjectBackedNativeHandler { | 21 class AssertNatives : public ObjectBackedNativeHandler { |
22 public: | 22 public: |
23 explicit AssertNatives(v8::Handle<v8::Context> context) | 23 explicit AssertNatives(extensions::ChromeV8Context* context) |
24 : ObjectBackedNativeHandler(context), | 24 : ObjectBackedNativeHandler(context), |
25 assertion_made_(false), | 25 assertion_made_(false), |
26 failed_(false) { | 26 failed_(false) { |
27 RouteFunction("AssertTrue", base::Bind(&AssertNatives::AssertTrue, | 27 RouteFunction("AssertTrue", base::Bind(&AssertNatives::AssertTrue, |
28 base::Unretained(this))); | 28 base::Unretained(this))); |
29 RouteFunction("AssertFalse", base::Bind(&AssertNatives::AssertFalse, | 29 RouteFunction("AssertFalse", base::Bind(&AssertNatives::AssertFalse, |
30 base::Unretained(this))); | 30 base::Unretained(this))); |
31 } | 31 } |
32 | 32 |
33 bool assertion_made() { return assertion_made_; } | 33 bool assertion_made() { return assertion_made_; } |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
81 public: | 81 public: |
82 virtual void HandleUncaughtException() OVERRIDE { | 82 virtual void HandleUncaughtException() OVERRIDE { |
83 FAIL(); | 83 FAIL(); |
84 } | 84 } |
85 }; | 85 }; |
86 | 86 |
87 ModuleSystemTest::ModuleSystemTest() | 87 ModuleSystemTest::ModuleSystemTest() |
88 : isolate_(v8::Isolate::GetCurrent()), | 88 : isolate_(v8::Isolate::GetCurrent()), |
89 handle_scope_(isolate_), | 89 handle_scope_(isolate_), |
90 context_(v8::Context::New(isolate_)), | 90 context_(v8::Context::New(isolate_)), |
91 chrome_v8_context_( | |
92 new extensions::ChromeV8Context( | |
93 context_.get(), | |
94 reinterpret_cast<WebKit::WebFrame*>(1), | |
95 NULL, | |
96 extensions::Feature::BLESSED_EXTENSION_CONTEXT)), | |
not at google - send to devlin
2013/05/29 15:55:13
let's make it an undefined context type, I want to
marja
2013/05/29 16:56:33
On 2013/05/29 15:55:13, kalman wrote:
> let's make
| |
91 source_map_(new StringSourceMap()), | 97 source_map_(new StringSourceMap()), |
92 should_assertions_be_made_(true) { | 98 should_assertions_be_made_(true) { |
93 context_->Enter(); | 99 context_->Enter(); |
94 assert_natives_ = new AssertNatives(context_.get()); | 100 assert_natives_ = new AssertNatives(chrome_v8_context_.get()); |
95 module_system_.reset(new ModuleSystem(context_.get(), source_map_.get())); | 101 module_system_.reset( |
102 new ModuleSystem(chrome_v8_context_.get(), source_map_.get())); | |
96 module_system_->RegisterNativeHandler("assert", scoped_ptr<NativeHandler>( | 103 module_system_->RegisterNativeHandler("assert", scoped_ptr<NativeHandler>( |
97 assert_natives_)); | 104 assert_natives_)); |
98 module_system_->SetExceptionHandlerForTest( | 105 module_system_->SetExceptionHandlerForTest( |
99 scoped_ptr<ModuleSystem::ExceptionHandler>(new FailsOnException)); | 106 scoped_ptr<ModuleSystem::ExceptionHandler>(new FailsOnException)); |
100 } | 107 } |
101 | 108 |
102 ModuleSystemTest::~ModuleSystemTest() { | 109 ModuleSystemTest::~ModuleSystemTest() { |
103 module_system_.reset(); | 110 module_system_.reset(); |
104 context_->Exit(); | 111 context_->Exit(); |
105 } | 112 } |
(...skipping 27 matching lines...) Expand all Loading... | |
133 should_assertions_be_made_ = false; | 140 should_assertions_be_made_ = false; |
134 } | 141 } |
135 | 142 |
136 v8::Handle<v8::Object> ModuleSystemTest::CreateGlobal(const std::string& name) { | 143 v8::Handle<v8::Object> ModuleSystemTest::CreateGlobal(const std::string& name) { |
137 v8::HandleScope handle_scope; | 144 v8::HandleScope handle_scope; |
138 v8::Handle<v8::Object> object = v8::Object::New(); | 145 v8::Handle<v8::Object> object = v8::Object::New(); |
139 v8::Context::GetCurrent()->Global()->Set(v8::String::New(name.c_str()), | 146 v8::Context::GetCurrent()->Global()->Set(v8::String::New(name.c_str()), |
140 object); | 147 object); |
141 return handle_scope.Close(object); | 148 return handle_scope.Close(object); |
142 } | 149 } |
OLD | NEW |