Chromium Code Reviews| 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 true if the feature is available to platform apps, either via a | |
| 8 // specific path or via an entire namespace. | |
| 9 function isAvailableToPlatformApps(namespace, path) { | |
| 10 function checkFeature(feature) { | |
| 11 return typeof(feature.extension_types) == "undefined" || | |
|
not at google - send to devlin
2014/05/02 22:19:57
this first check isn't right, since if it's undefi
James Cook
2014/05/02 23:59:15
I took out this isAvailableToPlatformApps check an
| |
| 12 feature.extension_types.indexOf('all') != -1 || | |
|
not at google - send to devlin
2014/05/02 22:19:57
however, this test could be much stronger if the s
James Cook
2014/05/02 23:59:15
Added permissions from app REPL and a pass through
not at google - send to devlin
2014/05/03 00:12:43
Awesome :)
though won't pick up on people acciden
| |
| 13 feature.extension_types.indexOf('platform_app') != -1; | |
| 14 } | |
| 15 | |
| 16 if (apiFeatures.hasOwnProperty(path)) | |
| 17 return checkFeature(apiFeatures[path]); | |
| 18 return apiFeatures.hasOwnProperty(namespace) && | |
| 19 checkFeature(apiFeatures[namespace]); | |
| 20 } | |
| 21 | |
| 22 // Returns a list of all chrome.foo.bar API paths available to an app. | |
| 23 function getApiPaths() { | |
| 24 var apiPaths = []; | |
| 25 var apiDefinitions = chrome.test.getApiDefinitions(); | |
| 26 apiDefinitions.forEach(function(module) { | |
| 27 var namespace = module.namespace; | |
| 28 | |
| 29 // Get the API functions and events. | |
| 30 ["functions", "events"].forEach(function(section) { | |
| 31 if (typeof(module[section]) == "undefined") | |
| 32 return; | |
| 33 module[section].forEach(function(entry) { | |
| 34 var path = namespace + "." + entry.name; | |
| 35 if (isAvailableToPlatformApps(namespace, path)) { | |
| 36 apiPaths.push(path); | |
| 37 } | |
| 38 }); | |
| 39 }); | |
| 40 | |
| 41 // Get the API properties. | |
| 42 if (module.properties) { | |
| 43 for (var propName in module.properties) { | |
|
not at google - send to devlin
2014/05/02 22:19:57
Object.getOwnPropertyNames(module.properties).forE
James Cook
2014/05/02 23:59:15
Done.
| |
| 44 var path = namespace + "." + propName; | |
| 45 if (isAvailableToPlatformApps(namespace, path)) { | |
| 46 apiPaths.push(path); | |
| 47 } | |
| 48 } | |
| 49 } | |
| 50 }); | |
| 51 return apiPaths; | |
| 52 } | |
| 53 | |
| 54 // Tests whether all parts of an API path can be accessed. The path is a | |
| 55 // namespace or function/property/event etc. within a namespace, and is | |
| 56 // dot-separated. | |
| 57 function testPath(path) { | |
| 58 var parts = path.split('.'); | |
| 59 | |
| 60 var module = chrome; | |
| 61 for (var i = 0; i < parts.length; i++) { | |
| 62 // Touch this component of the path. This will die if an API does not have | |
| 63 // a schema registered. | |
| 64 module = module[parts[i]]; | |
| 65 | |
| 66 if (i < parts.length - 1) { | |
| 67 // Not the last component. Allowed to be undefined because some paths are | |
|
not at google - send to devlin
2014/05/02 22:19:57
this check confuses me.
James Cook
2014/05/02 23:01:39
A quick question while I'm working on the rest of
not at google - send to devlin
2014/05/02 23:03:17
ah yeah you need to filter out internal APIs.
James Cook
2014/05/02 23:59:15
Filtering out internal APIs gets rid of the need f
| |
| 68 // only defined on some platforms. | |
| 69 if (typeof(module) == "undefined") | |
| 70 return true; | |
| 71 } else { | |
| 72 // This is the last component. It should be defined, unless it is the | |
| 73 // lastError property, which depends on there being an error. | |
| 74 if (typeof(module) == "undefined" && | |
| 75 path != "extension.lastError" && | |
| 76 path != "runtime.lastError") { | |
| 77 console.log(" fail (should not be undefined): " + path); | |
| 78 return false; | |
| 79 } | |
| 80 } | |
| 81 } | |
| 82 return true; | |
| 83 } | |
| 84 | |
| 85 function doTest() { | |
| 86 var apiPaths = getApiPaths(); | |
|
not at google - send to devlin
2014/05/02 22:19:57
I would just inline this
James Cook
2014/05/02 23:59:15
Done.
| |
| 87 var failures = []; | |
| 88 var success = true; | |
| 89 | |
| 90 // Run over each string path in apiPaths and ensure each path is defined. | |
| 91 apiPaths.forEach(function(path) { | |
| 92 if (!testPath(path)) { | |
| 93 success = false; | |
| 94 failures.push(path); | |
| 95 } | |
| 96 }); | |
| 97 | |
| 98 if (success) { | |
|
not at google - send to devlin
2014/05/02 22:19:57
use "failures.length == 0" here and you don't need
James Cook
2014/05/02 23:59:15
Done.
| |
| 99 chrome.test.notifyPass(); | |
| 100 } else { | |
| 101 console.log("failures on:\n" + failures.join("\n") + | |
| 102 "\n\n\n>>> See comment in stubs_apitest.cc for a " + | |
| 103 "hint about fixing this failure.\n\n"); | |
| 104 chrome.test.notifyFail("failed"); | |
| 105 } | |
| 106 } | |
| 107 | |
| 108 chrome.app.runtime.onLaunched.addListener(function() { | |
| 109 doTest(); | |
| 110 }); | |
| OLD | NEW |