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.
5 var apiFeatures = chrome.test.getApiFeatures();
7 // Returns a list of all chrome.foo.bar API paths available to an app.
8 function getApiPaths() {
10 var apiDefinitions = chrome.test.getApiDefinitions();
11 apiDefinitions.forEach(function(module) {
12 var namespace = module.namespace;
13 var apiFeature = apiFeatures[namespace];
14 if (Array.isArray(apiFeature))
15 apiFeature = apiFeatures[namespace][0];
17 // Skip internal APIs.
18 if (apiFeature.internal)
21 // Get the API functions and events.
22 [module.functions, module.events].forEach(function(section) {
23 if (typeof(section) == "undefined")
25 section.forEach(function(entry) {
26 apiPaths.push(namespace + "." + entry.name);
30 // Get the API properties.
31 if (module.properties) {
32 Object.getOwnPropertyNames(module.properties).forEach(function(propName) {
33 apiPaths.push(namespace + "." + propName);
40 // Tests whether all parts of an API path can be accessed. The path is a
41 // namespace or function/property/event etc. within a namespace, and is
43 function testPath(path) {
44 var parts = path.split('.');
47 for (var i = 0; i < parts.length; i++) {
48 // Touch this component of the path. This will die if an API does not have
49 // a schema registered.
50 module = module[parts[i]];
52 // The component should be defined unless it is lastError, which depends on
53 // there being an error.
54 if (typeof(module) == "undefined" && path != "runtime.lastError")
61 // Run over all API path strings and ensure each path is defined.
63 getApiPaths().forEach(function(path) {
64 if (!testPath(path)) {
69 // Lack of failure implies success.
70 if (failures.length == 0) {
71 chrome.test.notifyPass();
73 console.log("failures on:\n" + failures.join("\n") +
74 "\n\n\n>>> See comment in stubs_apitest.cc for a " +
75 "hint about fixing this failure.\n\n");
76 chrome.test.notifyFail("failed");
80 chrome.app.runtime.onLaunched.addListener(function() {