3 <script src="/js-test-resources/js-test.js"></script>
6 <p>This test makes sure that navigator.unregisterProtocolHandler throws the proper exceptions and has no-op default implementation.</p>
7 <pre id="console"></pre>
10 internals.setNavigatorContentUtilsClientMock(document);
12 if (window.navigator.unregisterProtocolHandler)
13 debug('PASS window.navigator.unregisterProtocolHandler is defined.');
15 debug('FAIL window.navigator.unregisterProtocolHandler is not defined.');
17 var invalid_schemes = ['http', 'https', 'file', 'web+'];
18 invalid_schemes.forEach(function (scheme) {
19 var succeeded = false;
21 window.navigator.unregisterProtocolHandler(scheme, "invalid scheme %s", "title");
23 succeeded = 'SecurityError' == e.name;
24 errorMessage = e.message;
28 debug('PASS Invalid scheme "' + scheme + '" threw SecurityError exception: "' + errorMessage + '".');
30 debug('FAIL Invalid scheme "' + scheme + '" allowed.');
33 var valid_schemes = ['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'];
34 valid_schemes.forEach(function (scheme) {
35 var succeeded = false;
37 window.navigator.unregisterProtocolHandler(scheme, "valid scheme %s", "title");
44 debug('PASS Valid scheme "' + scheme + '" allowed.');
46 debug('FAIL Valid scheme "' + scheme + '" failed.');
49 var invalid_schemes = ['mailto:', 'ssh:/', 'magnet:+', 'tel:sip'];
50 invalid_schemes.forEach(function (scheme) {
51 var succeeded = false;
53 window.navigator.unregisterProtocolHandler(scheme, 'invalid scheme uri=%s', 'title');
55 succeeded = 'SecurityError' == e.name;
56 errorMessage = e.message;
60 debug('PASS Invalid scheme "' + scheme + '" falied.');
62 debug('Fail: Invalid scheme "' + scheme + '" allowed. Threw exception: "' + errorMessage + '".');
65 var invalid_urls = ["", "%S"];
66 invalid_urls.forEach(function (url) {
67 var succeeded = false;
69 window.navigator.unregisterProtocolHandler('web+myscheme', url, 'title');
71 succeeded = 'SyntaxError' == e.name;
72 errorMessage = e.message;
76 debug('PASS Invalid url "' + url + '" threw SyntaxError exception.' + errorMessage + '".');
78 debug('FAIL Invalid url "' + url + '" allowed.');
81 // Test that the API throws SecurityError exception if the URL's origin differs from the document's origin.
85 window.navigator.unregisterProtocolHandler('web+myprotocol', "http://www.example.com/soup?url=%s", "title");
88 errorMessage = e.message;
92 debug('PASS URL with origin different than document origin threw SecurityError exception: "' + errorMessage + '".');
94 debug('FAIL URL with origin different than document origin is allowed.');
96 // Test that the API has default no-op implementation.
99 window.navigator.unregisterProtocolHandler('web+myscheme', "%s", "title");
105 debug('PASS Valid call succeeded.');
107 debug('FAIL Invalid call did not succeed.');
109 // Check if unregisterProtocolHandler can unregister scheme.
110 debug("\nCheck if unregisterProtocolHandler can unregister scheme correctly. If isProtocolHandlerRegistered() returns 'new' state, unregisterProtoclHandler() works well.");
111 debug("'bitcoin' scheme will be registered and unregistered for testing.\n");
113 // Register 'bitcoin' scheme for testing.
114 window.navigator.registerProtocolHandler('bitcoin', 'invalid scheme uri=%s', 'title');
115 var state = window.navigator.isProtocolHandlerRegistered('bitcoin', 'valid scheme %s');
116 if (state == "registered")
117 debug("PASS window.navigator.isProtocolHandlerRegistered returns 'registered' state. 'bitcoin' is registered successfully.");
118 else if (state == "new")
119 debug("FAIL window.navigator.isProtocolHandlerRegistered returns 'new' state. Fail to register 'bitcoin' scheme.");
120 else if (state == "declined")
121 debug("FAIL window.navigator.isProtocolHandlerRegistered returns 'declined' state. Fail to register 'bitcoin' scheme.");
123 window.navigator.unregisterProtocolHandler('bitcoin', 'invalid scheme uri=%s');
124 var state = window.navigator.isProtocolHandlerRegistered('bitcoin', 'valid scheme %s');
126 debug("PASS window.navigator.isProtocolHandlerRegistered returns 'new' state. 'bitcoin' is unregistered successfully.");
127 else if (state == "registered")
128 debug("FAIL window.navigator.isProtocolHandlerRegistered returns 'registered' state. Fail to unregister 'bitcoin' scheme.");
129 else if (state == "declined")
130 debug("FAIL window.navigator.isProtocolHandlerRegistered returns 'declined' state. Fail to unregister 'bitcoin' scheme.");
132 debug('FAIL window.navigator.isProtocolHandlerRegistered call is failed: "' + e.message + '".');