Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(78)

Side by Side Diff: LayoutTests/imported/web-platform-tests/html/webappapis/system-state-and-capabilities/the-navigator-object/protocol.html

Issue 1166693007: W3C Test: import web-platform-tests/html/webappapis (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 <!DOCTYPE html>
2 <meta charset='utf-8'>
3 <title>registerProtocolHandler()</title>
4
5 <script src='../../../../../../resources/testharness.js'></script>
6 <script src='../../../../../../resources/testharnessreport.js'></script>
7
8 <noscript><p>Enable JavaScript and reload.</p></noscript>
9
10 <p><strong>Note:</strong> If your browser limits the number of handler
11 registration requests on a page, you might need to disable or significantly
12 increase that limit for the tests below to run.</p>
13
14 <div id='log'></div>
15
16 <script type='text/javascript'>
17
18 test(function () {
19 assert_idl_attribute(navigator, 'registerProtocolHandler');
20 }, 'the registerProtocolHandler method should exist on the navigator object');
21
22 test(function () {
23 navigator.registerProtocolHandler('tel', location.href + '/%s', 'foo');
24 }, 'a handler with valid arguments should work');
25
26
27 /* URL argument */
28 test(function () {
29 navigator.registerProtocolHandler('tel', '%s', 'foo');
30 }, 'a relative URL should work');
31
32 test(function () {
33 navigator.registerProtocolHandler('tel', location.href + '#%s', 'foo');
34 }, 'a URL with a fragment identifier should work');
35
36 test(function () {
37 navigator.registerProtocolHandler('tel', location.href + '?foo=%s', 'foo');
38 }, 'a URL with a query string should work');
39
40 test(function () {
41 navigator.registerProtocolHandler('tel', location.href + '?foo=%s&bar', 'foo') ;
42 }, 'a URL with a multi-argument query string should work');
43
44 test(function () {
45 navigator.registerProtocolHandler('tel', location.href + '/%s/bar/baz/', 'foo' );
46 }, 'a URL with the passed string as a directory name should work');
47
48 test(function () {
49 navigator.registerProtocolHandler('tel', location.href + '/%s/bar/baz/?foo=133 7&bar#baz', 'foo');
50 }, 'a URL with the passed string as a directory name followed by a query string and fragment identifier should work');
51
52 test(function () {
53 navigator.registerProtocolHandler('tel', location.href + '/%s/foo/%s/', 'foo') ;
54 }, 'a URL with the passed string included twice should work');
55
56 test(function () {
57 assert_throws('SYNTAX_ERR', function () { navigator.registerProtocolHandler('m ailto', '', 'foo') } );
58 }, 'an empty url argument should throw SYNTAX_ERR');
59
60 test(function () {
61 assert_throws('SYNTAX_ERR', function () { navigator.registerProtocolHandler('m ailto', 'http://%s.com', 'foo') } );
62 }, '%s instead of domain name should throw SYNTAX_ERR');
63
64 test(function () {
65 assert_throws('SYNTAX_ERR', function () { navigator.registerProtocolHandler('m ailto', 'http://%s.example.com', 'foo') } );
66 }, '%s instead of subdomain name should throw SYNTAX_ERR');
67
68 test(function () {
69 assert_throws('SYNTAX_ERR', function () { navigator.registerProtocolHandler('m ailto', location.href + '', 'foo') } );
70 }, 'a url argument without %s should throw SYNTAX_ERR');
71
72 test(function () {
73 assert_throws('SYNTAX_ERR', function () { navigator.registerProtocolHandler('m ailto', 'http://example.com', 'foo') } );
74 }, 'a url argument pointing to a different domain name, without %s should throw SYNTAX_ERR');
75
76 test(function () {
77 assert_throws('SYNTAX_ERR', function () { navigator.registerProtocolHandler('m ailto', location.href + '/%', 'foo') } );
78 }, 'a url argument without %s (but with %) should throw SYNTAX_ERR');
79
80 test(function () {
81 assert_throws('SYNTAX_ERR', function () { navigator.registerProtocolHandler('m ailto', location.href + '/%a', 'foo') } );
82 }, 'a url argument without %s (but with %a) should throw SYNTAX_ERR');
83
84 test(function () {
85 assert_throws('SECURITY_ERR', function () { navigator.registerProtocolHandler( 'mailto', 'http://example.com/%s', 'foo') } );
86 }, 'a url argument pointing to a different domain name should throw SECURITY_ERR ');
87
88 test(function () {
89 assert_throws('SECURITY_ERR', function () { navigator.registerProtocolHandler( 'mailto', 'https://example.com/%s', 'foo') } );
90 }, 'a url argument pointing to a different domain name should throw SECURITY_ERR (2)');
91
92 test(function () {
93 assert_throws('SECURITY_ERR', function () { navigator.registerProtocolHandler( 'mailto', 'http://foobar.example.com/%s', 'foo') } );
94 }, 'a url argument pointing to a different domain name should throw SECURITY_ERR (3)');
95
96 test(function () {
97 assert_throws('SECURITY_ERR', function () { navigator.registerProtocolHandler( 'mailto', 'mailto:%s@example.com', 'foo') } );
98 }, 'looping handlers should throw SECURITY_ERR');
99
100 test(function () {
101 assert_throws('SECURITY_ERR', function () { navigator.registerProtocolHandler( 'sms', 'tel:%s', 'foo') } );
102 }, 'a url argument pointing to a non-http[s] scheme should throw SECURITY_ERR du e to not being of the same origin');
103
104 /* Protocol argument */
105 test(function () {
106 assert_throws('SYNTAX_ERR', function () { navigator.registerProtocolHandler('u nrecognized', location.href + '/%a', 'foo') } );
107 }, 'a protocol argument containing an unrecognized scheme should throw SECURITY_ ERR'); /* This is a whitelist, not a blacklist. */
108
109 test(function () {
110 assert_throws('SYNTAX_ERR', function () { navigator.registerProtocolHandler('m ailto:', location.href + '/%a', 'foo') } );
111 }, 'a protocol argument containing : should throw SYNTAX_ERR');
112
113 test(function () {
114 assert_throws('SYNTAX_ERR', function () { navigator.registerProtocolHandler('m ailto://', location.href + '/%a', 'foo') } );
115 }, 'a protocol argument containing :// should throw SYNTAX_ERR');
116
117 test(function () {
118 assert_throws('SYNTAX_ERR', function () { navigator.registerProtocolHandler('h ttp://', location.href + '/%a', 'foo') } );
119 }, 'a protocol argument containing http:// should throw SYNTAX_ERR');
120
121 test(function () {
122 assert_throws('SYNTAX_ERR', function () { navigator.registerProtocolHandler('m ailto' + String.fromCharCode(0), location.href + '/%a', 'foo') } );
123 }, 'a protocol argument containing a null character should throw SYNTAX_ERR');
124
125 test(function () {
126 assert_throws('SYNTAX_ERR', function () { navigator.registerProtocolHandler('m ailtoo' + String.fromCharCode(8), location.href + '/%a', 'foo') } );
127 }, 'a protocol argument containing a backspace character should throw SYNTAX_ERR ');
128
129 test(function () {
130 assert_throws('SYNTAX_ERR', function () { navigator.registerProtocolHandler('m ailto' + String.fromCharCode(10), location.href + '/%a', 'foo') } );
131 }, 'a protocol argument containing a LF character should throw SYNTAX_ERR');
132
133 test(function () {
134 assert_throws('SYNTAX_ERR', function () { navigator.registerProtocolHandler('m аilto', location.href + '/%a', 'foo') } );
135 }, 'a protocol argument containing non-alphanumeric characters (like a cyrillic “а”) should throw SYNTAX_ERR');
136
137 test(function () {
138 navigator.registerProtocolHandler('TEL', location.href + '/%s', 'foo');
139 }, 'a protocol argument of “TEL” should be equivalent to “tel”');
140
141 test(function () {
142 navigator.registerProtocolHandler('teL', location.href + '/%s', 'foo');
143 }, 'a protocol argument of “teL” should be equivalent to “tel”');
144
145
146 /* Overriding any of the following protocols must never be allowed. That would
147 * break the browser. */
148 var blacklist = new Array(
149 'about',
150 'attachment',
151 'blob',
152 'chrome',
153 'cid',
154 'data',
155 'file',
156 'ftp',
157 'http',
158 'https',
159 'javascript',
160 'livescript',
161 'mid',
162 'mocha',
163 'opera',
164 'operamail',
165 'res',
166 'resource',
167 'shttp',
168 'tcl',
169 'vbscript',
170 'view-source',
171 'ws',
172 'wss',
173 'wyciwyg');
174
175 for ( var bi=0, bl=blacklist.length; bi<bl; ++bi ){
176
177 test(function () {
178 assert_throws('SECURITY_ERR', function () { navigator.registerProtocolHandle r(blacklist[bi], location.href + '/%s', 'foo') } );
179 }, 'attempting to override the ' + blacklist[bi] + ' protocol should throw SEC URITY_ERR');
180
181 }
182
183 /* The following protocols must be possible to override.
184 * We're just testing that the call goes through here. Whether or not they
185 * actually work as handlers is covered by the interactive tests. */
186 var whitelist = new Array(
187 'geo',
188 'im',
189 'irc',
190 'ircs',
191 'mailto',
192 'mms',
193 'news',
194 'nntp',
195 'sms',
196 'smsto',
197 'tel',
198 'urn',
199 'webcal',
200 'wtai',
201 'xmpp');
202
203 for ( var wi=0, wl=whitelist.length; wi<wl; ++wi ){
204
205 test(function () {
206 navigator.registerProtocolHandler(whitelist[wi], location.href + '/%s', 'foo ');
207 assert_true(true);
208 }, 'overriding the ' + whitelist[wi] + ' protocol should work');
209
210 }
211 </script>
212
213 </body>
214 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698