OLD | NEW |
| (Empty) |
1 <html> | |
2 <head> | |
3 <script src="../resources/js-test.js"></script> | |
4 </head> | |
5 <body> | |
6 <p>This test makes sure that navigator.unregisterProtocolHandler throws the prop
er exceptions and has no-op default implementation.</p> | |
7 <pre id="console"></pre> | |
8 <script> | |
9 if (window.testRunner) | |
10 testRunner.dumpAsText(); | |
11 | |
12 if (window.internals) | |
13 internals.setNavigatorContentUtilsClientMock(document); | |
14 | |
15 if (window.navigator.unregisterProtocolHandler) | |
16 debug('PASS window.navigator.unregisterProtocolHandler is defined.'); | |
17 else | |
18 debug('FAIL window.navigator.unregisterProtocolHandler is not defined.'); | |
19 | |
20 var invalid_schemes = ['http', 'https', 'file', 'web+']; | |
21 invalid_schemes.forEach(function (scheme) { | |
22 var succeeded = false; | |
23 try { | |
24 window.navigator.unregisterProtocolHandler(scheme, "invalid scheme %s",
"title"); | |
25 } catch (e) { | |
26 succeeded = 'SecurityError' == e.name; | |
27 errorMessage = e.message; | |
28 } | |
29 | |
30 if (succeeded) | |
31 debug('PASS Invalid scheme "' + scheme + '" threw SecurityError exceptio
n: "' + errorMessage + '".'); | |
32 else | |
33 debug('FAIL Invalid scheme "' + scheme + '" allowed.'); | |
34 }); | |
35 | |
36 var valid_schemes = ['bitcoin', 'BitcoIn', 'geo', 'im', 'irc', 'Irc', 'ircs', 'm
agnet', 'MagneT', 'mailto', 'mms', 'news', 'nntp', 'sip', 'sms', 'smsto', 'SmsTo
', 'ssh', 'tel', 'urn', 'webcal', 'WebCAL', 'wtai', 'WTAI', 'xmpp']; | |
37 valid_schemes.forEach(function (scheme) { | |
38 var succeeded = false; | |
39 try { | |
40 window.navigator.unregisterProtocolHandler(scheme, "valid scheme %s", "t
itle"); | |
41 succeeded = true; | |
42 } catch (e) { | |
43 succeeded = false; | |
44 } | |
45 | |
46 if (succeeded) | |
47 debug('PASS Valid scheme "' + scheme + '" allowed.'); | |
48 else | |
49 debug('FAIL Valid scheme "' + scheme + '" failed.'); | |
50 }); | |
51 | |
52 var invalid_schemes = ['mailto:', 'ssh:/', 'magnet:+', 'tel:sip']; | |
53 invalid_schemes.forEach(function (scheme) { | |
54 var succeeded = false; | |
55 try { | |
56 window.navigator.unregisterProtocolHandler(scheme, 'invalid scheme uri=%
s', 'title'); | |
57 } catch (e) { | |
58 succeeded = 'SecurityError' == e.name; | |
59 errorMessage = e.message; | |
60 } | |
61 | |
62 if (succeeded) | |
63 debug('PASS Invalid scheme "' + scheme + '" falied.'); | |
64 else | |
65 debug('Fail: Invalid scheme "' + scheme + '" allowed. Threw exception: "
' + errorMessage + '".'); | |
66 }); | |
67 | |
68 var invalid_urls = ["", "%S"]; | |
69 invalid_urls.forEach(function (url) { | |
70 var succeeded = false; | |
71 try { | |
72 window.navigator.unregisterProtocolHandler('web+myscheme', url, 'title')
; | |
73 } catch (e) { | |
74 succeeded = 'SyntaxError' == e.name; | |
75 errorMessage = e.message; | |
76 } | |
77 | |
78 if (succeeded) | |
79 debug('PASS Invalid url "' + url + '" threw SyntaxError exception.' + er
rorMessage + '".'); | |
80 else | |
81 debug('FAIL Invalid url "' + url + '" allowed.'); | |
82 }); | |
83 | |
84 // Test that the API has default no-op implementation. | |
85 var succeeded = true; | |
86 try { | |
87 window.navigator.unregisterProtocolHandler('web+myscheme', "%s", "title"); | |
88 } catch (e) { | |
89 succeeded = false; | |
90 } | |
91 | |
92 if (succeeded) | |
93 debug('PASS Valid call succeeded.'); | |
94 else | |
95 debug('FAIL Invalid call did not succeed.'); | |
96 | |
97 // Check if unregisterProtocolHandler can unregister scheme. | |
98 debug("\nCheck if unregisterProtocolHandler can unregister scheme correctly. If
isProtocolHandlerRegistered() returns 'new' state, unregisterProtoclHandler() wo
rks well."); | |
99 debug("'bitcoin' scheme will be registered and unregistered for testing.\n"); | |
100 try { | |
101 // Register 'bitcoin' scheme for testing. | |
102 window.navigator.registerProtocolHandler('bitcoin', 'invalid scheme uri=%s',
'title'); | |
103 var state = window.navigator.isProtocolHandlerRegistered('bitcoin', 'valid s
cheme %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' scheme."); | |
108 else if (state == "declined") | |
109 debug("FAIL window.navigator.isProtocolHandlerRegistered returns 'declin
ed' state. Fail to register 'bitcoin' scheme."); | |
110 | |
111 window.navigator.unregisterProtocolHandler('bitcoin', 'invalid scheme uri=%s
'); | |
112 var state = window.navigator.isProtocolHandlerRegistered('bitcoin', 'valid s
cheme %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' scheme."); | |
117 else if (state == "declined") | |
118 debug("FAIL window.navigator.isProtocolHandlerRegistered returns 'declin
ed' state. Fail to unregister 'bitcoin' scheme."); | |
119 } catch (e) { | |
120 debug('FAIL window.navigator.isProtocolHandlerRegistered call is failed: "'
+ e.message + '".'); | |
121 } | |
122 debug("\n"); | |
123 | |
124 </script> | |
125 </body> | |
126 </html> | |
OLD | NEW |