| 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 "base/files/file_path.h" | 5 #include "base/files/file_path.h" |
| 6 #include "base/path_service.h" | 6 #include "base/path_service.h" |
| 7 #include "gin/modules/console.h" | 7 #include "gin/modules/console.h" |
| 8 #include "gin/modules/module_registry.h" | 8 #include "gin/modules/module_registry.h" |
| 9 #include "gin/modules/timer.h" | 9 #include "gin/modules/timer.h" |
| 10 #include "gin/test/file_runner.h" | 10 #include "gin/test/file_runner.h" |
| 11 #include "gin/test/gtest.h" | 11 #include "gin/test/gtest.h" |
| 12 #include "mojo/edk/js/core.h" | 12 #include "mojo/edk/js/core.h" |
| 13 #include "mojo/edk/js/support.h" | 13 #include "mojo/edk/js/support.h" |
| 14 #include "mojo/public/cpp/environment/environment.h" | 14 #include "mojo/edk/js/threading.h" |
| 15 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
| 16 | 16 |
| 17 namespace mojo { | 17 namespace mojo { |
| 18 namespace js { | 18 namespace js { |
| 19 namespace { | 19 namespace { |
| 20 | 20 |
| 21 class TestRunnerDelegate : public gin::FileRunnerDelegate { | 21 class TestRunnerDelegate : public gin::FileRunnerDelegate { |
| 22 public: | 22 public: |
| 23 TestRunnerDelegate() { | 23 TestRunnerDelegate() { |
| 24 AddBuiltinModule(gin::Console::kModuleName, gin::Console::GetModule); | 24 AddBuiltinModule(gin::Console::kModuleName, gin::Console::GetModule); |
| 25 AddBuiltinModule(Core::kModuleName, Core::GetModule); | 25 AddBuiltinModule(Core::kModuleName, Core::GetModule); |
| 26 AddBuiltinModule(Support::kModuleName, Support::GetModule); | 26 AddBuiltinModule(gin::TimerModule::kName, gin::TimerModule::GetModule); |
| 27 AddBuiltinModule(Threading::kModuleName, Threading::GetModule); |
| 27 } | 28 } |
| 28 | |
| 29 private: | 29 private: |
| 30 DISALLOW_COPY_AND_ASSIGN(TestRunnerDelegate); | 30 DISALLOW_COPY_AND_ASSIGN(TestRunnerDelegate); |
| 31 }; | 31 }; |
| 32 | 32 |
| 33 void RunTest(std::string test, bool run_until_idle) { | 33 void RunTest(std::string test, bool addSupportModule) { |
| 34 Environment env; | |
| 35 base::FilePath path; | 34 base::FilePath path; |
| 36 PathService::Get(base::DIR_SOURCE_ROOT, &path); | 35 PathService::Get(base::DIR_SOURCE_ROOT, &path); |
| 37 path = path.AppendASCII("mojo") | 36 path = path.AppendASCII("mojo") |
| 38 .AppendASCII("public") | 37 .AppendASCII("edk") |
| 39 .AppendASCII("js") | 38 .AppendASCII("js") |
| 39 .AppendASCII("tests") |
| 40 .AppendASCII(test); | 40 .AppendASCII(test); |
| 41 TestRunnerDelegate delegate; | 41 TestRunnerDelegate delegate; |
| 42 gin::RunTestFromFile(path, &delegate, run_until_idle); | 42 if (addSupportModule) |
| 43 delegate.AddBuiltinModule(Support::kModuleName, Support::GetModule); |
| 44 gin::RunTestFromFile(path, &delegate, true); |
| 43 } | 45 } |
| 44 | 46 |
| 45 // TODO(abarth): Should we autogenerate these stubs from GYP? | 47 TEST(JSTest, connection) { |
| 46 TEST(JSTest, core) { | 48 RunTest("connection_tests.js", false); |
| 47 RunTest("core_unittests.js", true); | |
| 48 } | 49 } |
| 49 | 50 |
| 50 TEST(JSTest, codec) { | 51 TEST(JSTest, sample_service) { |
| 51 RunTest("codec_unittests.js", true); | 52 RunTest("sample_service_tests.js", true); |
| 52 } | |
| 53 | |
| 54 TEST(JSTest, struct) { | |
| 55 RunTest("struct_unittests.js", true); | |
| 56 } | |
| 57 | |
| 58 TEST(JSTest, validation) { | |
| 59 RunTest("validation_unittests.js", true); | |
| 60 } | 53 } |
| 61 | 54 |
| 62 } // namespace | 55 } // namespace |
| 63 } // namespace js | 56 } // namespace js |
| 64 } // namespace mojo | 57 } // namespace mojo |
| OLD | NEW |