summaryrefslogtreecommitdiffstats
path: root/chrome/test/data/extensions/json_schema_test.js
diff options
context:
space:
mode:
authorrafaelw@chromium.org <rafaelw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-11-12 21:41:15 +0000
committerrafaelw@chromium.org <rafaelw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-11-12 21:41:15 +0000
commitdb30527a4f5017945dca3db5cf6cb5e1d589387e (patch)
tree22a0c41d138300aa72a7d441620d6dad3eed0440 /chrome/test/data/extensions/json_schema_test.js
parent99432806a06b73301e4723de2d4b6b12aad63a21 (diff)
downloadchromium_src-db30527a4f5017945dca3db5cf6cb5e1d589387e.zip
chromium_src-db30527a4f5017945dca3db5cf6cb5e1d589387e.tar.gz
chromium_src-db30527a4f5017945dca3db5cf6cb5e1d589387e.tar.bz2
JsonSchema support for declaring "object" constructors.
This adds support for an optional declaration of "isInstanceOf" on "type":"object". If present, the candidate object will be tested for js:instanceof window[schema.isInstanceOf]. Several api functions are modified to take advantage of declaring their "class". Also, support added to docs for modules, methods & events to declare "nodocs":"true" to be excluded from the docs. Also, check to warn on an attempt to use cygwin python to generate docs. BUG=27213 TEST=NONE Review URL: http://codereview.chromium.org/389005 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@31834 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/test/data/extensions/json_schema_test.js')
-rw-r--r--chrome/test/data/extensions/json_schema_test.js36
1 files changed, 35 insertions, 1 deletions
diff --git a/chrome/test/data/extensions/json_schema_test.js b/chrome/test/data/extensions/json_schema_test.js
index 1713b27..3f55c08 100644
--- a/chrome/test/data/extensions/json_schema_test.js
+++ b/chrome/test/data/extensions/json_schema_test.js
@@ -14,7 +14,9 @@ function assertValid(type, instance, schema, types) {
validator["validate" + type](instance, schema, "");
if (validator.errors.length != 0) {
log("Got unexpected errors");
- log(validator.errors);
+ for (var i = 0; i < validator.errors.length; i++) {
+ log(validator.errors[i].message + " path: " + validator.errors[i].path);
+ }
assert(false);
}
}
@@ -165,6 +167,16 @@ function testExtends() {
assertValid("", 43, schema);
}
+function ClassA() {
+ this.a = "a";
+}
+function ClassB() {
+}
+ClassB.prototype = new ClassA();
+function ClassC() {
+ this.a = "a";
+}
+
function testObject() {
var schema = {
properties: {
@@ -201,6 +213,28 @@ function testObject() {
assertValid("Object", {foo:"foo",bar:undefined}, schema);
assertNotValid("Object", {foo:"foo", bar:"42"}, schema,
[formatError("invalidType", ["integer", "string"])]);
+
+ var classASchema = {
+ properties: {
+ "a": { type: "string" }
+ },
+ isInstanceOf: "ClassA"
+ };
+
+ var classBSchema = {
+ properties: {},
+ isInstanceOf: "ClassB"
+ };
+
+ var a = new ClassA();
+ var b = new ClassB();
+ var c = new ClassC();
+
+ assertValid("Object", a, classASchema);
+ assertValid("Object", b, classBSchema);
+ assertValid("Object", b, classASchema);
+ assertNotValid("Object", c, classASchema,
+ [formatError("notInstance", [classASchema.isInstanceOf])]);
}
function testTypeReference() {