fcc42e074fdb6b9477034e6711981efed5bcc34c
[platform/framework/web/crosswalk.git] / src / mojo / bindings / js / run_js_tests.cc
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/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/bindings/js/core.h"
14 #include "mojo/bindings/js/unicode.h"
15 #include "mojo/common/test/test_utils.h"
16 #include "testing/gtest/include/gtest/gtest.h"
17
18 namespace mojo {
19 namespace js {
20 namespace {
21
22 class TestRunnerDelegate : public gin::FileRunnerDelegate {
23  public:
24   TestRunnerDelegate() {
25     AddBuiltinModule(gin::Console::kModuleName, gin::Console::GetModule);
26     AddBuiltinModule(Core::kModuleName, Core::GetModule);
27     AddBuiltinModule(Unicode::kModuleName, Unicode::GetModule);
28   }
29
30  private:
31   DISALLOW_COPY_AND_ASSIGN(TestRunnerDelegate);
32 };
33
34 void RunTest(std::string test, bool run_until_idle) {
35   base::FilePath path;
36   PathService::Get(base::DIR_SOURCE_ROOT, &path);
37   path = path.AppendASCII("mojo")
38              .AppendASCII("bindings")
39              .AppendASCII("js")
40              .AppendASCII(test);
41   TestRunnerDelegate delegate;
42   gin::RunTestFromFile(path, &delegate, run_until_idle);
43 }
44
45 // TODO(abarth): Should we autogenerate these stubs from GYP?
46 TEST(JSTest, core) {
47   RunTest("core_unittests.js", true);
48 }
49
50 TEST(JSTest, codec) {
51   // TODO(yzshen): Remove this check once isolated tests are supported on the
52   // Chromium waterfall. (http://crbug.com/351214)
53   const base::FilePath test_file_path(
54       test::GetFilePathForJSResource(
55           "mojo/public/interfaces/bindings/tests/sample_service.mojom"));
56   if (!base::PathExists(test_file_path)) {
57     LOG(WARNING) << "Mojom binding files don't exist. Skipping the test.";
58     return;
59   }
60
61   RunTest("codec_unittests.js", true);
62 }
63
64 }  // namespace
65 }  // namespace js
66 }  // namespace mojo