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.
5 #include "base/file_util.h"
6 #include "base/path_service.h"
7 #include "gin/modules/console.h"
8 #include "gin/modules/module_registry.h"
9 #include "gin/modules/timer.h"
10 #include "gin/test/file_runner.h"
11 #include "gin/test/gtest.h"
12 #include "mojo/apps/js/bindings/core.h"
13 #include "mojo/apps/js/bindings/monotonic_clock.h"
14 #include "mojo/apps/js/bindings/threading.h"
15 #include "testing/gtest/include/gtest/gtest.h"
21 class TestRunnerDelegate : public gin::FileRunnerDelegate {
23 TestRunnerDelegate() {
24 AddBuiltinModule(gin::Console::kModuleName, gin::Console::GetModule);
25 AddBuiltinModule(Core::kModuleName, Core::GetModule);
26 AddBuiltinModule(gin::TimerModule::kName, gin::TimerModule::GetModule);
27 AddBuiltinModule(apps::MonotonicClock::kModuleName,
28 apps::MonotonicClock::GetModule);
29 AddBuiltinModule(apps::Threading::kModuleName, apps::Threading::GetModule);
33 DISALLOW_COPY_AND_ASSIGN(TestRunnerDelegate);
36 void RunTest(std::string test, bool run_until_idle) {
38 PathService::Get(base::DIR_SOURCE_ROOT, &path);
39 path = path.AppendASCII("mojo")
42 .AppendASCII("bindings")
44 TestRunnerDelegate delegate;
45 gin::RunTestFromFile(path, &delegate, run_until_idle);
48 // TODO(abarth): Should we autogenerate these stubs from GYP?
50 RunTest("core_unittests.js", true);
54 RunTest("codec_unittests.js", true);
57 TEST(JSTest, sample_test) {
58 RunTest("sample_service_unittests.js", true);
61 TEST(JSTest, connector) {
62 RunTest("connector_unittests.js", true);
65 TEST(JSTest, monotonic_clock) {
66 RunTest("monotonic_clock_unittests.js", false);