run_apps_js_tests.cc revision 5c02ac1a9c1b504631c0a3d2b6e737b5d738bae1
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/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" 19 20namespace mojo { 21namespace js { 22namespace { 23 24class TestRunnerDelegate : public gin::FileRunnerDelegate { 25 public: 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); 34 } 35 36 private: 37 DISALLOW_COPY_AND_ASSIGN(TestRunnerDelegate); 38}; 39 40void RunTest(std::string test, bool run_until_idle) { 41 base::FilePath path; 42 PathService::Get(base::DIR_SOURCE_ROOT, &path); 43 path = path.AppendASCII("mojo") 44 .AppendASCII("apps") 45 .AppendASCII("js") 46 .AppendASCII("bindings") 47 .AppendASCII(test); 48 TestRunnerDelegate delegate; 49 gin::RunTestFromFile(path, &delegate, run_until_idle); 50} 51 52// TODO(abarth): Should we autogenerate these stubs from GYP? 53 54TEST(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."; 62 return; 63 } 64 65 RunTest("sample_service_unittests.js", true); 66} 67 68TEST(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."; 76 return; 77 } 78 79 RunTest("connection_unittests.js", false); 80} 81 82TEST(JSTest, monotonic_clock) { 83 RunTest("monotonic_clock_unittests.js", false); 84} 85 86} // namespace 87} // namespace js 88} // namespace mojo 89