OLD | NEW |
1 <html> | 1 <html> |
2 <head> | 2 <head> |
3 <script src="../resources/js-test.js"></script> | 3 <script src="../resources/js-test.js"></script> |
4 </head> | 4 </head> |
5 <body> | 5 <body> |
6 <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> |
7 <pre id="console"></pre> | 7 <pre id="console"></pre> |
8 <script> | 8 <script> |
9 if (window.testRunner) | 9 if (window.testRunner) |
10 testRunner.dumpAsText(); | 10 testRunner.dumpAsText(); |
11 | 11 |
12 if (window.internals) | 12 if (window.internals) |
13 internals.setNavigatorContentUtilsClientMock(document); | 13 internals.setNavigatorContentUtilsClientMock(document); |
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_schemes = ['http', 'https', 'file', 'web+']; |
21 invalid_protocols.forEach(function (protocol) { | 21 invalid_schemes.forEach(function (scheme) { |
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(scheme, "invalid scheme %s", "t
itle"); |
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 exce
ption: "' + errorMessage + '".'); | 32 debug('PASS Invalid scheme "' + scheme + '" threw SecurityError exceptio
n: "' + errorMessage + '".'); |
33 }else | 33 }else |
34 debug('FAIL Invalid protocol "' + protocol + '" allowed.'); | 34 debug('FAIL Invalid scheme "' + scheme + '" allowed.'); |
35 }); | 35 }); |
36 | 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']; | 37 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']; |
38 valid_protocols.forEach(function (protocol) { | 38 valid_schemes.forEach(function (scheme) { |
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(scheme, "valid scheme %s", "tit
le"); |
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 scheme "' + scheme + '" allowed.'); |
49 else | 49 else |
50 debug('FAIL Valid protocol "' + protocol + '" failed.'); | 50 debug('FAIL Valid scheme "' + scheme + '" 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 = 'SecurityError' == e.name; | 59 succeeded = 'SecurityError' == 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+myscheme', 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+myscheme', "%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 | 97 |
98 // Check if registerProtocolHandler can register protocol. | 98 // Check if registerProtocolHandler can register custom scheme. |
99 debug("\nCheck if registerProtocolHandler can register protocol correctly. If is
ProtocolHandlerRegistered() returns 'registered' state, registerProtoclHandler()
works well."); | 99 debug("\nCheck if registerProtocolHandler can register scheme correctly. If isPr
otocolHandlerRegistered() returns 'registered' state, registerProtoclHandler() w
orks well."); |
100 debug("'bitcoin' protocol will be registered for testing.\n"); | 100 debug("'bitcoin' scheme will be registered for testing.\n"); |
101 try { | 101 try { |
102 // Register 'bitcoin' protocol for testing. | 102 // Register 'bitcoin' scheme for testing. |
103 window.navigator.registerProtocolHandler('bitcoin', 'invalid scheme uri=%s',
'title'); | 103 window.navigator.registerProtocolHandler('bitcoin', 'invalid scheme uri=%s',
'title'); |
104 | 104 |
105 var state = window.navigator.isProtocolHandlerRegistered('bitcoin', 'valid p
rotocol %s'); | 105 var state = window.navigator.isProtocolHandlerRegistered('bitcoin', 'valid s
cheme %s'); |
106 if (state == "registered") | 106 if (state == "registered") |
107 debug("PASS window.navigator.isProtocolHandlerRegistered returns 'regist
ered' state. 'bitcoin' is registered successfully."); | 107 debug("PASS window.navigator.isProtocolHandlerRegistered returns 'regist
ered' state. 'bitcoin' is registered successfully."); |
108 else if (state == "new") | 108 else if (state == "new") |
109 debug("FAIL window.navigator.isProtocolHandlerRegistered returns 'new' s
tate. Fail to register 'bitcoin' protocol."); | 109 debug("FAIL window.navigator.isProtocolHandlerRegistered returns 'new' s
tate. Fail to register 'bitcoin' scheme."); |
110 else if (state == "declined") | 110 else if (state == "declined") |
111 debug("FAIL window.navigator.isProtocolHandlerRegistered returns 'declin
ed' state. Fail to register 'bitcoin' protocol"); | 111 debug("FAIL window.navigator.isProtocolHandlerRegistered returns 'declin
ed' state. Fail to register 'bitcoin' scheme"); |
112 } catch (e) { | 112 } catch (e) { |
113 debug('FAIL window.navigator.isProtocolHandlerRegistered call is failed: "'
+ e.message + '".'); | 113 debug('FAIL window.navigator.isProtocolHandlerRegistered call is failed: "'
+ e.message + '".'); |
114 } | 114 } |
115 debug("\n"); | 115 debug("\n"); |
116 | 116 |
117 </script> | 117 </script> |
118 </body> | 118 </body> |
119 </html> | 119 </html> |
OLD | NEW |