Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2369)

Unified Diff: chrome/test/data/extensions/api_test/stubs_app/background.js

Issue 264923009: Add browser_test for extension app API with missing schema (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: cleanup Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/test/data/extensions/api_test/stubs_app/background.js
diff --git a/chrome/test/data/extensions/api_test/stubs_app/background.js b/chrome/test/data/extensions/api_test/stubs_app/background.js
new file mode 100644
index 0000000000000000000000000000000000000000..0db022ac2258deca489f7828add9abf01b191f59
--- /dev/null
+++ b/chrome/test/data/extensions/api_test/stubs_app/background.js
@@ -0,0 +1,79 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+var apiFeatures = chrome.test.getApiFeatures();
+
+// Returns a list of all chrome.foo.bar API paths available to an app.
+function getApiPaths() {
+ var apiPaths = [];
+ var apiDefinitions = chrome.test.getApiDefinitions();
+ apiDefinitions.forEach(function(module) {
+ var namespace = module.namespace;
+
+ // Skip internal APIs.
+ if (apiFeatures[namespace].internal)
+ return;
+
+ // Get the API functions and events.
+ ["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.
+ if (typeof(module[section]) == "undefined")
+ return;
+ module[section].forEach(function(entry) {
+ apiPaths.push(namespace + "." + entry.name);
+ });
+ });
+
+ // Get the API properties.
+ if (module.properties) {
+ Object.getOwnPropertyNames(module.properties).forEach(function(propName) {
+ apiPaths.push(namespace + "." + propName);
+ });
+ }
+ });
+ return apiPaths;
+}
+
+// Tests whether all parts of an API path can be accessed. The path is a
+// namespace or function/property/event etc. within a namespace, and is
+// dot-separated.
+function testPath(path) {
+ var parts = path.split('.');
+
+ var module = chrome;
+ for (var i = 0; i < parts.length; i++) {
+ // Touch this component of the path. This will die if an API does not have
+ // a schema registered.
+ module = module[parts[i]];
+
+ // The component should be defined unless it is lastError, which depends on
+ // there being an error.
+ if (typeof(module) == "undefined" && path != "runtime.lastError")
+ return false;
+ }
+ return true;
+}
+
+function doTest() {
+ // Run over all API path strings and ensure each path is defined.
+ var failures = [];
+ getApiPaths().forEach(function(path) {
+ if (!testPath(path)) {
+ failures.push(path);
+ }
+ });
+
+ // Lack of failure implies success.
+ if (failures.length == 0) {
+ chrome.test.notifyPass();
+ } else {
+ console.log("failures on:\n" + failures.join("\n") +
+ "\n\n\n>>> See comment in stubs_apitest.cc for a " +
+ "hint about fixing this failure.\n\n");
+ chrome.test.notifyFail("failed");
+ }
+}
+
+chrome.app.runtime.onLaunched.addListener(function() {
+ doTest();
+});

Powered by Google App Engine
This is Rietveld 408576698