| 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/file_util.h" | |
| 6 #include "base/files/file_path.h" | 5 #include "base/files/file_path.h" |
| 7 #include "base/path_service.h" | 6 #include "base/path_service.h" |
| 8 #include "gin/modules/console.h" | 7 #include "gin/modules/console.h" |
| 9 #include "gin/modules/module_registry.h" | 8 #include "gin/modules/module_registry.h" |
| 10 #include "gin/modules/timer.h" | 9 #include "gin/modules/timer.h" |
| 11 #include "gin/test/file_runner.h" | 10 #include "gin/test/file_runner.h" |
| 12 #include "gin/test/gtest.h" | 11 #include "gin/test/gtest.h" |
| 13 #include "mojo/bindings/js/core.h" | 12 #include "mojo/bindings/js/core.h" |
| 14 #include "mojo/common/test/test_utils.h" | |
| 15 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
| 16 | 14 |
| 17 namespace mojo { | 15 namespace mojo { |
| 18 namespace js { | 16 namespace js { |
| 19 namespace { | 17 namespace { |
| 20 | 18 |
| 21 class TestRunnerDelegate : public gin::FileRunnerDelegate { | 19 class TestRunnerDelegate : public gin::FileRunnerDelegate { |
| 22 public: | 20 public: |
| 23 TestRunnerDelegate() { | 21 TestRunnerDelegate() { |
| 24 AddBuiltinModule(gin::Console::kModuleName, gin::Console::GetModule); | 22 AddBuiltinModule(gin::Console::kModuleName, gin::Console::GetModule); |
| 25 AddBuiltinModule(Core::kModuleName, Core::GetModule); | 23 AddBuiltinModule(Core::kModuleName, Core::GetModule); |
| 26 } | 24 } |
| 27 | 25 |
| 28 private: | 26 private: |
| 29 DISALLOW_COPY_AND_ASSIGN(TestRunnerDelegate); | 27 DISALLOW_COPY_AND_ASSIGN(TestRunnerDelegate); |
| 30 }; | 28 }; |
| 31 | 29 |
| 32 void RunTest(std::string test, bool run_until_idle) { | 30 void RunTest(std::string test, bool run_until_idle) { |
| 33 base::FilePath path; | 31 base::FilePath path; |
| 34 PathService::Get(base::DIR_SOURCE_ROOT, &path); | 32 PathService::Get(base::DIR_SOURCE_ROOT, &path); |
| 35 path = path.AppendASCII("mojo") | 33 path = path.AppendASCII("mojo") |
| 34 .AppendASCII("public") |
| 35 .AppendASCII("js") |
| 36 .AppendASCII("bindings") | 36 .AppendASCII("bindings") |
| 37 .AppendASCII("js") | |
| 38 .AppendASCII(test); | 37 .AppendASCII(test); |
| 39 TestRunnerDelegate delegate; | 38 TestRunnerDelegate delegate; |
| 40 gin::RunTestFromFile(path, &delegate, run_until_idle); | 39 gin::RunTestFromFile(path, &delegate, run_until_idle); |
| 41 } | 40 } |
| 42 | 41 |
| 43 // TODO(abarth): Should we autogenerate these stubs from GYP? | 42 // TODO(abarth): Should we autogenerate these stubs from GYP? |
| 44 TEST(JSTest, core) { | 43 TEST(JSTest, core) { |
| 45 RunTest("core_unittests.js", true); | 44 RunTest("core_unittests.js", true); |
| 46 } | 45 } |
| 47 | 46 |
| 48 TEST(JSTest, codec) { | 47 TEST(JSTest, codec) { |
| 49 // TODO(yzshen): Remove this check once isolated tests are supported on the | 48 RunTest("codec_unittests.js", true); |
| 50 // Chromium waterfall. (http://crbug.com/351214) | 49 } |
| 51 const base::FilePath test_file_path( | |
| 52 test::GetFilePathForJSResource( | |
| 53 "mojo/public/interfaces/bindings/tests/sample_service.mojom")); | |
| 54 if (!base::PathExists(test_file_path)) { | |
| 55 LOG(WARNING) << "Mojom binding files don't exist. Skipping the test."; | |
| 56 return; | |
| 57 } | |
| 58 | 50 |
| 59 RunTest("codec_unittests.js", true); | 51 TEST(JSTest, validation) { |
| 52 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 |