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

Side by Side Diff: LayoutTests/navigatorcontentutils/register-protocol-handler.html

Issue 392993005: Custom handlers should throw SecurityError exception if the URL's origin differs from the document'… (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Done Created 6 years, 3 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
OLDNEW
(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_schemes = ['http', 'https', 'file', 'web+'];
21 invalid_schemes.forEach(function (scheme) {
22 var succeeded = false;
23 var errorMessage;
24 try {
25 window.navigator.registerProtocolHandler(scheme, "invalid scheme %s", "t itle");
26 } catch (e) {
27 succeeded = 'SecurityError' == e.name;
28 errorMessage = e.message;
29 }
30
31 if (succeeded) {
32 debug('PASS Invalid scheme "' + scheme + '" threw SecurityError exceptio n: "' + errorMessage + '".');
33 }else
34 debug('FAIL Invalid scheme "' + scheme + '" allowed.');
35 });
36
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_schemes.forEach(function (scheme) {
39 var succeeded = false;
40 try {
41 window.navigator.registerProtocolHandler(scheme, "valid scheme %s", "tit le");
42 succeeded = true;
43 } catch (e) {
44 succeeded = false;
45 }
46
47 if (succeeded)
48 debug('PASS Valid scheme "' + scheme + '" allowed.');
49 else
50 debug('FAIL Valid scheme "' + scheme + '" 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 = 'SecurityError' == 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+myscheme', 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+myscheme', "%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 custom scheme.
99 debug("\nCheck if registerProtocolHandler can register scheme correctly. If isPr otocolHandlerRegistered() returns 'registered' state, registerProtoclHandler() w orks well.");
100 debug("'bitcoin' scheme will be registered for testing.\n");
101 try {
102 // Register 'bitcoin' scheme for testing.
103 window.navigator.registerProtocolHandler('bitcoin', 'invalid scheme uri=%s', 'title');
104
105 var state = window.navigator.isProtocolHandlerRegistered('bitcoin', 'valid s cheme %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' scheme.");
110 else if (state == "declined")
111 debug("FAIL window.navigator.isProtocolHandlerRegistered returns 'declin ed' state. Fail to register 'bitcoin' scheme");
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>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698