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

Side by Side Diff: extensions/renderer/module_system_test.cc

Issue 502893002: Fix some leaks and failures under valgrind in JS extensions unit tests. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: SetUp Created 6 years, 3 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
« no previous file with comments | « extensions/renderer/module_system_test.h ('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 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/module_system_test.h" 5 #include "extensions/renderer/module_system_test.h"
6 6
7 #include <map> 7 #include <map>
8 #include <string> 8 #include <string>
9 9
10 #include "base/callback.h" 10 #include "base/callback.h"
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 const std::string& name) { 202 const std::string& name) {
203 v8::EscapableHandleScope handle_scope(isolate_); 203 v8::EscapableHandleScope handle_scope(isolate_);
204 v8::Local<v8::Object> object = v8::Object::New(isolate_); 204 v8::Local<v8::Object> object = v8::Object::New(isolate_);
205 isolate_->GetCurrentContext()->Global()->Set( 205 isolate_->GetCurrentContext()->Global()->Set(
206 v8::String::NewFromUtf8(isolate_, name.c_str()), object); 206 v8::String::NewFromUtf8(isolate_, name.c_str()), object);
207 return handle_scope.Escape(object); 207 return handle_scope.Escape(object);
208 } 208 }
209 209
210 ModuleSystemTest::ModuleSystemTest() 210 ModuleSystemTest::ModuleSystemTest()
211 : isolate_(v8::Isolate::GetCurrent()), 211 : isolate_(v8::Isolate::GetCurrent()),
212 env_(CreateEnvironment()),
213 should_assertions_be_made_(true) { 212 should_assertions_be_made_(true) {
214 } 213 }
215 214
216 ModuleSystemTest::~ModuleSystemTest() { 215 ModuleSystemTest::~ModuleSystemTest() {
217 } 216 }
218 217
218 void ModuleSystemTest::SetUp() {
219 env_ = CreateEnvironment();
220 }
221
219 void ModuleSystemTest::TearDown() { 222 void ModuleSystemTest::TearDown() {
220 // All tests must assert at least once unless otherwise specified. 223 // All tests must assert at least once unless otherwise specified.
221 EXPECT_EQ(should_assertions_be_made_, 224 EXPECT_EQ(should_assertions_be_made_,
222 env_->assert_natives()->assertion_made()); 225 env_->assert_natives()->assertion_made());
223 EXPECT_FALSE(env_->assert_natives()->failed()); 226 EXPECT_FALSE(env_->assert_natives()->failed());
227 env_.reset();
228 v8::HeapStatistics stats;
229 isolate_->GetHeapStatistics(&stats);
230 size_t old_heap_size = 0;
231 // Run the GC until the heap size reaches a steady state to ensure that
232 // all the garbage is collected.
233 while (stats.used_heap_size() != old_heap_size) {
234 old_heap_size = stats.used_heap_size();
235 isolate_->RequestGarbageCollectionForTesting(
236 v8::Isolate::kFullGarbageCollection);
237 isolate_->GetHeapStatistics(&stats);
238 }
224 } 239 }
225 240
226 scoped_ptr<ModuleSystemTestEnvironment> ModuleSystemTest::CreateEnvironment() { 241 scoped_ptr<ModuleSystemTestEnvironment> ModuleSystemTest::CreateEnvironment() {
227 return make_scoped_ptr(new ModuleSystemTestEnvironment(isolate_)); 242 return make_scoped_ptr(new ModuleSystemTestEnvironment(isolate_));
228 } 243 }
229 244
230 void ModuleSystemTest::ExpectNoAssertionsMade() { 245 void ModuleSystemTest::ExpectNoAssertionsMade() {
231 should_assertions_be_made_ = false; 246 should_assertions_be_made_ = false;
232 } 247 }
233 248
234 void ModuleSystemTest::RunResolvedPromises() { 249 void ModuleSystemTest::RunResolvedPromises() {
235 isolate_->RunMicrotasks(); 250 isolate_->RunMicrotasks();
236 } 251 }
237 252
238 } // namespace extensions 253 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/renderer/module_system_test.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698