OLD | NEW |
1 <html> | 1 <html> |
| 2 <head> |
| 3 <script src="../../../resources/js-test.js"></script> |
| 4 </head> |
2 <body> | 5 <body> |
3 <p>This test makes sure that navigator.registerProtocolHandler throws the proper
exceptions and has no-op default implementation.</p> | 6 <p>This test makes sure that navigator.registerProtocolHandler throws the proper
exceptions and has no-op default implementation.</p> |
4 <pre id="console"></pre> | 7 <pre id="console"></pre> |
5 <script> | 8 <script> |
6 if (window.testRunner) | 9 if (window.testRunner) |
7 testRunner.dumpAsText(); | 10 testRunner.dumpAsText(); |
8 | 11 |
9 function debug(str) | 12 if (window.internals) |
10 { | 13 internals.setNavigatorContentUtilsClientMock(document); |
11 var c = document.getElementById('console') | |
12 c.appendChild(document.createTextNode(str + '\n')); | |
13 } | |
14 | 14 |
15 if (window.navigator.registerProtocolHandler) | 15 if (window.navigator.registerProtocolHandler) |
16 debug('Pass: window.navigator.registerProtocolHandler is defined.'); | 16 debug('PASS window.navigator.registerProtocolHandler is defined.'); |
17 else | 17 else |
18 debug('Fail: window.navigator.registerProtocolHandler is not defined.'); | 18 debug('FAIL window.navigator.registerProtocolHandler is not defined.'); |
19 | 19 |
20 var invalid_protocols = ['http', 'https', 'file', 'web+']; | 20 var invalid_protocols = ['http', 'https', 'file', 'web+']; |
21 invalid_protocols.forEach(function (protocol) { | 21 invalid_protocols.forEach(function (protocol) { |
22 var succeeded = false; | 22 var succeeded = false; |
23 var errorMessage; | 23 var errorMessage; |
24 try { | 24 try { |
25 window.navigator.registerProtocolHandler(protocol, "invalid protocol %s"
, "title"); | 25 window.navigator.registerProtocolHandler(protocol, "invalid protocol %s"
, "title"); |
26 } catch (e) { | 26 } catch (e) { |
27 succeeded = 'SecurityError' == e.name; | 27 succeeded = 'SecurityError' == e.name; |
28 errorMessage = e.message; | 28 errorMessage = e.message; |
29 } | 29 } |
30 | 30 |
31 if (succeeded) { | 31 if (succeeded) { |
32 debug('Pass: Invalid protocol "' + protocol + '" threw SecurityError exc
eption: "' + errorMessage + '".'); | 32 debug('PASS Invalid protocol "' + protocol + '" threw SecurityError exce
ption: "' + errorMessage + '".'); |
33 }else | 33 }else |
34 debug('Fail: Invalid protocol "' + protocol + '" allowed.'); | 34 debug('FAIL Invalid protocol "' + protocol + '" allowed.'); |
35 }); | 35 }); |
36 | 36 |
37 var valid_protocols = ['bitcoin', 'geo', 'im', 'irc', 'ircs', 'magnet', 'mailto'
, 'mms', 'news', 'nntp', 'sip', 'sms', 'smsto', 'ssh', 'tel', 'urn', 'webcal', '
wtai', 'xmpp']; | 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) { | 38 valid_protocols.forEach(function (protocol) { |
39 var succeeded = false; | 39 var succeeded = false; |
40 try { | 40 try { |
41 window.navigator.registerProtocolHandler(protocol, "valid protocol %s",
"title"); | 41 window.navigator.registerProtocolHandler(protocol, "valid protocol %s",
"title"); |
42 succeeded = true; | 42 succeeded = true; |
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']; | 53 var invalid_schemes = ['mailto:', 'ssh:/', 'magnet:+', 'tel:sip']; |
54 invalid_schemes.forEach(function (scheme) { | 54 invalid_schemes.forEach(function (scheme) { |
55 var succeeded = false; | 55 var succeeded = false; |
56 try { | 56 try { |
57 window.navigator.registerProtocolHandler(scheme, 'invalid scheme uri=%s'
, 'title'); | 57 window.navigator.registerProtocolHandler(scheme, 'invalid scheme uri=%s'
, 'title'); |
58 } catch (e) { | 58 } catch (e) { |
59 succeeded = 'SyntaxError' == e.name; | 59 succeeded = 'SyntaxError' == e.name; |
60 errorMessage = e.message; | 60 errorMessage = e.message; |
61 } | 61 } |
62 | 62 |
63 if (succeeded) | 63 if (succeeded) |
64 debug('Pass: Invalid scheme "' + scheme + '" falied.'); | 64 debug('PASS Invalid scheme "' + scheme + '" falied.'); |
65 else | 65 else |
66 debug('Fail: Invalid scheme "' + scheme + '" allowed. Threw exception: "
' + errorMessage + '".'); | 66 debug('Fail: Invalid scheme "' + scheme + '" allowed. Threw exception: "
' + errorMessage + '".'); |
67 }); | 67 }); |
68 | 68 |
69 var invalid_urls = ["", "%S"]; | 69 var invalid_urls = ["", "%S"]; |
70 invalid_urls.forEach(function (url) { | 70 invalid_urls.forEach(function (url) { |
71 var succeeded = false; | 71 var succeeded = false; |
72 try { | 72 try { |
73 window.navigator.registerProtocolHandler('web+myprotocol', url, 'title')
; | 73 window.navigator.registerProtocolHandler('web+myprotocol', url, 'title')
; |
74 } catch (e) { | 74 } catch (e) { |
75 succeeded = 'SyntaxError' == e.name; | 75 succeeded = 'SyntaxError' == e.name; |
76 errorMessage = e.message; | 76 errorMessage = e.message; |
77 } | 77 } |
78 | 78 |
79 if (succeeded) | 79 if (succeeded) |
80 debug('Pass: Invalid url "' + url + '" threw SyntaxError exception: "' +
errorMessage + '".'); | 80 debug('PASS Invalid url "' + url + '" threw SyntaxError exception: "' +
errorMessage + '".'); |
81 else | 81 else |
82 debug('Fail: Invalid url "' + url + '" allowed.'); | 82 debug('FAIL Invalid url "' + url + '" allowed.'); |
83 }); | 83 }); |
84 | 84 |
85 // Test that the API has default no-op implementation. | 85 // Test that the API has default no-op implementation. |
86 var succeeded = true; | 86 var succeeded = true; |
87 try { | 87 try { |
88 window.navigator.registerProtocolHandler('web+myprotocol', "%s", "title"); | 88 window.navigator.registerProtocolHandler('web+myprotocol', "%s", "title"); |
89 } catch (e) { | 89 } catch (e) { |
90 succeeded = false; | 90 succeeded = false; |
91 } | 91 } |
92 | 92 |
93 if (succeeded) | 93 if (succeeded) |
94 debug('Pass: Valid call succeeded.'); | 94 debug('PASS Valid call succeeded.'); |
95 else | 95 else |
96 debug('Fail: Invalid call did not succeed.'); | 96 debug('FAIL Invalid call did not succeed.'); |
| 97 |
| 98 // Check if registerProtocolHandler can register protocol. |
| 99 debug("\nCheck if registerProtocolHandler can register protocol correctly. If is
ProtocolHandlerRegistered() returns 'registered' state, registerProtoclHandler()
works well."); |
| 100 debug("'bitcoin' protocol will be registered for testing.\n"); |
| 101 try { |
| 102 // Register 'bitcoin' protocol for testing. |
| 103 window.navigator.registerProtocolHandler('bitcoin', 'invalid scheme uri=%s',
'title'); |
| 104 |
| 105 var state = window.navigator.isProtocolHandlerRegistered('bitcoin', 'valid p
rotocol %s'); |
| 106 if (state == "registered") |
| 107 debug("PASS window.navigator.isProtocolHandlerRegistered returns 'regist
ered' state. 'bitcoin' is registered successfully."); |
| 108 else if (state == "new") |
| 109 debug("FAIL window.navigator.isProtocolHandlerRegistered returns 'new' s
tate. Fail to register 'bitcoin' protocol."); |
| 110 else if (state == "declined") |
| 111 debug("FAIL window.navigator.isProtocolHandlerRegistered returns 'declin
ed' state. Fail to register 'bitcoin' protocol"); |
| 112 } catch (e) { |
| 113 debug('FAIL window.navigator.isProtocolHandlerRegistered call is failed: "'
+ e.message + '".'); |
| 114 } |
| 115 debug("\n"); |
| 116 |
97 </script> | 117 </script> |
98 </body> | 118 </body> |
99 </html> | 119 </html> |
OLD | NEW |