Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(39)

Side by Side Diff: chrome/test/base/module_system_test.cc

Issue 12313142: Revert 184837 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/renderer/resources/renderer_resources.grd ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/object_backed_native_handler.h" 10 #include "chrome/renderer/extensions/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;
19 18
20 // Native JS functions for doing asserts. 19 // Native JS functions for doing asserts.
21 class AssertNatives : public ObjectBackedNativeHandler { 20 class AssertNatives : public NativeHandler {
22 public: 21 public:
23 explicit AssertNatives(v8::Handle<v8::Context> context) 22 explicit AssertNatives(v8::Isolate* isolate)
24 : ObjectBackedNativeHandler(context), 23 : NativeHandler(isolate),
25 assertion_made_(false), 24 assertion_made_(false),
26 failed_(false) { 25 failed_(false) {
27 RouteFunction("AssertTrue", base::Bind(&AssertNatives::AssertTrue, 26 RouteFunction("AssertTrue", base::Bind(&AssertNatives::AssertTrue,
28 base::Unretained(this))); 27 base::Unretained(this)));
29 RouteFunction("AssertFalse", base::Bind(&AssertNatives::AssertFalse, 28 RouteFunction("AssertFalse", base::Bind(&AssertNatives::AssertFalse,
30 base::Unretained(this))); 29 base::Unretained(this)));
31 } 30 }
32 31
33 bool assertion_made() { return assertion_made_; } 32 bool assertion_made() { return assertion_made_; }
34 bool failed() { return failed_; } 33 bool failed() { return failed_; }
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 virtual void HandleUncaughtException() OVERRIDE { 81 virtual void HandleUncaughtException() OVERRIDE {
83 FAIL(); 82 FAIL();
84 } 83 }
85 }; 84 };
86 85
87 ModuleSystemTest::ModuleSystemTest() 86 ModuleSystemTest::ModuleSystemTest()
88 : context_(v8::Context::New()), 87 : context_(v8::Context::New()),
89 source_map_(new StringSourceMap()), 88 source_map_(new StringSourceMap()),
90 should_assertions_be_made_(true) { 89 should_assertions_be_made_(true) {
91 context_->Enter(); 90 context_->Enter();
92 assert_natives_ = new AssertNatives(context_); 91 assert_natives_ = new AssertNatives(context_->GetIsolate());
93 module_system_.reset(new ModuleSystem(context_, source_map_.get())); 92 module_system_.reset(new ModuleSystem(context_, source_map_.get()));
94 module_system_->RegisterNativeHandler("assert", scoped_ptr<NativeHandler>( 93 module_system_->RegisterNativeHandler("assert", scoped_ptr<NativeHandler>(
95 assert_natives_)); 94 assert_natives_));
96 module_system_->set_exception_handler( 95 module_system_->set_exception_handler(
97 scoped_ptr<ModuleSystem::ExceptionHandler>(new FailsOnException)); 96 scoped_ptr<ModuleSystem::ExceptionHandler>(new FailsOnException));
98 } 97 }
99 98
100 ModuleSystemTest::~ModuleSystemTest() { 99 ModuleSystemTest::~ModuleSystemTest() {
101 module_system_.reset(); 100 module_system_.reset();
102 context_->Exit(); 101 context_->Exit();
103 context_.Dispose(); 102 context_.Dispose(context_->GetIsolate());
104 } 103 }
105 104
106 void ModuleSystemTest::RegisterModule(const std::string& name, 105 void ModuleSystemTest::RegisterModule(const std::string& name,
107 const std::string& code) { 106 const std::string& code) {
108 source_map_->RegisterModule(name, code); 107 source_map_->RegisterModule(name, code);
109 } 108 }
110 109
111 void ModuleSystemTest::RegisterModule(const std::string& name, 110 void ModuleSystemTest::RegisterModule(const std::string& name,
112 int resource_id) { 111 int resource_id) {
113 const std::string& code = ResourceBundle::GetSharedInstance(). 112 const std::string& code = ResourceBundle::GetSharedInstance().
(...skipping 18 matching lines...) Expand all
132 should_assertions_be_made_ = false; 131 should_assertions_be_made_ = false;
133 } 132 }
134 133
135 v8::Handle<v8::Object> ModuleSystemTest::CreateGlobal(const std::string& name) { 134 v8::Handle<v8::Object> ModuleSystemTest::CreateGlobal(const std::string& name) {
136 v8::HandleScope handle_scope; 135 v8::HandleScope handle_scope;
137 v8::Handle<v8::Object> object = v8::Object::New(); 136 v8::Handle<v8::Object> object = v8::Object::New();
138 v8::Context::GetCurrent()->Global()->Set(v8::String::New(name.c_str()), 137 v8::Context::GetCurrent()->Global()->Set(v8::String::New(name.c_str()),
139 object); 138 object);
140 return handle_scope.Close(object); 139 return handle_scope.Close(object);
141 } 140 }
OLDNEW
« no previous file with comments | « chrome/renderer/resources/renderer_resources.grd ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698