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

Side by Side Diff: LayoutTests/imported/web-platform-tests/html/webappapis/system-state-and-capabilities/the-navigator-object/content.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>registerContentHandler()</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
15 <div id='log'></div>
16
17 <script>
18 test(function () {
19 assert_idl_attribute(navigator, 'registerContentHandler');
20 }, 'the registerContentHandler method should exist on the navigator object');
21
22 /* Happy path */
23 test(function () {
24 navigator.registerContentHandler('text/x-unknown-type', location.href + '/%s', 'foo');
25 }, 'a handler with valid arguments should work');
26
27
28 /* URL argument */
29 test(function () {
30 navigator.registerContentHandler('text/x-unknown-type', '%s', 'foo');
31 }, 'a relative URL should work');
32
33 test(function () {
34 navigator.registerContentHandler('text/x-unknown-type', location.href + '#%s', 'foo');
35 }, 'a URL with a fragment identifier should work');
36
37 test(function () {
38 navigator.registerContentHandler('text/x-unknown-type', location.href + '?foo= %s', 'foo');
39 }, 'a URL with a query string should work');
40
41 test(function () {
42 navigator.registerContentHandler('text/x-unknown-type', location.href + '?foo= %s&bar', 'foo');
43 }, 'a URL with a multi-argument query string should work');
44
45 test(function () {
46 navigator.registerContentHandler('text/x-unknown-type', location.href + '/%s/b ar/baz/', 'foo');
47 }, 'a URL with the passed string as a directory name should work');
48
49 test(function () {
50 navigator.registerContentHandler('text/x-unknown-type', location.href + '/%s/b ar/baz/?foo=1337&bar#baz', 'foo');
51 }, 'a URL with the passed string as a directory name followed by a query string and fragment identifier should work');
52
53 test(function () {
54 navigator.registerContentHandler('text/x-unknown-type', location.href + '/%s/f oo/%s/', 'foo');
55 }, 'a URL with the passed string included twice should work');
56
57 test(function () {
58 assert_throws('SYNTAX_ERR', function () { navigator.registerContentHandler('te xt/x-unknown-type', '', 'foo') } );
59 }, 'an empty url argument should throw SYNTAX_ERR');
60
61 test(function () {
62 assert_throws('SYNTAX_ERR', function () { navigator.registerContentHandler('te xt/x-unknown-type', 'http://%s.com', 'foo') } );
63 }, '%s instead of domain name should throw SYNTAX_ERR');
64
65 test(function () {
66 assert_throws('SYNTAX_ERR', function () { navigator.registerContentHandler('te xt/x-unknown-type', 'http://%s.example.com', 'foo') } );
67 }, '%s instead of subdomain name should throw syntax_err');
68
69 test(function () {
70 assert_throws('SYNTAX_ERR', function () { navigator.registerContentHandler('te xt/x-unknown-type', location.href + '', 'foo') } );
71 }, 'a url argument without %s should throw SYNTAX_ERR');
72
73 test(function () {
74 assert_throws('SYNTAX_ERR', function () { navigator.registerContentHandler('te xt/x-unknown-type', 'http://example.com', 'foo') } );
75 }, 'a url argument pointing to a different domain name, without %s should throw SYNTAX_ERR');
76
77 test(function () {
78 assert_throws('SYNTAX_ERR', function () { navigator.registerContentHandler('te xt/x-unknown-type', location.href + '/%', 'foo') } );
79 }, 'a url argument without %s (but with %) should throw SYNTAX_ERR');
80
81 test(function () {
82 assert_throws('SYNTAX_ERR', function () { navigator.registerContentHandler('te xt/x-unknown-type', location.href + '/%a', 'foo') } );
83 }, 'a url argument without %s (but with %a) should throw SYNTAX_ERR');
84
85 test(function () {
86 assert_throws('SECURITY_ERR', function () { navigator.registerContentHandler(' text/x-unknown-type', 'http://example.com/%s', 'foo') } );
87 }, 'a url argument pointing to a different domain name should throw SECURITY_ERR ');
88
89 test(function () {
90 assert_throws('SECURITY_ERR', function () { navigator.registerContentHandler(' text/x-unknown-type', 'https://example.com/%s', 'foo') } );
91 }, 'a url argument pointing to a different domain name should throw SECURITY_ERR (2)');
92
93 test(function () {
94 assert_throws('SECURITY_ERR', function () { navigator.registerContentHandler(' text/x-unknown-type', 'http://foobar.example.com/%s', 'foo') } );
95 }, 'a url argument pointing to a different domain name should throw SECURITY_ERR (3)');
96
97 /* Content type argument */
98
99 /* The following MIME types are handled natively by the browser, and must not
100 * be possible to override. Note that this list only covers a few basic content
101 * types. Full lists of content types handled by each browser is found under
102 * /vendor/. */
103
104 var blacklist = new Array(
105 'image/jpeg',
106 'text/html',
107 'text/javascript',
108 'text/plain');
109
110 for (var bi=0, bl=blacklist.length; bi<bl; ++bi){
111
112 test(function () {
113 assert_throws('SECURITY_ERR', function () { navigator.registerContentHandler (blacklist[bi], location.href + '/%s', 'foo') } );
114 }, 'attempting to override the ' + blacklist[bi] + ' MIME type should throw SE CURITY_ERR');
115
116 }
117
118 /* Overriding the following MIME types should be possible. */
119 var whitelist = new Array('application/atom+xml', /* For feeds. */
120 'application/rss+xml', /* For feeds. */
121 'application/x-unrecognized', /* Arbitrary MIME types should be overridable. * /
122 'text/unrecognized',
123 'foo/bar');
124
125 for (var wi=0, wl=whitelist.length; wi<wl; ++wi){
126
127 test(function () {
128 navigator.registerContentHandler(whitelist[wi], location.href + '/%s', 'foo' );
129 }, 'overriding the ' + whitelist[wi] + ' MIME type should work');
130
131 }
132
133 </script>
134
135 </body>
136 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698