| OLD | NEW |
| 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 Loading... |
| 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 |
| OLD | NEW |