| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // Helper function to log message to both the local console and to the | 5 // Helper function to log message to both the local console and to the |
| 6 // background page, so that the latter can output the message via the | 6 // background page, so that the latter can output the message via the |
| 7 // chrome.test.log() function. | 7 // chrome.test.log() function. |
| 8 function logToConsoleAndStdout(msg) { | 8 function logToConsoleAndStdout(msg) { |
| 9 console.log(msg); | 9 console.log(msg); |
| 10 chrome.extension.sendRequest("log: " + msg); | 10 chrome.extension.sendRequest("log: " + msg); |
| 11 } | 11 } |
| 12 | 12 |
| 13 // We ask the background page to get the extension API to test against. When it | 13 // We ask the background page to get the extension API to test against. When it |
| 14 // responds we start the test. | 14 // responds we start the test. |
| 15 console.log("asking for api ..."); | 15 console.log("asking for api ..."); |
| 16 chrome.extension.sendRequest("getApi", function(apis) { | 16 chrome.extension.sendRequest("getApi", function(apis) { |
| 17 var apiFeatures = chrome.test.getApiFeatures(); |
| 18 function isAvailableToContentScripts(namespace, path) { |
| 19 if (apiFeatures.hasOwnProperty(path)) |
| 20 return apiFeatures[path]['contexts'].indexOf('content_script') != -1 |
| 21 return apiFeatures.hasOwnProperty(namespace) && |
| 22 apiFeatures[namespace]['contexts'].indexOf('content_script') != -1; |
| 23 } |
| 24 |
| 17 console.log("got api response"); | 25 console.log("got api response"); |
| 18 var privilegedPaths = []; | 26 var privilegedPaths = []; |
| 19 var unprivilegedPaths = []; | 27 var unprivilegedPaths = []; |
| 20 apis.forEach(function(module) { | 28 apis.forEach(function(module) { |
| 21 var namespace = module.namespace; | 29 var namespace = module.namespace; |
| 22 | 30 |
| 23 ["functions", "events"].forEach(function(section) { | 31 ["functions", "events"].forEach(function(section) { |
| 24 if (typeof(module[section]) == "undefined") | 32 if (typeof(module[section]) == "undefined") |
| 25 return; | 33 return; |
| 26 module[section].forEach(function(entry) { | 34 module[section].forEach(function(entry) { |
| 27 // Ignore entries that are not applicable to the manifest that we're | 35 // Ignore entries that are not applicable to the manifest that we're |
| 28 // running under. | 36 // running under. |
| 29 if (entry.maximumManifestVersion && entry.maximumManifestVersion < 2) { | 37 if (entry.maximumManifestVersion && entry.maximumManifestVersion < 2) { |
| 30 return; | 38 return; |
| 31 } | 39 } |
| 32 | 40 |
| 33 var path = namespace + "." + entry.name; | 41 var path = namespace + "." + entry.name; |
| 34 // TODO(cduvall): Make this inspect _api_features.json. | 42 if (module.unprivileged || entry.unprivileged || |
| 35 // http://crbug.com/232247 | 43 isAvailableToContentScripts(namespace, path)) { |
| 36 // Manually add chrome.app to the unprivileged APIs since it uses the | |
| 37 // feature system now. | |
| 38 if (module.unprivileged || entry.unprivileged || namespace == 'app') { | |
| 39 unprivilegedPaths.push(path); | 44 unprivilegedPaths.push(path); |
| 40 } else { | 45 } else { |
| 41 privilegedPaths.push(path); | 46 privilegedPaths.push(path); |
| 42 } | 47 } |
| 43 }); | 48 }); |
| 44 }); | 49 }); |
| 45 | 50 |
| 46 if (module.properties) { | 51 if (module.properties) { |
| 47 for (var propName in module.properties) { | 52 for (var propName in module.properties) { |
| 48 var path = namespace + "." + propName; | 53 var path = namespace + "." + propName; |
| 49 if (module.unprivileged || module.properties[propName].unprivileged) { | 54 if (module.unprivileged || module.properties[propName].unprivileged || |
| 55 isAvailableToContentScripts(namespace, path)) { |
| 50 unprivilegedPaths.push(path); | 56 unprivilegedPaths.push(path); |
| 51 } else { | 57 } else { |
| 52 privilegedPaths.push(path); | 58 privilegedPaths.push(path); |
| 53 } | 59 } |
| 54 } | 60 } |
| 55 } | 61 } |
| 56 }); | 62 }); |
| 57 doTest(privilegedPaths, unprivilegedPaths); | 63 doTest(privilegedPaths, unprivilegedPaths); |
| 58 }); | 64 }); |
| 59 | 65 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 77 return false; | 83 return false; |
| 78 } | 84 } |
| 79 if (typeof(module) == "undefined") | 85 if (typeof(module) == "undefined") |
| 80 return true; | 86 return true; |
| 81 } else { | 87 } else { |
| 82 // This is the last component - we expect it to either be undefined or | 88 // This is the last component - we expect it to either be undefined or |
| 83 // to throw an error on access. | 89 // to throw an error on access. |
| 84 try { | 90 try { |
| 85 if (typeof(module[parts[i]]) == "undefined" && | 91 if (typeof(module[parts[i]]) == "undefined" && |
| 86 path != "extension.lastError" && | 92 path != "extension.lastError" && |
| 87 path != "runtime.lastError" && | 93 path != "runtime.lastError") { |
| 88 path != "runtime.id") { | 94 if (expectError) { |
| 89 logToConsoleAndStdout(" fail (undefined and not throwing error): " + | 95 return true; |
| 90 path); | 96 } else { |
| 91 return false; | 97 logToConsoleAndStdout(" fail (should not be undefined): " + path); |
| 98 return false; |
| 99 } |
| 92 } else if (!expectError) { | 100 } else if (!expectError) { |
| 93 return true; | 101 return true; |
| 94 } | 102 } |
| 95 } catch (err) { | 103 } catch (err) { |
| 96 if (!expectError) { | 104 if (!expectError) { |
| 97 logToConsoleAndStdout(" fail (did not expect error): " + path); | 105 logToConsoleAndStdout(" fail (did not expect error): " + path); |
| 98 return false; | 106 return false; |
| 99 } | 107 } |
| 100 var str = err.toString(); | 108 var str = err.toString(); |
| 101 if (str.search("can only be used in extension processes.") != -1) { | 109 if (str.search("can only be used in extension processes.") != -1) { |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 161 console.log(success ? "pass" : "fail"); | 169 console.log(success ? "pass" : "fail"); |
| 162 if (success) { | 170 if (success) { |
| 163 reportSuccess(); | 171 reportSuccess(); |
| 164 } else { | 172 } else { |
| 165 logToConsoleAndStdout("failures on:\n" + failures.join("\n") + | 173 logToConsoleAndStdout("failures on:\n" + failures.join("\n") + |
| 166 "\n\n\n>>> See comment in stubs_apitest.cc for a " + | 174 "\n\n\n>>> See comment in stubs_apitest.cc for a " + |
| 167 "hint about fixing this failure.\n\n"); | 175 "hint about fixing this failure.\n\n"); |
| 168 reportFailure(); | 176 reportFailure(); |
| 169 } | 177 } |
| 170 } | 178 } |
| OLD | NEW |