OLD | NEW |
---|---|
(Empty) | |
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 var apiFeatures = chrome.test.getApiFeatures(); | |
6 | |
7 // Returns a list of all chrome.foo.bar API paths available to an app. | |
8 function getApiPaths() { | |
9 var apiPaths = []; | |
10 var apiDefinitions = chrome.test.getApiDefinitions(); | |
11 apiDefinitions.forEach(function(module) { | |
12 var namespace = module.namespace; | |
13 | |
14 // Skip internal APIs. | |
15 if (apiFeatures[namespace].internal) | |
16 return; | |
17 | |
18 // Get the API functions and events. | |
19 ["functions", "events"].forEach(function(section) { | |
not at google - send to devlin
2014/05/03 00:12:43
it would be cleaner to loop over [module.functions
James Cook
2014/05/05 16:36:26
Done.
| |
20 if (typeof(module[section]) == "undefined") | |
21 return; | |
22 module[section].forEach(function(entry) { | |
23 apiPaths.push(namespace + "." + entry.name); | |
24 }); | |
25 }); | |
26 | |
27 // Get the API properties. | |
28 if (module.properties) { | |
29 Object.getOwnPropertyNames(module.properties).forEach(function(propName) { | |
30 apiPaths.push(namespace + "." + propName); | |
31 }); | |
32 } | |
33 }); | |
34 return apiPaths; | |
35 } | |
36 | |
37 // Tests whether all parts of an API path can be accessed. The path is a | |
38 // namespace or function/property/event etc. within a namespace, and is | |
39 // dot-separated. | |
40 function testPath(path) { | |
41 var parts = path.split('.'); | |
42 | |
43 var module = chrome; | |
44 for (var i = 0; i < parts.length; i++) { | |
45 // Touch this component of the path. This will die if an API does not have | |
46 // a schema registered. | |
47 module = module[parts[i]]; | |
48 | |
49 // The component should be defined unless it is lastError, which depends on | |
50 // there being an error. | |
51 if (typeof(module) == "undefined" && path != "runtime.lastError") | |
52 return false; | |
53 } | |
54 return true; | |
55 } | |
56 | |
57 function doTest() { | |
58 // Run over all API path strings and ensure each path is defined. | |
59 var failures = []; | |
60 getApiPaths().forEach(function(path) { | |
61 if (!testPath(path)) { | |
62 failures.push(path); | |
63 } | |
64 }); | |
65 | |
66 // Lack of failure implies success. | |
67 if (failures.length == 0) { | |
68 chrome.test.notifyPass(); | |
69 } else { | |
70 console.log("failures on:\n" + failures.join("\n") + | |
71 "\n\n\n>>> See comment in stubs_apitest.cc for a " + | |
72 "hint about fixing this failure.\n\n"); | |
73 chrome.test.notifyFail("failed"); | |
74 } | |
75 } | |
76 | |
77 chrome.app.runtime.onLaunched.addListener(function() { | |
78 doTest(); | |
79 }); | |
OLD | NEW |