| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "base/file_util.h" | 5 #include "base/file_util.h" |
| 6 #include "base/path_service.h" | 6 #include "base/path_service.h" |
| 7 #include "gin/converter.h" | 7 #include "gin/converter.h" |
| 8 #include "gin/runner.h" | 8 #include "gin/runner.h" |
| 9 #include "gin/test/gtest.h" | 9 #include "gin/test/gtest.h" |
| 10 #include "mojo/public/bindings/js/runner_delegate.h" | 10 #include "mojo/public/bindings/js/runner_delegate.h" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 | 25 |
| 26 virtual v8::Handle<Object> CreateRootObject( | 26 virtual v8::Handle<Object> CreateRootObject( |
| 27 gin::Runner* runner) MOJO_OVERRIDE { | 27 gin::Runner* runner) MOJO_OVERRIDE { |
| 28 v8::Handle<Object> root = RunnerDelegate::CreateRootObject(runner); | 28 v8::Handle<Object> root = RunnerDelegate::CreateRootObject(runner); |
| 29 root->Set(gin::StringToSymbol(runner->isolate(), "gtest"), | 29 root->Set(gin::StringToSymbol(runner->isolate(), "gtest"), |
| 30 gin::GetGTestTemplate(runner->isolate())->NewInstance()); | 30 gin::GetGTestTemplate(runner->isolate())->NewInstance()); |
| 31 return root; | 31 return root; |
| 32 } | 32 } |
| 33 }; | 33 }; |
| 34 | 34 |
| 35 std::string GetExceptionInfo(const v8::TryCatch& try_catch) { |
| 36 std::string info; |
| 37 gin::ConvertFromV8(try_catch.Message()->Get(), &info); |
| 38 return info; |
| 39 } |
| 40 |
| 35 void RunTestFromFile(const base::FilePath& path) { | 41 void RunTestFromFile(const base::FilePath& path) { |
| 36 EXPECT_TRUE(base::PathExists(path)) << path.LossyDisplayName(); | 42 EXPECT_TRUE(base::PathExists(path)) << path.LossyDisplayName(); |
| 37 std::string source; | 43 std::string source; |
| 38 EXPECT_TRUE(ReadFileToString(path, &source)); | 44 EXPECT_TRUE(ReadFileToString(path, &source)); |
| 39 Isolate* isolate = Isolate::GetCurrent(); | 45 Isolate* isolate = Isolate::GetCurrent(); |
| 40 | 46 |
| 41 TestRunnerDelegate delegate; | 47 TestRunnerDelegate delegate; |
| 42 gin::Runner runner(&delegate, isolate); | 48 gin::Runner runner(&delegate, isolate); |
| 43 gin::Runner::Scope scope(&runner); | 49 gin::Runner::Scope scope(&runner); |
| 44 | 50 |
| 45 v8::TryCatch try_catch; | 51 v8::TryCatch try_catch; |
| 46 runner.Run(Script::New(gin::StringToV8(isolate, source))); | 52 runner.Run(Script::New(gin::StringToV8(isolate, source))); |
| 47 | 53 |
| 48 EXPECT_FALSE(try_catch.HasCaught()); | 54 EXPECT_FALSE(try_catch.HasCaught()) << GetExceptionInfo(try_catch); |
| 49 } | 55 } |
| 50 | 56 |
| 51 void RunTest(std::string test) { | 57 void RunTest(std::string test) { |
| 52 base::FilePath path; | 58 base::FilePath path; |
| 53 PathService::Get(base::DIR_SOURCE_ROOT, &path); | 59 PathService::Get(base::DIR_SOURCE_ROOT, &path); |
| 54 path = path.AppendASCII("mojo") | 60 path = path.AppendASCII("mojo") |
| 55 .AppendASCII("public") | 61 .AppendASCII("public") |
| 56 .AppendASCII("bindings") | 62 .AppendASCII("bindings") |
| 57 .AppendASCII("js") | 63 .AppendASCII("js") |
| 58 .AppendASCII(test); | 64 .AppendASCII(test); |
| 59 RunTestFromFile(path); | 65 RunTestFromFile(path); |
| 60 } | 66 } |
| 61 | 67 |
| 62 // TODO(abarth): Should we autogenerate these stubs from GYP? | 68 // TODO(abarth): Should we autogenerate these stubs from GYP? |
| 63 TEST(Harness, mojo_unittests_js) { | 69 TEST(Harness, mojo_unittests_js) { |
| 64 RunTest("mojo_unittests.js"); | 70 RunTest("mojo_unittests.js"); |
| 65 } | 71 } |
| 66 | 72 |
| 73 TEST(Harness, core_unittests_js) { |
| 74 RunTest("core_unittests.js"); |
| 75 } |
| 76 |
| 67 } // namespace | 77 } // namespace |
| 68 } // namespace js | 78 } // namespace js |
| 69 } // namespace mojo | 79 } // namespace mojo |
| OLD | NEW |