Commit 2ba3c88d authored by rdevlin.cronin's avatar rdevlin.cronin Committed by Commit bot

[Extensions] Expose enums on extension APIs.

BUG=463184

Review URL: https://codereview.chromium.org/969063002

Cr-Commit-Position: refs/heads/master@{#318811}
parent 9244b35b
...@@ -92,5 +92,9 @@ IN_PROC_BROWSER_TEST_F(ExtensionBindingsApiTest, Nocompile) { ...@@ -92,5 +92,9 @@ IN_PROC_BROWSER_TEST_F(ExtensionBindingsApiTest, Nocompile) {
<< message_; << message_;
} }
IN_PROC_BROWSER_TEST_F(ExtensionBindingsApiTest, ApiEnums) {
ASSERT_TRUE(RunExtensionTest("bindings/api_enums")) << message_;
};
} // namespace } // namespace
} // namespace extensions } // namespace extensions
// Copyright 2015 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.
chrome.test.runTests([
function() {
// Test management (backed by a json file) api enums.
// The enum should be declared on the API object.
chrome.test.assertTrue(
'LaunchType' in chrome.management,
'"LaunchType" is not present on chrome.management.');
// The object should have entries for each enum entry. Note that we don't
// test all entries here because we don't want to update this test if the
// management api changes.
chrome.test.assertTrue(
'OPEN_AS_REGULAR_TAB' in chrome.management.LaunchType,
'"OPEN_AS_REGULAR_TAB" is not present on management.LaunchType');
// The value of the enum should be its string value.
chrome.test.assertEq(chrome.management.LaunchType.OPEN_AS_REGULAR_TAB,
'OPEN_AS_REGULAR_TAB');
// There should be more than one value for the enum.
chrome.test.assertTrue(
Object.keys(chrome.management.LaunchType).length > 1);
// Perform an analogous test for the notifications api (backed by an idl).
chrome.test.assertTrue(
'PermissionLevel' in chrome.notifications,
'"PermissionLevel" is not present on chrome.notifications.');
chrome.test.assertTrue(
'granted' in chrome.notifications.PermissionLevel,
'"granted" is not present on notifications.PermissionLevel');
chrome.test.assertEq(chrome.notifications.PermissionLevel.granted,
'granted');
chrome.test.assertTrue(
Object.keys(chrome.notifications.PermissionLevel).length > 1);
chrome.test.succeed();
}
]);
{
"name": "bindings/api_enums",
"manifest_version": 2,
"version": "1",
"background": {
"scripts": ["background.js"]
},
"permissions": ["management", "notifications"]
}
...@@ -275,13 +275,35 @@ Binding.prototype = { ...@@ -275,13 +275,35 @@ Binding.prototype = {
mod = mod[name]; mod = mod[name];
} }
// Add types to global schemaValidator, the types we depend on from other
// namespaces will be added as needed.
if (schema.types) { if (schema.types) {
$Array.forEach(schema.types, function(t) { $Array.forEach(schema.types, function(t) {
if (!isSchemaNodeSupported(t, platform, manifestVersion)) if (!isSchemaNodeSupported(t, platform, manifestVersion))
return; return;
// Add types to global schemaValidator; the types we depend on from
// other namespaces will be added as needed.
schemaUtils.schemaValidator.addTypes(t); schemaUtils.schemaValidator.addTypes(t);
// Generate symbols for enums.
var enumValues = t['enum'];
if (enumValues) {
// Type IDs are qualified with the namespace during compilation,
// unfortunately, so remove it here.
logging.DCHECK(
t.id.substr(0, schema.namespace.length) == schema.namespace);
// Note: + 1 because it ends in a '.', e.g., 'fooApi.Type'.
var id = t.id.substr(schema.namespace.length + 1);
mod[id] = {};
$Array.forEach(enumValues, function(enumValue) {
// Note: enums can be declared either as a list of strings
// ['foo', 'bar'] or as a list of objects
// [{'name': 'foo'}, {'name': 'bar'}].
enumValue =
enumValue.hasOwnProperty('name') ? enumValue.name : enumValue;
if (enumValue) // Avoid setting any empty enums.
mod[id][enumValue] = enumValue;
});
}
}, this); }, this);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment