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/files/file_path.h"
7 #include "base/path_service.h"
8 #include "gin/modules/console.h"
9 #include "gin/modules/module_registry.h"
10 #include "gin/modules/timer.h"
11 #include "gin/test/file_runner.h"
12 #include "gin/test/gtest.h"
13 #include "mojo/apps/js/bindings/monotonic_clock.h"
14 #include "mojo/apps/js/bindings/threading.h"
15 #include "mojo/bindings/js/core.h"
16 #include "mojo/bindings/js/unicode.h"
17 #include "mojo/common/test/test_utils.h"
18 #include "testing/gtest/include/gtest/gtest.h"
24 class TestRunnerDelegate : public gin::FileRunnerDelegate {
26 TestRunnerDelegate() {
27 AddBuiltinModule(gin::Console::kModuleName, gin::Console::GetModule);
28 AddBuiltinModule(Core::kModuleName, Core::GetModule);
29 AddBuiltinModule(Unicode::kModuleName, Unicode::GetModule);
30 AddBuiltinModule(gin::TimerModule::kName, gin::TimerModule::GetModule);
31 AddBuiltinModule(apps::MonotonicClock::kModuleName,
32 apps::MonotonicClock::GetModule);
33 AddBuiltinModule(apps::Threading::kModuleName, apps::Threading::GetModule);
37 DISALLOW_COPY_AND_ASSIGN(TestRunnerDelegate);
40 void RunTest(std::string test, bool run_until_idle) {
42 PathService::Get(base::DIR_SOURCE_ROOT, &path);
43 path = path.AppendASCII("mojo")
46 .AppendASCII("bindings")
48 TestRunnerDelegate delegate;
49 gin::RunTestFromFile(path, &delegate, run_until_idle);
52 // TODO(abarth): Should we autogenerate these stubs from GYP?
54 TEST(JSTest, sample_test) {
55 // TODO(yzshen): Remove this check once isolated tests are supported on the
56 // Chromium waterfall. (http://crbug.com/351214)
57 const base::FilePath test_file_path(
58 test::GetFilePathForJSResource(
59 "mojo/public/interfaces/bindings/tests/sample_service.mojom"));
60 if (!base::PathExists(test_file_path)) {
61 LOG(WARNING) << "Mojom binding files don't exist. Skipping the test.";
65 RunTest("sample_service_unittests.js", true);
68 TEST(JSTest, connection) {
69 // TODO(yzshen): Remove this check once isolated tests are supported on the
70 // Chromium waterfall. (http://crbug.com/351214)
71 const base::FilePath test_file_path(
72 test::GetFilePathForJSResource(
73 "mojo/public/interfaces/bindings/tests/sample_service.mojom"));
74 if (!base::PathExists(test_file_path)) {
75 LOG(WARNING) << "Mojom binding files don't exist. Skipping the test.";
79 RunTest("connection_unittests.js", false);
82 TEST(JSTest, monotonic_clock) {
83 RunTest("monotonic_clock_unittests.js", false);