OLD | NEW |
| (Empty) |
1 <html> | |
2 <body> | |
3 <p>This test makes sure that navigator.registerProtocolHandler throws the proper
exceptions and has no-op default implementation.</p> | |
4 <pre id="console"></pre> | |
5 <script> | |
6 if (window.testRunner) | |
7 testRunner.dumpAsText(); | |
8 | |
9 function debug(str) | |
10 { | |
11 var c = document.getElementById('console') | |
12 c.appendChild(document.createTextNode(str + '\n')); | |
13 } | |
14 | |
15 if (window.navigator.registerProtocolHandler) | |
16 debug('Pass: window.navigator.registerProtocolHandler is defined.'); | |
17 else | |
18 debug('Fail: window.navigator.registerProtocolHandler is not defined.'); | |
19 | |
20 var invalid_protocols = ['http', 'https', 'file', 'web+']; | |
21 invalid_protocols.forEach(function (protocol) { | |
22 var succeeded = false; | |
23 var errorMessage; | |
24 try { | |
25 window.navigator.registerProtocolHandler(protocol, "invalid protocol %s"
, "title"); | |
26 } catch (e) { | |
27 succeeded = 'SecurityError' == e.name; | |
28 errorMessage = e.message; | |
29 } | |
30 | |
31 if (succeeded) { | |
32 debug('Pass: Invalid protocol "' + protocol + '" threw SecurityError exc
eption: "' + errorMessage + '".'); | |
33 }else | |
34 debug('Fail: Invalid protocol "' + protocol + '" allowed.'); | |
35 }); | |
36 | |
37 var valid_protocols = ['bitcoin', 'geo', 'im', 'irc', 'ircs', 'magnet', 'mailto'
, 'mms', 'news', 'nntp', 'sip', 'sms', 'smsto', 'ssh', 'tel', 'urn', 'webcal', '
wtai', 'xmpp']; | |
38 valid_protocols.forEach(function (protocol) { | |
39 var succeeded = false; | |
40 try { | |
41 window.navigator.registerProtocolHandler(protocol, "valid protocol %s",
"title"); | |
42 succeeded = true; | |
43 } catch (e) { | |
44 succeeded = false; | |
45 } | |
46 | |
47 if (succeeded) | |
48 debug('Pass: Valid protocol "' + protocol + '" allowed.'); | |
49 else | |
50 debug('Fail: Valid protocol "' + protocol + '" failed.'); | |
51 }); | |
52 | |
53 var invalid_urls = ["", "%S"]; | |
54 invalid_urls.forEach(function (url) { | |
55 var succeeded = false; | |
56 try { | |
57 window.navigator.registerProtocolHandler('web+myprotocol', url, 'title')
; | |
58 } catch (e) { | |
59 succeeded = 'SyntaxError' == e.name; | |
60 errorMessage = e.message; | |
61 } | |
62 | |
63 if (succeeded) | |
64 debug('Pass: Invalid url "' + url + '" threw SyntaxError exception: "' +
errorMessage + '".'); | |
65 else | |
66 debug('Fail: Invalid url "' + url + '" allowed.'); | |
67 }); | |
68 | |
69 // Test that the API has default no-op implementation. | |
70 var succeeded = true; | |
71 try { | |
72 window.navigator.registerProtocolHandler('web+myprotocol', "%s", "title"); | |
73 } catch (e) { | |
74 succeeded = false; | |
75 } | |
76 | |
77 if (succeeded) | |
78 debug('Pass: Valid call succeeded.'); | |
79 else | |
80 debug('Fail: Invalid call did not succeed.'); | |
81 </script> | |
82 </body> | |
83 </html> | |
OLD | NEW |