blob: 63f3e8e8d7c3242454516b1f5d916565cb586359 [file] [log] [blame]
<!doctype html>
<title>Credential Manager: get() basics.</title>
<script src="../resources/testharness.js"></script>
<script src="../resources/testharnessreport.js"></script>
<script src="/gen/layout_test_data/mojo/public/js/mojo_bindings.js"></script>
<script src="/gen/third_party/WebKit/public/platform/modules/credentialmanager/credential_manager.mojom.js"></script>
<script src="/gen/third_party/WebKit/public/platform/modules/webauth/authenticator.mojom.js"></script>
<script src="resources/credential-helpers.js"></script>
<script>
if (document.location.hostname == "127.0.0.1") {
document.location = "https://subdomain.example.test:8443/credentialmanager/credentialscontainer-get-basics.html";
promise_test(_ => new Promise(_ => {}), "Stall tests on the wrong host.");
}
add_completion_callback(() => {
mockCredentialManager.reset();
});
promise_test(_ => {
return navigator.credentials.get().then(r => {
assert_equals(r, null);
});
}, "navigator.credentials.get() with no argument.");
promise_test(_ => {
return navigator.credentials.get({}).then(r => {
assert_equals(r, null);
});
}, "navigator.credentials.get({}).");
promise_test(_ => {
return navigator.credentials.get({
federated: {
providers: [ 'https://example.com/' ]
}
}).then(r => {
assert_equals(r, null);
});
}, "navigator.credentials.get() with a valid options including FederatedCredentialRequestOptions.");
promise_test(_ => {
return navigator.credentials.get({
password: true,
unmediated: true
}).then(r => {
assert_equals(r, null);
});
}, "navigator.credentials.get() with a valid options including password and unmediated.");
promise_test(_ => {
return navigator.credentials.get({
federated: {
providers: [ 'https://example.com/' ]
},
unmediated: true
}).then(r => {
assert_equals(r, null);
});
}, "navigator.credentials.get() with a valid options including federated and unmediated.");
promise_test(_ => {
return navigator.credentials.get({
password: true,
federated: {
providers: [ 'https://example.com/' ]
},
unmediated: true
}).then(r => {
assert_equals(r, null);
});
}, "navigator.credentials.get() with a valid options including federated, password and unmediated.");
promise_test(_ => {
return navigator.credentials.get({
unmediated: true
}).then(r => {
assert_equals(r, null);
});
}, "navigator.credentials.get() with a valid options including unmediated.");
promise_test(_ => {
return navigator.credentials.get({
mediation: "silent"
}).then(r => {
assert_equals(r, null);
});
}, "navigator.credentials.get() with a valid options including mediation.");
promise_test(_ => {
return navigator.credentials.get({
notValid: 'yay!'
}).then(r => {
assert_equals(r, null);
});
}, "navigator.credentials.get() with an options including an unknown attribute.");
promise_test(_ => {
var id = "id";
var password = "pencil";
var name = "name";
var icon = "http://example.com/";
mockCredentialManager.setResponse(id, password, name, icon);
return navigator.credentials.get({
password: true
}).then(r => {
assert_equals(r.id, id, "id");
assert_equals(r.password, password, "password");
assert_equals(r.name, name, "name");
assert_equals(r.iconURL, icon, "icon");
});
}, "Verify that the mock returns the values we give it.");
promise_test(_ => {
mockAuthenticator.setRawId(RAW_ID);
mockAuthenticator.setDefaultsForSuccessfulGetAssertion();
return navigator.credentials.get({publicKey : GET_CREDENTIAL_OPTIONS}).then(r => {
assertValidGetCredentialResponse(r);
});
}, "Verify that mockAuthenticator returns the values we give it.");
promise_test(t => {
mockAuthenticator.setAuthenticatorStatus(
webauth.mojom.AuthenticatorStatus.PENDING_REQUEST);
return promise_rejects(t, "InvalidStateError",
navigator.credentials.get({ publicKey : GET_CREDENTIAL_OPTIONS}));
}, "Verify that pending request error returned by mock is properly handled.");
promise_test(function (t) {
mockAuthenticator.setAuthenticatorStatus(
webauth.mojom.AuthenticatorStatus.UNKNOWN_ERROR);
return promise_rejects(t, "NotReadableError",
navigator.credentials.get({ publicKey : GET_CREDENTIAL_OPTIONS}));
}, "Verify that unknown error returned by mock is properly handled.");
promise_test(t => {
mockAuthenticator.setAuthenticatorStatus(
webauth.mojom.AuthenticatorStatus.NOT_ALLOWED_ERROR);
return promise_rejects(t, "NotAllowedError",
navigator.credentials.get({ publicKey : GET_CREDENTIAL_OPTIONS}));
}, "Verify that not allowed error returned by mock is properly handled.");
promise_test(t => {
mockAuthenticator.setAuthenticatorStatus(
webauth.mojom.AuthenticatorStatus.NOT_SUPPORTED_ERROR);
return promise_rejects(t, "NotSupportedError",
navigator.credentials.get({ publicKey : GET_CREDENTIAL_OPTIONS}));
}, "Verify that not supported error returned by mock is properly handled.");
promise_test(function(t) {
var customGetCredentialOptions = deepCopy(MAKE_CREDENTIAL_OPTIONS);
delete customGetCredentialOptions.challenge;
return promise_rejects(t, new TypeError(),
navigator.credentials.get({publicKey: customGetCredentialOptions}));
}, "navigator.credentials.get() with missing challenge");
promise_test(_ => {
mockAuthenticator.reset();
mockAuthenticator.setDefaultsForSuccessfulGetAssertion();
var customGetCredentialOptions = deepCopy(MAKE_CREDENTIAL_OPTIONS);
delete customGetCredentialOptions.rpId;
return navigator.credentials.get({publicKey: customGetCredentialOptions}).then(r => {
assertValidGetCredentialResponse(r);
});
}, "navigator.credentials.get() with missing rpId");
promise_test(_ => {
mockAuthenticator.reset();
mockAuthenticator.setDefaultsForSuccessfulGetAssertion();
var customGetCredentialOptions = deepCopy(MAKE_CREDENTIAL_OPTIONS);
delete customGetCredentialOptions.userVerification;
return navigator.credentials.get({publicKey: customGetCredentialOptions}).then(r => {
assertValidGetCredentialResponse(r);
});
}, "navigator.credentials.get() with missing user verification requirement");
</script>