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
3 // found in the LICENSE file.
4
5 #include "base/files/file_path.h"
6 #include "base/macros.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/edk/js/core.h"
14 #include "mojo/edk/js/support.h"
15 #include "mojo/edk/js/threading.h"
16 #include "testing/gtest/include/gtest/gtest.h"
17
18 namespace mojo {
19 namespace edk {
20 namespace js {
21 namespace {
22
23 class TestRunnerDelegate : public gin::FileRunnerDelegate {
24 public:
TestRunnerDelegate()25 TestRunnerDelegate() {
26 AddBuiltinModule(gin::Console::kModuleName, gin::Console::GetModule);
27 AddBuiltinModule(Core::kModuleName, Core::GetModule);
28 AddBuiltinModule(gin::TimerModule::kName, gin::TimerModule::GetModule);
29 AddBuiltinModule(Threading::kModuleName, Threading::GetModule);
30 AddBuiltinModule(Support::kModuleName, Support::GetModule);
31 }
32 private:
33 DISALLOW_COPY_AND_ASSIGN(TestRunnerDelegate);
34 };
35
RunTest(std::string test)36 void RunTest(std::string test) {
37 base::FilePath path;
38 PathService::Get(base::DIR_SOURCE_ROOT, &path);
39 path = path.AppendASCII("mojo")
40 .AppendASCII("edk")
41 .AppendASCII("js")
42 .AppendASCII("tests")
43 .AppendASCII(test);
44 TestRunnerDelegate delegate;
45 gin::RunTestFromFile(path, &delegate, false);
46 }
47
TEST(JSTest,connection)48 TEST(JSTest, connection) {
49 RunTest("connection_tests.js");
50 }
51
TEST(JSTest,sample_service)52 TEST(JSTest, sample_service) {
53 RunTest("sample_service_tests.js");
54 }
55
56 } // namespace
57 } // namespace js
58 } // namespace edk
59 } // namespace mojo
60