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

Unified Diff: chrome/test/data/extensions/json_schema_test.js

Issue 9317072: Allow omitting optional parameters for Extensions API functions (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Synced and merged. Created 8 years, 10 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
« no previous file with comments | « chrome/renderer/resources/extensions/windows_custom_bindings.js ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/test/data/extensions/json_schema_test.js
diff --git a/chrome/test/data/extensions/json_schema_test.js b/chrome/test/data/extensions/json_schema_test.js
index fe21b37fa6ff44b157d329bf2ab3b3d02d10991f..d7340d19c03c3f766df1b1de929fd93a14debb57 100644
--- a/chrome/test/data/extensions/json_schema_test.js
+++ b/chrome/test/data/extensions/json_schema_test.js
@@ -39,6 +39,21 @@ function assertNotValid(type, instance, schema, errors, types) {
}
}
+function assertListConsistsOfElements(list, elements) {
+ for (var li = 0; li < list.length; li++) {
+ for (var ei = 0; ei < elements.length && list[li] != elements[ei]; ei++) { }
+ if (ei == elements.length) {
+ log("Expected type not found: " + list[li]);
+ assert(false);
+ }
+ }
+}
+
+function assertEqualSets(set1, set2) {
+ assertListConsistsOfElements(set1, set2);
+ assertListConsistsOfElements(set2, set1);
+}
+
function formatError(key, replacements) {
return chromeHidden.JSONSchemaValidator.formatError(key, replacements);
}
@@ -449,3 +464,147 @@ function testType() {
assertNotValid("Type", {}, {type: "function"},
[formatError("invalidType", ["function", "object"])]);
}
+
+function testGetAllTypesForSchema() {
+ var referencedTypes = [
+ {
+ id: "ChoicesRef",
+ choices: [
+ { type: "integer" },
+ { type: "string" }
+ ]
+ },
+ {
+ id: "ObjectRef",
+ type: "object",
+ }
+ ];
+
+ var arraySchema = {
+ type: "array"
+ };
+
+ var choicesSchema = {
+ choices: [
+ { type: "object" },
+ { type: "function" }
+ ]
+ };
+
+ var objectRefSchema = {
+ $ref: "ObjectRef"
+ };
+
+ var complexSchema = {
+ choices: [
+ { $ref: "ChoicesRef" },
+ { type: "function" },
+ { $ref: "ObjectRef" }
+ ]
+ };
+
+ var validator = new chromeHidden.JSONSchemaValidator();
+ validator.addTypes(referencedTypes);
+
+ var arraySchemaTypes = validator.getAllTypesForSchema(arraySchema);
+ assertEqualSets(arraySchemaTypes, ["array"]);
+
+ var choicesSchemaTypes = validator.getAllTypesForSchema(choicesSchema);
+ assertEqualSets(choicesSchemaTypes, ["object", "function"]);
+
+ var objectRefSchemaTypes = validator.getAllTypesForSchema(objectRefSchema);
+ assertEqualSets(objectRefSchemaTypes, ["object"]);
+
+ var complexSchemaTypes = validator.getAllTypesForSchema(complexSchema);
+ assertEqualSets(complexSchemaTypes,
+ ["integer", "string", "function", "object"]);
+}
+
+function testIsValidSchemaType() {
+ var referencedTypes = [
+ {
+ id: "ChoicesRef",
+ choices: [
+ { type: "integer" },
+ { type: "string" }
+ ]
+ }
+ ];
+
+ var objectSchema = {
+ type: "object",
+ optional: true
+ };
+
+ var complexSchema = {
+ choices: [
+ { $ref: "ChoicesRef" },
+ { type: "function" },
+ ]
+ };
+
+ var validator = new chromeHidden.JSONSchemaValidator();
+ validator.addTypes(referencedTypes);
+
+ assert(validator.isValidSchemaType("object", objectSchema));
+ assert(!validator.isValidSchemaType("integer", objectSchema));
+ assert(!validator.isValidSchemaType("array", objectSchema));
+ assert(validator.isValidSchemaType("null", objectSchema));
+ assert(validator.isValidSchemaType("undefined", objectSchema));
+
+ assert(validator.isValidSchemaType("integer", complexSchema));
+ assert(validator.isValidSchemaType("function", complexSchema));
+ assert(validator.isValidSchemaType("string", complexSchema));
+ assert(!validator.isValidSchemaType("object", complexSchema));
+ assert(!validator.isValidSchemaType("null", complexSchema));
+ assert(!validator.isValidSchemaType("undefined", complexSchema));
+}
+
+function testCheckSchemaOverlap() {
+ var referencedTypes = [
+ {
+ id: "ChoicesRef",
+ choices: [
+ { type: "integer" },
+ { type: "string" }
+ ]
+ },
+ {
+ id: "ObjectRef",
+ type: "object",
+ }
+ ];
+
+ var arraySchema = {
+ type: "array"
+ };
+
+ var choicesSchema = {
+ choices: [
+ { type: "object" },
+ { type: "function" }
+ ]
+ };
+
+ var objectRefSchema = {
+ $ref: "ObjectRef"
+ };
+
+ var complexSchema = {
+ choices: [
+ { $ref: "ChoicesRef" },
+ { type: "function" },
+ { $ref: "ObjectRef" }
+ ]
+ };
+
+ var validator = new chromeHidden.JSONSchemaValidator();
+ validator.addTypes(referencedTypes);
+
+ assert(!validator.checkSchemaOverlap(arraySchema, choicesSchema));
+ assert(!validator.checkSchemaOverlap(arraySchema, objectRefSchema));
+ assert(!validator.checkSchemaOverlap(arraySchema, complexSchema));
+ assert(validator.checkSchemaOverlap(choicesSchema, objectRefSchema));
+ assert(validator.checkSchemaOverlap(choicesSchema, complexSchema));
+ assert(validator.checkSchemaOverlap(objectRefSchema, complexSchema));
+}
« no previous file with comments | « chrome/renderer/resources/extensions/windows_custom_bindings.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698