| <!DOCTYPE HTML> |
| <html> |
| <head> |
| <meta charset="utf-8"> |
| <title>IdlInterface.prototype.test_to_json_operation()</title> |
| <script src="/resources/testharness.js"></script> |
| <script src="/resources/testharnessreport.js"></script> |
| <script src="/resources/WebIDLParser.js"></script> |
| <script src="/resources/idlharness.js"></script> |
| <script src="../helper.js"></script> |
| </head> |
| <body> |
| <script> |
| "use strict"; |
| function wrap(member, obj) { |
| function F(obj) { |
| this._obj = obj; |
| } |
| |
| F.prototype.toJSON = function() { |
| return this._obj; |
| } |
| Object.defineProperty(F, 'name', { value: member.name }); |
| return new F(obj); |
| } |
| |
| var i, obj; |
| i = interfaceFrom("interface A { [Default] object toJSON(); attribute long foo; };"); |
| i.test_to_json_operation(wrap(i, { foo: 123 }), i.members[0]); |
| |
| // should fail (wrong type) |
| i = interfaceFrom("interface B { [Default] object toJSON(); attribute long foo; };"); |
| i.test_to_json_operation(wrap(i, { foo: "a value" }), i.members[0]); |
| |
| // should handle extraneous attributes (e.g. from an extension specification) |
| i = interfaceFrom("interface C { [Default] object toJSON(); attribute long foo; };"); |
| i.test_to_json_operation(wrap(i, { foo: 123, bar: 456 }), i.members[0]); |
| |
| // should fail (missing property) |
| i = interfaceFrom("interface D { [Default] object toJSON(); attribute long foo; };"); |
| i.test_to_json_operation(wrap(i, { }), i.members[0]); |
| |
| // should fail (should be writable) |
| obj = Object.defineProperties({}, { foo: { |
| writable: false, |
| enumerable: true, |
| configurable: true, |
| value: 123 |
| }}); |
| i = interfaceFrom("interface F { [Default] object toJSON(); attribute long foo; };"); |
| i.test_to_json_operation(wrap(i, obj), i.members[0]); |
| |
| // should fail (should be enumerable) |
| obj = Object.defineProperties({}, { foo: { |
| writable: true, |
| enumerable: false, |
| configurable: true, |
| value: 123 |
| }}); |
| i = interfaceFrom("interface G { [Default] object toJSON(); attribute long foo; };"); |
| i.test_to_json_operation(wrap(i, obj), i.members[0]); |
| |
| // should fail (should be configurable) |
| obj = Object.defineProperties({}, { foo: { |
| writable: true, |
| enumerable: true, |
| configurable: false, |
| value: 123 |
| }}); |
| i = interfaceFrom("interface H { [Default] object toJSON(); attribute long foo; };"); |
| i.test_to_json_operation(wrap(i, obj), i.members[0]); |
| |
| var idl = new IdlArray(); |
| idl.add_idls("interface I : J { [Default] object toJSON(); attribute long foo; };"); |
| idl.add_idls("interface J { [Default] object toJSON(); attribute DOMString foo;};"); |
| var i = idl.members.I; |
| i.test_to_json_operation(wrap(i, { foo: 123 }), i.members[0]); |
| |
| i = interfaceFrom("interface K { [Default] object toJSON(); };"); |
| i.test_to_json_operation(wrap(i, {}), i.members[0]); |
| |
| i = interfaceFrom("interface L { DOMString toJSON(); };"); |
| i.test_to_json_operation(wrap(i, "a string"), i.members[0]); |
| |
| // should fail (wrong output type) |
| i = interfaceFrom("interface M { DOMString toJSON(); };"); |
| i.test_to_json_operation(wrap(i, {}), i.members[0]); |
| |
| // should fail (not an IDL type) |
| i = interfaceFrom("interface N { DOMException toJSON(); };"); |
| i.test_to_json_operation(wrap(i, {}), i.members[0]); |
| </script> |
| <script type="text/json" id="expected"> |
| { |
| "summarized_status": { |
| "message": null, |
| "status_string": "OK" |
| }, |
| "summarized_tests": [ |
| { |
| "message": null, |
| "name": "Test default toJSON operation of A", |
| "properties": {}, |
| "status_string": "PASS" |
| }, |
| { |
| "message": "assert_equals: expected \"number\" but got \"string\"", |
| "name": "Test default toJSON operation of B", |
| "properties": {}, |
| "status_string": "FAIL" |
| }, |
| { |
| "message": null, |
| "name": "Test default toJSON operation of C", |
| "properties": {}, |
| "status_string": "PASS" |
| }, |
| { |
| "message": "assert_true: property \"foo\" should be present in the output of D.prototype.toJSON() expected true got false", |
| "name": "Test default toJSON operation of D", |
| "properties": {}, |
| "status_string": "FAIL" |
| }, |
| { |
| "message": "assert_true: property foo should be writable expected true got false", |
| "name": "Test default toJSON operation of F", |
| "properties": {}, |
| "status_string": "FAIL" |
| }, |
| { |
| "message": "assert_true: property foo should be enumerable expected true got false", |
| "name": "Test default toJSON operation of G", |
| "properties": {}, |
| "status_string": "FAIL" |
| }, |
| { |
| "message": "assert_true: property foo should be configurable expected true got false", |
| "name": "Test default toJSON operation of H", |
| "properties": {}, |
| "status_string": "FAIL" |
| }, |
| { |
| "message": null, |
| "name": "Test default toJSON operation of I", |
| "properties": {}, |
| "status_string": "PASS" |
| }, |
| { |
| "message": null, |
| "name": "Test default toJSON operation of K", |
| "properties": {}, |
| "status_string": "PASS" |
| }, |
| { |
| "message": null, |
| "name": "Test toJSON operation of L", |
| "properties": {}, |
| "status_string": "PASS" |
| }, |
| { |
| "message": "assert_equals: expected \"string\" but got \"object\"", |
| "name": "Test toJSON operation of M", |
| "properties": {}, |
| "status_string": "FAIL" |
| }, |
| { |
| "message": "assert_true: {\"type\":\"return-type\",\"sequence\":false,\"generic\":null,\"nullable\":false,\"union\":false,\"idlType\":\"DOMException\"} is not an appropriate return value for the toJSON operation of N expected true got false", |
| "name": "Test toJSON operation of N", |
| "properties": {}, |
| "status_string": "FAIL" |
| } |
| ], |
| "type": "complete" |
| } |
| </script> |
| </body> |
| </html> |