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.registerProtocolHandler throws the proper
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.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 exce
ption: "' + errorMessage + '".'); | |
33 }else | |
34 debug('FAIL Invalid protocol "' + protocol + '" allowed.'); | |
35 }); | |
36 | |
37 var valid_protocols = ['bitcoin', 'BitcoIn', 'geo', 'im', 'irc', 'Irc', 'ircs',
'magnet', 'MagneT', 'mailto', 'mms', 'news', 'nntp', 'sip', 'sms', 'smsto', 'Sms
To', 'ssh', 'tel', 'urn', 'webcal', 'WebCAL', 'wtai', '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_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 = 'SyntaxError' == e.name; | |
60 errorMessage = e.message; | |
61 } | |
62 | |
63 if (succeeded) | |
64 debug('PASS Invalid scheme "' + scheme + '" falied.'); | |
65 else | |
66 debug('Fail: Invalid scheme "' + scheme + '" allowed. Threw exception: "
' + errorMessage + '".'); | |
67 }); | |
68 | |
69 var invalid_urls = ["", "%S"]; | |
70 invalid_urls.forEach(function (url) { | |
71 var succeeded = false; | |
72 try { | |
73 window.navigator.registerProtocolHandler('web+myprotocol', url, 'title')
; | |
74 } catch (e) { | |
75 succeeded = 'SyntaxError' == e.name; | |
76 errorMessage = e.message; | |
77 } | |
78 | |
79 if (succeeded) | |
80 debug('PASS Invalid url "' + url + '" threw SyntaxError exception: "' +
errorMessage + '".'); | |
81 else | |
82 debug('FAIL Invalid url "' + url + '" allowed.'); | |
83 }); | |
84 | |
85 // Test that the API has default no-op implementation. | |
86 var succeeded = true; | |
87 try { | |
88 window.navigator.registerProtocolHandler('web+myprotocol', "%s", "title"); | |
89 } catch (e) { | |
90 succeeded = false; | |
91 } | |
92 | |
93 if (succeeded) | |
94 debug('PASS Valid call succeeded.'); | |
95 else | |
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 | |
117 </script> | |
118 </body> | |
119 </html> | |
OLD | NEW |