blob: d0dd88dfa2c2979275191d8873d52d87b3d3bb3f [file] [log] [blame]
<!DOCTYPE html>
<title>Credential Manager: get() with custom origins.</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>
// For tests that require custom-set origins.
const VALID_ORIGIN_RPID_PAIRS = [
{ 'origin': 'https://google.test:8443',
'rpId': 'google.test' },
{ 'origin': 'https://google.test:8443',
'rpId': '' },
{'origin': 'https://subdomain.example.test:8443',
'rpId': 'example.test' },
{'origin': 'https://subdomain.example.test:8443',
'rpId': 'subdomain.example.test' },
{'origin': 'https://localhost:8443',
'rpId': 'localhost' },
];
for (let test of VALID_ORIGIN_RPID_PAIRS) {
promise_test(t => {
let eventWatcher = new EventWatcher(t, window, "message");
var w = window.open(test.origin
+ "/credentialmanager/resources/publickey-get-helper.html?rpId="
+ test.rpId);
return eventWatcher.wait_for("message").then(message => {
assert_equals(message.data, "SUCCESS");
});
}, "navigator.credentials.get({publicKey}) in '" + test.origin
+ "' with valid |rpId| '" + test.rpId + "' should succeed.");
}
const INVALID_ORIGIN_RPID_PAIRS = [
{ 'origin': 'https://google.test:8443',
'rpId': 'localhost' },
{ 'origin': 'https://google.test:8443',
'rpId': 'foo.google.test' },
{ 'origin': 'https://google.test:8443',
'rpId': null },
{ 'origin': 'https://google.test:8443',
'rpId': String(0) },
{ 'origin': 'https://google.test:8443',
'rpId': 'test' },
];
for (let test of INVALID_ORIGIN_RPID_PAIRS) {
promise_test(t => {
let eventWatcher = new EventWatcher(t, window, "message");
var w = window.open(test.origin
+ "/credentialmanager/resources/publickey-get-helper.html?rpId="
+ test.rpId);
return eventWatcher.wait_for("message").then(message => {
assert_equals(message.data, "SecurityError");
});
}, "navigator.credentials.get({publicKey}) in '" + test.origin
+ "' with invalid |rpId| '" + test.rpId + "' should fail.");
}
</script>