diff options
author | jochen@chromium.org <jochen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-11-19 19:25:12 +0000 |
---|---|---|
committer | jochen@chromium.org <jochen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-11-19 19:25:12 +0000 |
commit | 1b93c237f36e291242da6b03550f2c4a9f1c6d1c (patch) | |
tree | 91bbdda0b6425fc5a2b191ef0777619f5cce8f19 /gin/test | |
parent | 41494f74e8f9dac770129841b73b5251b96b6fe0 (diff) | |
download | chromium_src-1b93c237f36e291242da6b03550f2c4a9f1c6d1c.zip chromium_src-1b93c237f36e291242da6b03550f2c4a9f1c6d1c.tar.gz chromium_src-1b93c237f36e291242da6b03550f2c4a9f1c6d1c.tar.bz2 |
Introduce a Gin class instead of using global functions to control gin
The Gin class holds and controls a v8::Isolate. The isolate is not
entered by default, i.e. before you can use gin for a given Gin
instance, you need to enter the isolate first, e.g. by using a
v8::Isolate::Scope.
This has the advantage that we don't rely on the deprecate default
isolate, and also support having multiple isolates in one process.
BUG=317398
R=abarth@chromium.org
TEST=gin_unittests and mojo_js_bindings_unittests pass
Review URL: https://codereview.chromium.org/76353002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@236029 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'gin/test')
-rw-r--r-- | gin/test/file_runner.cc | 22 | ||||
-rw-r--r-- | gin/test/run_all_unittests.cc | 4 | ||||
-rw-r--r-- | gin/test/v8_test.cc | 22 | ||||
-rw-r--r-- | gin/test/v8_test.h | 9 |
4 files changed, 36 insertions, 21 deletions
diff --git a/gin/test/file_runner.cc b/gin/test/file_runner.cc index dd0ca66..e6b4256 100644 --- a/gin/test/file_runner.cc +++ b/gin/test/file_runner.cc @@ -8,6 +8,7 @@ #include "base/message_loop/message_loop.h" #include "base/path_service.h" #include "gin/converter.h" +#include "gin/gin.h" #include "gin/modules/module_registry.h" #include "gin/test/gtest.h" #include "gin/try_catch.h" @@ -46,17 +47,20 @@ void RunTestFromFile(const base::FilePath& path, FileRunnerDelegate* delegate) { base::MessageLoop message_loop; - gin::Runner runner(delegate, v8::Isolate::GetCurrent()); - gin::Runner::Scope scope(&runner); - runner.Run(source); + gin::Gin instance; + gin::Runner runner(delegate, instance.isolate()); + { + gin::Runner::Scope scope(&runner); + runner.Run(source); - message_loop.RunUntilIdle(); + message_loop.RunUntilIdle(); - v8::Handle<v8::Value> result = runner.context()->Global()->Get( - StringToSymbol(runner.isolate(), "result")); - std::string result_string; - ASSERT_TRUE(ConvertFromV8(result, &result_string)); - EXPECT_EQ("PASS", result_string); + v8::Handle<v8::Value> result = runner.context()->Global()->Get( + StringToSymbol(runner.isolate(), "result")); + std::string result_string; + ASSERT_TRUE(ConvertFromV8(result, &result_string)); + EXPECT_EQ("PASS", result_string); + } } } // namespace gin diff --git a/gin/test/run_all_unittests.cc b/gin/test/run_all_unittests.cc index c8644ed..cb1c96c 100644 --- a/gin/test/run_all_unittests.cc +++ b/gin/test/run_all_unittests.cc @@ -5,15 +5,13 @@ #include "base/basictypes.h" #include "base/bind.h" #include "base/compiler_specific.h" +#include "base/memory/scoped_ptr.h" #include "base/test/launcher/unit_test_launcher.h" #include "base/test/test_suite.h" -#include "gin/initialize.h" int main(int argc, char** argv) { base::TestSuite test_suite(argc, argv); - gin::Initialize(); - return base::LaunchUnitTests( argc, argv, base::Bind(&base::TestSuite::Run, base::Unretained(&test_suite))); diff --git a/gin/test/v8_test.cc b/gin/test/v8_test.cc index b2c1d5d..b09930e 100644 --- a/gin/test/v8_test.cc +++ b/gin/test/v8_test.cc @@ -4,10 +4,11 @@ #include "gin/test/v8_test.h" +#include "gin/gin.h" + using v8::Context; using v8::Local; using v8::HandleScope; -using v8::Isolate; namespace gin { @@ -18,16 +19,21 @@ V8Test::~V8Test() { } void V8Test::SetUp() { - isolate_ = Isolate::GetCurrent(); - HandleScope handle_scope(isolate_); - context_.Reset(isolate_, Context::New(isolate_)); - Local<Context>::New(isolate_, context_)->Enter(); + instance_.reset(new gin::Gin); + instance_->isolate()->Enter(); + HandleScope handle_scope(instance_->isolate()); + context_.Reset(instance_->isolate(), Context::New(instance_->isolate())); + Local<Context>::New(instance_->isolate(), context_)->Enter(); } void V8Test::TearDown() { - HandleScope handle_scope(isolate_); - Local<Context>::New(isolate_, context_)->Exit(); - context_.Reset(); + { + HandleScope handle_scope(instance_->isolate()); + Local<Context>::New(instance_->isolate(), context_)->Exit(); + context_.Reset(); + } + instance_->isolate()->Exit(); + instance_.reset(); } } // namespace gin diff --git a/gin/test/v8_test.h b/gin/test/v8_test.h index 2b46f24..e7f93a6 100644 --- a/gin/test/v8_test.h +++ b/gin/test/v8_test.h @@ -5,12 +5,16 @@ #ifndef GIN_TEST_V8_TEST_H_ #define GIN_TEST_V8_TEST_H_ +#include "base/basictypes.h" #include "base/compiler_specific.h" +#include "base/memory/scoped_ptr.h" #include "testing/gtest/include/gtest/gtest.h" #include "v8/include/v8.h" namespace gin { +class Gin; + // A base class for tests that use v8. class V8Test : public testing::Test { public: @@ -21,8 +25,11 @@ class V8Test : public testing::Test { virtual void TearDown() OVERRIDE; protected: - v8::Isolate* isolate_; + scoped_ptr<Gin> instance_; v8::Persistent<v8::Context> context_; + + private: + DISALLOW_COPY_AND_ASSIGN(V8Test); }; } // namespace gin |