| <!DOCTYPE html> |
| <title>Web Authentication API: PublicKeyCredential's [[create]] failure cases.</title> |
| <script src="/resources/testharness.js"></script> |
| <script src="/resources/testharnessreport.js"></script> |
| <script src="./resources/util.js"></script> |
| <script> |
| // Default mock configuration. Tests need to override if they need different configuration. |
| if (window.internals) |
| internals.setMockWebAuthenticationConfiguration({ }); |
| |
| promise_test(function(t) { |
| const options = { |
| publicKey: { |
| rp: { |
| name: "example.com" |
| }, |
| user: { |
| name: "John Appleseed", |
| id: asciiToUint8Array("123456"), |
| displayName: "John", |
| }, |
| challenge: asciiToUint8Array("123456"), |
| pubKeyCredParams: [{ type: "public-key", alg: -7 }], |
| timeout: 10, |
| } |
| }; |
| |
| return promiseRejects(t, "NotAllowedError", |
| navigator.credentials.create(options), "Operation timed out."); |
| }, "PublicKeyCredential's [[create]] with timeout"); |
| |
| promise_test(function(t) { |
| const options = { |
| publicKey: { |
| rp: { |
| name: "example.com", |
| id: "example.com" |
| }, |
| user: { |
| name: "John Appleseed", |
| id: asciiToUint8Array("123456"), |
| displayName: "John", |
| }, |
| challenge: asciiToUint8Array("123456"), |
| pubKeyCredParams: [{ type: "public-key", alg: -7 }], |
| } |
| }; |
| |
| return promiseRejects(t, "SecurityError", |
| navigator.credentials.create(options), "The provided RP ID is not a registrable domain suffix of the effective domain of the document."); |
| }, "PublicKeyCredential's [[create]] with a mismatched RP ID"); |
| |
| promise_test(function(t) { |
| const options = { |
| publicKey: { |
| rp: { |
| name: "localhost", |
| id: "localhost" |
| }, |
| user: { |
| name: "John Appleseed", |
| id: asciiToUint8Array("123456"), |
| displayName: "Appleseed", |
| }, |
| challenge: asciiToUint8Array("123456"), |
| pubKeyCredParams: [ ], |
| } |
| }; |
| |
| return promiseRejects(t, "NotSupportedError", |
| navigator.credentials.create(options), "No desired properties of the to be created credential are provided."); |
| }, "PublicKeyCredential's [[create]] with an empty pubKeyCredParams"); |
| |
| promise_test(function(t) { |
| const options = { |
| publicKey: { |
| rp: { |
| name: "example.com" |
| }, |
| user: { |
| name: "John Appleseed", |
| id: asciiToUint8Array("123456"), |
| displayName: "John", |
| }, |
| challenge: asciiToUint8Array("123456"), |
| pubKeyCredParams: [{ type: "public-key", alg: -7 }], |
| } |
| }; |
| |
| const result = promiseRejects(t, "NotAllowedError", navigator.credentials.create(options), "This request has been cancelled by a new request."); |
| promiseRejects(t, "NotAllowedError", navigator.credentials.create(options), "This request has been cancelled by a new request."); |
| return result; |
| }, "PublicKeyCredential's [[create]] with two consecutive requests"); |
| |
| promise_test(function(t) { |
| const creationOptions = { |
| publicKey: { |
| rp: { |
| name: "example.com" |
| }, |
| user: { |
| name: "John Appleseed", |
| id: asciiToUint8Array("123456"), |
| displayName: "John", |
| }, |
| challenge: asciiToUint8Array("123456"), |
| pubKeyCredParams: [{ type: "public-key", alg: -7 }], |
| } |
| }; |
| const result = promiseRejects(t, "NotAllowedError", navigator.credentials.create(creationOptions), "This request has been cancelled by a new request."); |
| |
| const requestOptions = { |
| publicKey: { |
| challenge: asciiToUint8Array("123456") |
| } |
| }; |
| promiseRejects(t, "NotAllowedError", navigator.credentials.get(requestOptions), "This request has been cancelled by a new request."); |
| return result; |
| }, "PublicKeyCredential's [[create]] with two consecutive requests (2)"); |
| |
| promise_test(function(t) { |
| const options = { |
| publicKey: { |
| rp: { |
| name: "example.com" |
| }, |
| user: { |
| name: "John Appleseed", |
| id: asciiToUint8Array("123456"), |
| displayName: "John", |
| }, |
| challenge: asciiToUint8Array("123456"), |
| pubKeyCredParams: [{ type: "public-key", alg: -7 }], |
| } |
| }; |
| |
| const result = promiseRejects(t, "NotAllowedError", navigator.credentials.create(options), "This request has been cancelled by a new request."); |
| window.open("./resources/new-page.html?isCreation=true"); |
| return result; |
| }, "PublicKeyCredential's [[create]] with new requests in a new page"); |
| |
| promise_test(function(t) { |
| const options = { |
| publicKey: { |
| rp: { |
| name: "example.com" |
| }, |
| user: { |
| name: "John Appleseed", |
| id: asciiToUint8Array("123456"), |
| displayName: "John", |
| }, |
| challenge: asciiToUint8Array("123456"), |
| pubKeyCredParams: [{ type: "public-key", alg: -7 }], |
| } |
| }; |
| |
| const result = promiseRejects(t, "NotAllowedError", navigator.credentials.create(options), "This request has been cancelled by a new request."); |
| window.open("./resources/new-page.html?isCreation=false"); |
| return result; |
| }, "PublicKeyCredential's [[create]] with new requests in a new page (2)"); |
| </script> |