| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "base/file_util.h" | |
| 6 #include "base/path_service.h" | |
| 7 #include "gin/converter.h" | |
| 8 #include "gin/runner.h" | |
| 9 #include "gin/test/gtest.h" | |
| 10 #include "mojo/public/bindings/js/runner_delegate.h" | |
| 11 #include "testing/gtest/include/gtest/gtest.h" | |
| 12 | |
| 13 using v8::Isolate; | |
| 14 using v8::Object; | |
| 15 using v8::Script; | |
| 16 using v8::Value; | |
| 17 | |
| 18 namespace mojo { | |
| 19 namespace js { | |
| 20 namespace { | |
| 21 | |
| 22 class TestRunnerDelegate : public RunnerDelegate { | |
| 23 public: | |
| 24 virtual ~TestRunnerDelegate() {} | |
| 25 | |
| 26 virtual v8::Handle<Object> CreateRootObject( | |
| 27 gin::Runner* runner) MOJO_OVERRIDE { | |
| 28 v8::Handle<Object> root = RunnerDelegate::CreateRootObject(runner); | |
| 29 root->Set(gin::StringToSymbol(runner->isolate(), "gtest"), | |
| 30 gin::GetGTestTemplate(runner->isolate())->NewInstance()); | |
| 31 return root; | |
| 32 } | |
| 33 }; | |
| 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 | |
| 41 void RunTestFromFile(const base::FilePath& path) { | |
| 42 EXPECT_TRUE(base::PathExists(path)) << path.LossyDisplayName(); | |
| 43 std::string source; | |
| 44 EXPECT_TRUE(ReadFileToString(path, &source)); | |
| 45 Isolate* isolate = Isolate::GetCurrent(); | |
| 46 | |
| 47 TestRunnerDelegate delegate; | |
| 48 gin::Runner runner(&delegate, isolate); | |
| 49 gin::Runner::Scope scope(&runner); | |
| 50 | |
| 51 v8::TryCatch try_catch; | |
| 52 runner.Run(Script::New(gin::StringToV8(isolate, source))); | |
| 53 | |
| 54 EXPECT_FALSE(try_catch.HasCaught()) << GetExceptionInfo(try_catch); | |
| 55 } | |
| 56 | |
| 57 void RunTest(std::string test) { | |
| 58 base::FilePath path; | |
| 59 PathService::Get(base::DIR_SOURCE_ROOT, &path); | |
| 60 path = path.AppendASCII("mojo") | |
| 61 .AppendASCII("public") | |
| 62 .AppendASCII("bindings") | |
| 63 .AppendASCII("js") | |
| 64 .AppendASCII(test); | |
| 65 RunTestFromFile(path); | |
| 66 } | |
| 67 | |
| 68 // TODO(abarth): Should we autogenerate these stubs from GYP? | |
| 69 TEST(Harness, mojo_unittests_js) { | |
| 70 RunTest("mojo_unittests.js"); | |
| 71 } | |
| 72 | |
| 73 TEST(Harness, core_unittests_js) { | |
| 74 RunTest("core_unittests.js"); | |
| 75 } | |
| 76 | |
| 77 } // namespace | |
| 78 } // namespace js | |
| 79 } // namespace mojo | |
| OLD | NEW |