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(gin::Runner* runner) OVERRIDE { |
| 27 v8::Handle<Object> root = RunnerDelegate::CreateRootObject(runner); |
| 28 root->Set(gin::StringToV8(runner->isolate(), "gtest"), |
| 29 gin::GTestTemplate(runner->isolate())->NewInstance()); |
| 30 return root; |
| 31 } |
| 32 }; |
| 33 |
| 34 void RunTestFromFile(const base::FilePath& path) { |
| 35 EXPECT_TRUE(base::PathExists(path)) << path.LossyDisplayName(); |
| 36 std::string source; |
| 37 EXPECT_TRUE(ReadFileToString(path, &source)); |
| 38 Isolate* isolate = Isolate::GetCurrent(); |
| 39 |
| 40 TestRunnerDelegate delegate; |
| 41 gin::Runner runner(&delegate, isolate); |
| 42 gin::Runner::Scope scope(&runner); |
| 43 |
| 44 v8::TryCatch try_catch; |
| 45 runner.Run(Script::New(gin::StringToV8(isolate, source))); |
| 46 |
| 47 EXPECT_FALSE(try_catch.HasCaught()); |
| 48 } |
| 49 |
| 50 void RunTest(std::string test) { |
| 51 base::FilePath path; |
| 52 PathService::Get(base::DIR_SOURCE_ROOT, &path); |
| 53 path = path.AppendASCII("mojo") |
| 54 .AppendASCII("public") |
| 55 .AppendASCII("bindings") |
| 56 .AppendASCII("js") |
| 57 .AppendASCII(test); |
| 58 RunTestFromFile(path); |
| 59 } |
| 60 |
| 61 // TODO(abarth): Should we autogenerate these stubs from GYP? |
| 62 TEST(Harness, mojo_unittests_js) { |
| 63 RunTest("mojo_unittests.js"); |
| 64 } |
| 65 |
| 66 } // namespace |
| 67 } // namespace js |
| 68 } // namespace mojo |
OLD | NEW |