Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / chrome / test / data / extensions / api_test / stubs_app / background.js
blob32ae43446fabc2dbd2d8d010b97fbd03bb6c46b7
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() {
9 var apiPaths = [];
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)
19 return;
21 // Get the API functions and events.
22 [module.functions, module.events].forEach(function(section) {
23 if (typeof(section) == "undefined")
24 return;
25 section.forEach(function(entry) {
26 apiPaths.push(namespace + "." + entry.name);
27 });
28 });
30 // Get the API properties.
31 if (module.properties) {
32 Object.getOwnPropertyNames(module.properties).forEach(function(propName) {
33 apiPaths.push(namespace + "." + propName);
34 });
36 });
37 return apiPaths;
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
42 // dot-separated.
43 function testPath(path) {
44 var parts = path.split('.');
46 var module = chrome;
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")
55 return false;
57 return true;
60 function doTest() {
61 // Run over all API path strings and ensure each path is defined.
62 var failures = [];
63 getApiPaths().forEach(function(path) {
64 if (!testPath(path)) {
65 failures.push(path);
67 });
69 // Lack of failure implies success.
70 if (failures.length == 0) {
71 chrome.test.notifyPass();
72 } else {
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() {
81 doTest();
82 });