• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/test/file_runner.h"
11 #include "gin/test/gtest.h"
12 #include "mojo/edk/js/core.h"
13 #include "mojo/edk/js/support.h"
14 #include "testing/gtest/include/gtest/gtest.h"
15 
16 namespace mojo {
17 namespace edk {
18 namespace js {
19 namespace {
20 
21 class TestRunnerDelegate : public gin::FileRunnerDelegate {
22  public:
TestRunnerDelegate()23   TestRunnerDelegate() {
24     AddBuiltinModule(gin::Console::kModuleName, gin::Console::GetModule);
25     AddBuiltinModule(Core::kModuleName, Core::GetModule);
26     AddBuiltinModule(Support::kModuleName, Support::GetModule);
27   }
28 
29  private:
30   DISALLOW_COPY_AND_ASSIGN(TestRunnerDelegate);
31 };
32 
RunTest(std::string test,bool run_until_idle)33 void RunTest(std::string test, bool run_until_idle) {
34   base::FilePath path;
35   PathService::Get(base::DIR_SOURCE_ROOT, &path);
36   path = path.AppendASCII("mojo")
37              .AppendASCII("public")
38              .AppendASCII("js")
39              .AppendASCII(test);
40   TestRunnerDelegate delegate;
41   gin::RunTestFromFile(path, &delegate, run_until_idle);
42 }
43 
44 // TODO(abarth): Should we autogenerate these stubs from GYP?
TEST(JSTest,core)45 TEST(JSTest, core) {
46   RunTest("core_unittests.js", true);
47 }
48 
TEST(JSTest,codec)49 TEST(JSTest, codec) {
50   RunTest("codec_unittests.js", true);
51 }
52 
TEST(JSTest,struct)53 TEST(JSTest, struct) {
54   RunTest("struct_unittests.js", true);
55 }
56 
TEST(JSTest,union)57 TEST(JSTest, union) {
58   RunTest("union_unittests.js", true);
59 }
60 
TEST(JSTest,validation)61 TEST(JSTest, validation) {
62   RunTest("validation_unittests.js", true);
63 }
64 
65 }  // namespace
66 }  // namespace js
67 }  // namespace edk
68 }  // namespace mojo
69