blob: efa54f37c16a54aee2d77330d9ee4a05aa18dfd2 [file] [log] [blame]
<!DOCTYPE html>
<html>
<head>
<script src="/js-test-resources/js-test.js"></script>
</head>
<body>
<p>This test makes sure that navigator.isProtocolHandlerRegistered throws the proper exceptions and returns the default state of handler.</p>
<pre id="console"></pre>
<script>
if (window.internals)
internals.setNavigatorContentUtilsClientMock(document);
if (window.navigator.isProtocolHandlerRegistered)
debug('PASS window.navigator.isProtocolHandlerRegistered is defined.');
else
debug('FAIL window.navigator.isProtocolHandlerRegistered is not defined.');
var invalidUrl = "%S";
var succeeded = false;
try {
window.navigator.isProtocolHandlerRegistered(scheme, invalidUrl);
succeeded = false;
} catch (e) {
succeeded = true;
}
if (succeeded)
debug('PASS Invalid url "' + invalidUrl + '" threw SyntaxError exception.');
else
debug('FAIL Invalid url "' + invalidUrl + '" allowed.');
var invalid_schemes = ['mailto:', 'ssh:/', 'magnet:+', 'tel:sip'];
invalid_schemes.forEach(function (scheme) {
var succeeded = false;
try {
window.navigator.isProtocolHandlerRegistered(scheme, 'invalid scheme uri=%s');
} catch (e) {
succeeded = 'SecurityError' == e.name;
errorMessage = e.message;
}
if (succeeded)
debug('PASS Invalid scheme "' + scheme + '" falied.');
else
debug('FAIL Invalid scheme "' + scheme + '" allowed. Threw exception: "' + errorMessage + '".');
});
// Test that the API throws SecurityError exception if the URL's origin differs from the document's origin.
succeeded = false;
var errorMessage;
try {
window.navigator.isProtocolHandlerRegistered('web+myprotocol', "http://www.example.com/soup?url=%s");
} catch (e) {
succeeded = true;
errorMessage = e.message;
}
if (succeeded)
debug('PASS URL with origin different than document origin threw SecurityError exception: "' + errorMessage + '".');
else
debug('FAIL URL with origin different than document origin is allowed.');
debug("\nCheck if isProtocolHandlerRegistered() works correctly. If isProtocolHandlerRegistered() returns 'new' state, it works well.");
debug("'bitcoin' scheme will be registered, and then checks if the 'bitcoin' scheme is registered by isProtocolHandlerRegistered().\n");
try {
// Register 'bitcoin' scheme for testing.
window.navigator.registerProtocolHandler('bitcoin', 'invalid scheme uri=%s', 'title');
var state = window.navigator.isProtocolHandlerRegistered("bitcoin", "valid scheme %s");
if (state == "registered")
debug("PASS window.navigator.isProtocolHandlerRegistered returns 'registered' state. isProtocolHandlerRegistered() works correctly.");
else if (state == "new")
debug("FAIL window.navigator.isProtocolHandlerRegistered returns 'new' state.");
else if (state == "declined")
debug("FAIL window.navigator.isProtocolHandlerRegistered returns 'declined' state.");
} catch (e) {
debug('FAIL window.navigator.isProtocolHandlerRegistered call is failed: "' + e.message + '".');
}
debug("\n");
</script>
</body>
</html>