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.unregisterProtocolHandler throws the prop
er exceptions and has no-op default implementation.</p> | 6 <p>This test makes sure that navigator.unregisterProtocolHandler throws the prop
er 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.unregisterProtocolHandler) | 15 if (window.navigator.unregisterProtocolHandler) |
16 debug('Pass: window.navigator.unregisterProtocolHandler is defined.'); | 16 debug('PASS window.navigator.unregisterProtocolHandler is defined.'); |
17 else | 17 else |
18 debug('Fail: window.navigator.unregisterProtocolHandler is not defined.'); | 18 debug('FAIL window.navigator.unregisterProtocolHandler 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 try { | 23 try { |
24 window.navigator.unregisterProtocolHandler(protocol, "invalid protocol %
s", "title"); | 24 window.navigator.unregisterProtocolHandler(protocol, "invalid protocol %
s", "title"); |
25 } catch (e) { | 25 } catch (e) { |
26 succeeded = 'SecurityError' == e.name; | 26 succeeded = 'SecurityError' == e.name; |
27 errorMessage = e.message; | 27 errorMessage = e.message; |
28 } | 28 } |
29 | 29 |
30 if (succeeded) | 30 if (succeeded) |
31 debug('Pass: Invalid protocol "' + protocol + '" threw SecurityError exc
eption: "' + errorMessage + '".'); | 31 debug('PASS Invalid protocol "' + protocol + '" threw SecurityError exce
ption: "' + errorMessage + '".'); |
32 else | 32 else |
33 debug('Fail: Invalid protocol "' + protocol + '" allowed.'); | 33 debug('FAIL Invalid protocol "' + protocol + '" allowed.'); |
34 }); | 34 }); |
35 | 35 |
36 var valid_protocols = ['bitcoin', 'geo', 'im', 'irc', 'ircs', 'magnet', 'mailto'
, 'mms', 'news', 'nntp', 'sip', 'sms', 'smsto', 'ssh', 'tel', 'urn', 'webcal', '
wtai', 'xmpp']; | 36 var valid_protocols = ['bitcoin', 'geo', 'im', 'irc', 'ircs', 'magnet', 'mailto'
, 'mms', 'news', 'nntp', 'sip', 'sms', 'smsto', 'ssh', 'tel', 'urn', 'webcal', '
wtai', 'xmpp']; |
37 valid_protocols.forEach(function (protocol) { | 37 valid_protocols.forEach(function (protocol) { |
38 var succeeded = false; | 38 var succeeded = false; |
39 try { | 39 try { |
40 window.navigator.unregisterProtocolHandler(protocol, "valid protocol %s"
, "title"); | 40 window.navigator.unregisterProtocolHandler(protocol, "valid protocol %s"
, "title"); |
41 succeeded = true; | 41 succeeded = true; |
42 } catch (e) { | 42 } catch (e) { |
43 succeeded = false; | 43 succeeded = false; |
44 } | 44 } |
45 | 45 |
46 if (succeeded) | 46 if (succeeded) |
47 debug('Pass: Valid protocol "' + protocol + '" allowed.'); | 47 debug('PASS Valid protocol "' + protocol + '" allowed.'); |
48 else | 48 else |
49 debug('Fail: Valid protocol "' + protocol + '" failed.'); | 49 debug('FAIL Valid protocol "' + protocol + '" failed.'); |
50 }); | 50 }); |
51 | 51 |
52 var invalid_schemes = ['mailto:', 'ssh:/', 'magnet:+', 'tel:sip']; | 52 var invalid_schemes = ['mailto:', 'ssh:/', 'magnet:+', 'tel:sip']; |
53 invalid_schemes.forEach(function (scheme) { | 53 invalid_schemes.forEach(function (scheme) { |
54 var succeeded = false; | 54 var succeeded = false; |
55 try { | 55 try { |
56 window.navigator.unregisterProtocolHandler(scheme, 'invalid scheme uri=%
s', 'title'); | 56 window.navigator.unregisterProtocolHandler(scheme, 'invalid scheme uri=%
s', 'title'); |
57 } catch (e) { | 57 } catch (e) { |
58 succeeded = 'SyntaxError' == e.name; | 58 succeeded = 'SyntaxError' == e.name; |
59 errorMessage = e.message; | 59 errorMessage = e.message; |
60 } | 60 } |
61 | 61 |
62 if (succeeded) | 62 if (succeeded) |
63 debug('Pass: Invalid scheme "' + scheme + '" falied.'); | 63 debug('PASS Invalid scheme "' + scheme + '" falied.'); |
64 else | 64 else |
65 debug('Fail: Invalid scheme "' + scheme + '" allowed. Threw exception: "
' + errorMessage + '".'); | 65 debug('Fail: Invalid scheme "' + scheme + '" allowed. Threw exception: "
' + errorMessage + '".'); |
66 }); | 66 }); |
67 | 67 |
68 var invalid_urls = ["", "%S"]; | 68 var invalid_urls = ["", "%S"]; |
69 invalid_urls.forEach(function (url) { | 69 invalid_urls.forEach(function (url) { |
70 var succeeded = false; | 70 var succeeded = false; |
71 try { | 71 try { |
72 window.navigator.unregisterProtocolHandler('web+myprotocol', url, 'title
'); | 72 window.navigator.unregisterProtocolHandler('web+myprotocol', url, 'title
'); |
73 } catch (e) { | 73 } catch (e) { |
74 succeeded = 'SyntaxError' == e.name; | 74 succeeded = 'SyntaxError' == e.name; |
75 errorMessage = e.message; | 75 errorMessage = e.message; |
76 } | 76 } |
77 | 77 |
78 if (succeeded) | 78 if (succeeded) |
79 debug('Pass: Invalid url "' + url + '" threw SyntaxError exception.' + e
rrorMessage + '".'); | 79 debug('PASS Invalid url "' + url + '" threw SyntaxError exception.' + er
rorMessage + '".'); |
80 else | 80 else |
81 debug('Fail: Invalid url "' + url + '" allowed.'); | 81 debug('FAIL Invalid url "' + url + '" allowed.'); |
82 }); | 82 }); |
83 | 83 |
84 // Test that the API has default no-op implementation. | 84 // Test that the API has default no-op implementation. |
85 var succeeded = true; | 85 var succeeded = true; |
86 try { | 86 try { |
87 window.navigator.unregisterProtocolHandler('web+myprotocol', "%s", "title"); | 87 window.navigator.unregisterProtocolHandler('web+myprotocol', "%s", "title"); |
88 } catch (e) { | 88 } catch (e) { |
89 succeeded = false; | 89 succeeded = false; |
90 } | 90 } |
91 | 91 |
92 if (succeeded) | 92 if (succeeded) |
93 debug('Pass: Valid call succeeded.'); | 93 debug('PASS Valid call succeeded.'); |
94 else | 94 else |
95 debug('Fail: Invalid call did not succeed.'); | 95 debug('FAIL Invalid call did not succeed.'); |
| 96 |
| 97 // Check if unregisterProtocolHandler can unregister protocol. |
| 98 debug("\nCheck if unregisterProtocolHandler can unregister protocol correctly. I
f isProtocolHandlerRegistered() returns 'new' state, unregisterProtoclHandler()
works well."); |
| 99 debug("'bitcoin' protocol will be registered and unregistered for testing.\n"); |
| 100 try { |
| 101 // Register 'bitcoin' protocol for testing. |
| 102 window.navigator.registerProtocolHandler('bitcoin', 'invalid scheme uri=%s',
'title'); |
| 103 var state = window.navigator.isProtocolHandlerRegistered('bitcoin', 'valid p
rotocol %s'); |
| 104 if (state == "registered") |
| 105 debug("PASS window.navigator.isProtocolHandlerRegistered returns 'regist
ered' state. 'bitcoin' is registered successfully."); |
| 106 else if (state == "new") |
| 107 debug("FAIL window.navigator.isProtocolHandlerRegistered returns 'new' s
tate. Fail to register 'bitcoin' protocol."); |
| 108 else if (state == "declined") |
| 109 debug("FAIL window.navigator.isProtocolHandlerRegistered returns 'declin
ed' state. Fail to register 'bitcoin' protocol."); |
| 110 |
| 111 window.navigator.unregisterProtocolHandler('bitcoin', 'invalid scheme uri=%s
'); |
| 112 var state = window.navigator.isProtocolHandlerRegistered('bitcoin', 'valid p
rotocol %s'); |
| 113 if (state == "new") |
| 114 debug("PASS window.navigator.isProtocolHandlerRegistered returns 'new' s
tate. 'bitcoin' is unregistered successfully."); |
| 115 else if (state == "registered") |
| 116 debug("FAIL window.navigator.isProtocolHandlerRegistered returns 'regist
ered' state. Fail to unregister 'bitcoin' protocol."); |
| 117 else if (state == "declined") |
| 118 debug("FAIL window.navigator.isProtocolHandlerRegistered returns 'declin
ed' state. Fail to unregister 'bitcoin' protocol."); |
| 119 } catch (e) { |
| 120 debug('FAIL window.navigator.isProtocolHandlerRegistered call is failed: "'
+ e.message + '".'); |
| 121 } |
| 122 debug("\n"); |
| 123 |
96 </script> | 124 </script> |
97 </body> | 125 </body> |
98 </html> | 126 </html> |
OLD | NEW |