blob: c75f0ba2ae2a1950b710e5a8263b6e52dd4242fa [file] [log] [blame]
<html>
<body>
<p>This test makes sure that navigator.unregisterProtocolHandler throws the proper exceptions and has no-op default implementation.</p>
<pre id="console"></pre>
<script>
if (window.testRunner)
testRunner.dumpAsText();
function debug(str)
{
var c = document.getElementById('console')
c.appendChild(document.createTextNode(str + '\n'));
}
if (window.navigator.unregisterProtocolHandler)
debug('Pass: window.navigator.unregisterProtocolHandler is defined.');
else
debug('Fail: window.navigator.unregisterProtocolHandler is not defined.');
var invalid_protocols = ['http', 'https', 'file', 'web+'];
invalid_protocols.forEach(function (protocol) {
var succeeded = false;
try {
window.navigator.unregisterProtocolHandler(protocol, "invalid protocol %s", "title");
} catch (e) {
succeeded = 'SecurityError' == e.name;
}
if (succeeded)
debug('Pass: Invalid protocol "' + protocol + '" threw SecurityError exception.');
else
debug('Fail: Invalid protocol "' + protocol + '" allowed.');
});
var valid_protocols = ['bitcoin', 'BitcoIn', 'geo', 'im', 'irc', 'Irc', 'ircs', 'magnet', 'MagneT', 'mailto', 'mms', 'news', 'nntp', 'sip', 'sms', 'smsto', 'SmsTo', 'ssh', 'tel', 'urn', 'webcal', 'WebCAL', 'wtai', 'WTAI', 'xmpp'];
valid_protocols.forEach(function (protocol) {
var succeeded = false;
try {
window.navigator.unregisterProtocolHandler(protocol, "valid protocol %s", "title");
succeeded = true;
} catch (e) {
succeeded = false;
}
if (succeeded)
debug('Pass: Valid protocol "' + protocol + '" allowed.');
else
debug('Fail: Valid protocol "' + protocol + '" failed.');
});
var invalid_schemes = ['mailto:', 'ssh:/', 'magnet:+', 'tel:sip'];
invalid_schemes.forEach(function (scheme) {
var succeeded = false;
try {
window.navigator.unregisterProtocolHandler(scheme, 'invalid scheme uri=%s', 'title');
} catch (e) {
succeeded = true;
}
if (succeeded)
debug('Pass: Invalid scheme "' + scheme + '" failed.');
else
debug('Fail: Invalid scheme "' + scheme + '" allowed.');
});
var invalid_urls = ["", "%S"];
invalid_urls.forEach(function (url) {
var succeeded = false;
try {
window.navigator.unregisterProtocolHandler('web+myprotocol', url, 'title');
} catch (e) {
succeeded = 'SyntaxError' == e.name;
}
if (succeeded)
debug('Pass: Invalid url "' + url + '" threw SyntaxError exception.');
else
debug('Fail: Invalid url "' + url + '" allowed.');
});
// Test that the API has default no-op implementation.
var succeeded = true;
try {
window.navigator.unregisterProtocolHandler('web+myprotocol', "%s", "title");
} catch (e) {
succeeded = false;
}
if (succeeded)
debug('Pass: Valid call succeeded.');
else
debug('Fail: Invalid call did not succeed.');
</script>
</body>
</html>