run_apps_js_tests.cc revision effb81e5f8246d0db0270817048dc992db66e9fb
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 "build/build_config.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 "testing/gtest/include/gtest/gtest.h"
17
18namespace mojo {
19namespace js {
20namespace {
21
22class TestRunnerDelegate : public gin::FileRunnerDelegate {
23 public:
24  TestRunnerDelegate() {
25    AddBuiltinModule(gin::Console::kModuleName, gin::Console::GetModule);
26    AddBuiltinModule(Core::kModuleName, Core::GetModule);
27    AddBuiltinModule(gin::TimerModule::kName, gin::TimerModule::GetModule);
28    AddBuiltinModule(apps::MonotonicClock::kModuleName,
29                     apps::MonotonicClock::GetModule);
30    AddBuiltinModule(apps::Threading::kModuleName, apps::Threading::GetModule);
31  }
32
33 private:
34  DISALLOW_COPY_AND_ASSIGN(TestRunnerDelegate);
35};
36
37void RunTest(std::string test, bool run_until_idle) {
38  base::FilePath path;
39  PathService::Get(base::DIR_SOURCE_ROOT, &path);
40  path = path.AppendASCII("mojo")
41             .AppendASCII("apps")
42             .AppendASCII("js")
43             .AppendASCII("bindings")
44             .AppendASCII(test);
45  TestRunnerDelegate delegate;
46  gin::RunTestFromFile(path, &delegate, run_until_idle);
47}
48
49// TODO(abarth): Should we autogenerate these stubs from GYP?
50
51// http://crbug.com/351214
52#if defined(OS_POSIX)
53#define MAYBE_sample_test DISABLED_sample_test
54#else
55#define MAYBE_sample_test sample_test
56#endif
57TEST(JSTest, MAYBE_sample_test) {
58  RunTest("sample_service_unittests.js", true);
59}
60
61// http://crbug.com/351214
62#if defined(OS_POSIX)
63#define MAYBE_connection DISABLED_connection
64#else
65#define MAYBE_connection connection
66#endif
67TEST(JSTest, MAYBE_connection) {
68  RunTest("connection_unittests.js", true);
69}
70
71TEST(JSTest, monotonic_clock) {
72  RunTest("monotonic_clock_unittests.js", false);
73}
74
75}  // namespace
76}  // namespace js
77}  // namespace mojo
78