OLD | NEW |
1 <html> | 1 <html> |
2 <body> | 2 <body> |
3 <p>This test makes sure that navigator.registerProtocolHandler throws the proper
exceptions and has no-op default implementation.</p> | 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> | 4 <pre id="console"></pre> |
5 <script> | 5 <script> |
6 if (window.testRunner) | 6 if (window.testRunner) |
7 testRunner.dumpAsText(); | 7 testRunner.dumpAsText(); |
8 | 8 |
9 function debug(str) | 9 function debug(str) |
10 { | 10 { |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 } catch (e) { | 43 } catch (e) { |
44 succeeded = false; | 44 succeeded = false; |
45 } | 45 } |
46 | 46 |
47 if (succeeded) | 47 if (succeeded) |
48 debug('Pass: Valid protocol "' + protocol + '" allowed.'); | 48 debug('Pass: Valid protocol "' + protocol + '" allowed.'); |
49 else | 49 else |
50 debug('Fail: Valid protocol "' + protocol + '" failed.'); | 50 debug('Fail: Valid protocol "' + protocol + '" failed.'); |
51 }); | 51 }); |
52 | 52 |
| 53 var invalid_schemes = ['mailto:', 'ssh:/', 'magnet:+', 'tel:sip']; |
| 54 invalid_schemes.forEach(function (scheme) { |
| 55 var succeeded = false; |
| 56 try { |
| 57 window.navigator.registerProtocolHandler(scheme, 'invalid scheme uri=%s'
, 'title'); |
| 58 } catch (e) { |
| 59 succeeded = true; |
| 60 } |
| 61 |
| 62 if (succeeded) |
| 63 debug('Pass: Invalid scheme "' + scheme + '" falied.'); |
| 64 else |
| 65 debug('Fail: Invalid scheme "' + scheme + '" allowed.'); |
| 66 }); |
| 67 |
53 var invalid_urls = ["", "%S"]; | 68 var invalid_urls = ["", "%S"]; |
54 invalid_urls.forEach(function (url) { | 69 invalid_urls.forEach(function (url) { |
55 var succeeded = false; | 70 var succeeded = false; |
56 try { | 71 try { |
57 window.navigator.registerProtocolHandler('web+myprotocol', url, 'title')
; | 72 window.navigator.registerProtocolHandler('web+myprotocol', url, 'title')
; |
58 } catch (e) { | 73 } catch (e) { |
59 succeeded = 'SyntaxError' == e.name; | 74 succeeded = 'SyntaxError' == e.name; |
60 errorMessage = e.message; | 75 errorMessage = e.message; |
61 } | 76 } |
62 | 77 |
63 if (succeeded) | 78 if (succeeded) |
64 debug('Pass: Invalid url "' + url + '" threw SyntaxError exception: "' +
errorMessage + '".'); | 79 debug('Pass: Invalid url "' + url + '" threw SyntaxError exception: "' +
errorMessage + '".'); |
65 else | 80 else |
66 debug('Fail: Invalid url "' + url + '" allowed.'); | 81 debug('Fail: Invalid url "' + url + '" allowed.'); |
67 }); | 82 }); |
68 | 83 |
69 // Test that the API has default no-op implementation. | 84 // Test that the API has default no-op implementation. |
70 var succeeded = true; | 85 var succeeded = true; |
71 try { | 86 try { |
72 window.navigator.registerProtocolHandler('web+myprotocol', "%s", "title"); | 87 window.navigator.registerProtocolHandler('web+myprotocol', "%s", "title"); |
73 } catch (e) { | 88 } catch (e) { |
74 succeeded = false; | 89 succeeded = false; |
75 } | 90 } |
76 | 91 |
77 if (succeeded) | 92 if (succeeded) |
78 debug('Pass: Valid call succeeded.'); | 93 debug('Pass: Valid call succeeded.'); |
79 else | 94 else |
80 debug('Fail: Invalid call did not succeed.'); | 95 debug('Fail: Invalid call did not succeed.'); |
81 </script> | 96 </script> |
82 </body> | 97 </body> |
83 </html> | 98 </html> |
OLD | NEW |