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

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

Issue 440833006: Use a consistent scheme name in navigatorcontentutils tests (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 4 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
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.unregisterProtocolHandler throws the prop er exceptions and has no-op default implementation.</p> 6 <p>This test makes sure that navigator.unregisterProtocolHandler throws the prop er 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.unregisterProtocolHandler) 15 if (window.navigator.unregisterProtocolHandler)
16 debug('PASS window.navigator.unregisterProtocolHandler is defined.'); 16 debug('PASS window.navigator.unregisterProtocolHandler is defined.');
17 else 17 else
18 debug('FAIL window.navigator.unregisterProtocolHandler is not defined.'); 18 debug('FAIL window.navigator.unregisterProtocolHandler 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 try { 23 try {
24 window.navigator.unregisterProtocolHandler(protocol, "invalid protocol % s", "title"); 24 window.navigator.unregisterProtocolHandler(scheme, "invalid scheme %s", "title");
25 } catch (e) { 25 } catch (e) {
26 succeeded = 'SecurityError' == e.name; 26 succeeded = 'SecurityError' == e.name;
27 errorMessage = e.message; 27 errorMessage = e.message;
28 } 28 }
29 29
30 if (succeeded) 30 if (succeeded)
31 debug('PASS Invalid protocol "' + protocol + '" threw SecurityError exce ption: "' + errorMessage + '".'); 31 debug('PASS Invalid scheme "' + scheme + '" threw SecurityError exceptio n: "' + errorMessage + '".');
32 else 32 else
33 debug('FAIL Invalid protocol "' + protocol + '" allowed.'); 33 debug('FAIL Invalid scheme "' + scheme + '" allowed.');
34 }); 34 });
35 35
36 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']; 36 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'];
37 valid_protocols.forEach(function (protocol) { 37 valid_schemes.forEach(function (scheme) {
38 var succeeded = false; 38 var succeeded = false;
39 try { 39 try {
40 window.navigator.unregisterProtocolHandler(protocol, "valid protocol %s" , "title"); 40 window.navigator.unregisterProtocolHandler(scheme, "valid scheme %s", "t itle");
41 succeeded = true; 41 succeeded = true;
42 } catch (e) { 42 } catch (e) {
43 succeeded = false; 43 succeeded = false;
44 } 44 }
45 45
46 if (succeeded) 46 if (succeeded)
47 debug('PASS Valid protocol "' + protocol + '" allowed.'); 47 debug('PASS Valid scheme "' + scheme + '" allowed.');
48 else 48 else
49 debug('FAIL Valid protocol "' + protocol + '" failed.'); 49 debug('FAIL Valid scheme "' + scheme + '" failed.');
50 }); 50 });
51 51
52 var invalid_schemes = ['mailto:', 'ssh:/', 'magnet:+', 'tel:sip']; 52 var invalid_schemes = ['mailto:', 'ssh:/', 'magnet:+', 'tel:sip'];
53 invalid_schemes.forEach(function (scheme) { 53 invalid_schemes.forEach(function (scheme) {
54 var succeeded = false; 54 var succeeded = false;
55 try { 55 try {
56 window.navigator.unregisterProtocolHandler(scheme, 'invalid scheme uri=% s', 'title'); 56 window.navigator.unregisterProtocolHandler(scheme, 'invalid scheme uri=% s', 'title');
57 } catch (e) { 57 } catch (e) {
58 succeeded = 'SecurityError' == e.name; 58 succeeded = 'SecurityError' == e.name;
59 errorMessage = e.message; 59 errorMessage = e.message;
60 } 60 }
61 61
62 if (succeeded) 62 if (succeeded)
63 debug('PASS Invalid scheme "' + scheme + '" falied.'); 63 debug('PASS Invalid scheme "' + scheme + '" falied.');
64 else 64 else
65 debug('Fail: Invalid scheme "' + scheme + '" allowed. Threw exception: " ' + errorMessage + '".'); 65 debug('Fail: Invalid scheme "' + scheme + '" allowed. Threw exception: " ' + errorMessage + '".');
66 }); 66 });
67 67
68 var invalid_urls = ["", "%S"]; 68 var invalid_urls = ["", "%S"];
69 invalid_urls.forEach(function (url) { 69 invalid_urls.forEach(function (url) {
70 var succeeded = false; 70 var succeeded = false;
71 try { 71 try {
72 window.navigator.unregisterProtocolHandler('web+myprotocol', url, 'title '); 72 window.navigator.unregisterProtocolHandler('web+myscheme', url, 'title') ;
73 } catch (e) { 73 } catch (e) {
74 succeeded = 'SyntaxError' == e.name; 74 succeeded = 'SyntaxError' == e.name;
75 errorMessage = e.message; 75 errorMessage = e.message;
76 } 76 }
77 77
78 if (succeeded) 78 if (succeeded)
79 debug('PASS Invalid url "' + url + '" threw SyntaxError exception.' + er rorMessage + '".'); 79 debug('PASS Invalid url "' + url + '" threw SyntaxError exception.' + er rorMessage + '".');
80 else 80 else
81 debug('FAIL Invalid url "' + url + '" allowed.'); 81 debug('FAIL Invalid url "' + url + '" allowed.');
82 }); 82 });
83 83
84 // Test that the API has default no-op implementation. 84 // Test that the API has default no-op implementation.
85 var succeeded = true; 85 var succeeded = true;
86 try { 86 try {
87 window.navigator.unregisterProtocolHandler('web+myprotocol', "%s", "title"); 87 window.navigator.unregisterProtocolHandler('web+myscheme', "%s", "title");
88 } catch (e) { 88 } catch (e) {
89 succeeded = false; 89 succeeded = false;
90 } 90 }
91 91
92 if (succeeded) 92 if (succeeded)
93 debug('PASS Valid call succeeded.'); 93 debug('PASS Valid call succeeded.');
94 else 94 else
95 debug('FAIL Invalid call did not succeed.'); 95 debug('FAIL Invalid call did not succeed.');
96 96
97 // Check if unregisterProtocolHandler can unregister protocol. 97 // Check if unregisterProtocolHandler can unregister scheme.
98 debug("\nCheck if unregisterProtocolHandler can unregister protocol correctly. I f isProtocolHandlerRegistered() returns 'new' state, unregisterProtoclHandler() works well."); 98 debug("\nCheck if unregisterProtocolHandler can unregister scheme correctly. If isProtocolHandlerRegistered() returns 'new' state, unregisterProtoclHandler() wo rks well.");
99 debug("'bitcoin' protocol will be registered and unregistered for testing.\n"); 99 debug("'bitcoin' scheme will be registered and unregistered for testing.\n");
100 try { 100 try {
101 // Register 'bitcoin' protocol for testing. 101 // Register 'bitcoin' scheme for testing.
102 window.navigator.registerProtocolHandler('bitcoin', 'invalid scheme uri=%s', 'title'); 102 window.navigator.registerProtocolHandler('bitcoin', 'invalid scheme uri=%s', 'title');
103 var state = window.navigator.isProtocolHandlerRegistered('bitcoin', 'valid p rotocol %s'); 103 var state = window.navigator.isProtocolHandlerRegistered('bitcoin', 'valid s cheme %s');
104 if (state == "registered") 104 if (state == "registered")
105 debug("PASS window.navigator.isProtocolHandlerRegistered returns 'regist ered' state. 'bitcoin' is registered successfully."); 105 debug("PASS window.navigator.isProtocolHandlerRegistered returns 'regist ered' state. 'bitcoin' is registered successfully.");
106 else if (state == "new") 106 else if (state == "new")
107 debug("FAIL window.navigator.isProtocolHandlerRegistered returns 'new' s tate. Fail to register 'bitcoin' protocol."); 107 debug("FAIL window.navigator.isProtocolHandlerRegistered returns 'new' s tate. Fail to register 'bitcoin' scheme.");
108 else if (state == "declined") 108 else if (state == "declined")
109 debug("FAIL window.navigator.isProtocolHandlerRegistered returns 'declin ed' state. Fail to register 'bitcoin' protocol."); 109 debug("FAIL window.navigator.isProtocolHandlerRegistered returns 'declin ed' state. Fail to register 'bitcoin' scheme.");
110 110
111 window.navigator.unregisterProtocolHandler('bitcoin', 'invalid scheme uri=%s '); 111 window.navigator.unregisterProtocolHandler('bitcoin', 'invalid scheme uri=%s ');
112 var state = window.navigator.isProtocolHandlerRegistered('bitcoin', 'valid p rotocol %s'); 112 var state = window.navigator.isProtocolHandlerRegistered('bitcoin', 'valid s cheme %s');
113 if (state == "new") 113 if (state == "new")
114 debug("PASS window.navigator.isProtocolHandlerRegistered returns 'new' s tate. 'bitcoin' is unregistered successfully."); 114 debug("PASS window.navigator.isProtocolHandlerRegistered returns 'new' s tate. 'bitcoin' is unregistered successfully.");
115 else if (state == "registered") 115 else if (state == "registered")
116 debug("FAIL window.navigator.isProtocolHandlerRegistered returns 'regist ered' state. Fail to unregister 'bitcoin' protocol."); 116 debug("FAIL window.navigator.isProtocolHandlerRegistered returns 'regist ered' state. Fail to unregister 'bitcoin' scheme.");
117 else if (state == "declined") 117 else if (state == "declined")
118 debug("FAIL window.navigator.isProtocolHandlerRegistered returns 'declin ed' state. Fail to unregister 'bitcoin' protocol."); 118 debug("FAIL window.navigator.isProtocolHandlerRegistered returns 'declin ed' state. Fail to unregister 'bitcoin' scheme.");
119 } catch (e) { 119 } catch (e) {
120 debug('FAIL window.navigator.isProtocolHandlerRegistered call is failed: "' + e.message + '".'); 120 debug('FAIL window.navigator.isProtocolHandlerRegistered call is failed: "' + e.message + '".');
121 } 121 }
122 debug("\n"); 122 debug("\n");
123 123
124 </script> 124 </script>
125 </body> 125 </body>
126 </html> 126 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698