OLD | NEW |
1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
2 <html> | 2 <html> |
3 <head> | 3 <head> |
4 <script src="../resources/js-test.js"></script> | 4 <script src="/js-test-resources/js-test.js"></script> |
5 </head> | 5 </head> |
6 <body> | 6 <body> |
7 <p>This test makes sure that navigator.isProtocolHandlerRegistered throws the pr
oper exceptions and returns the default state of handler.</p> | 7 <p>This test makes sure that navigator.isProtocolHandlerRegistered throws the pr
oper exceptions and returns the default state of handler.</p> |
8 <pre id="console"></pre> | 8 <pre id="console"></pre> |
9 <script> | 9 <script> |
10 if (window.testRunner) | |
11 testRunner.dumpAsText(); | |
12 | |
13 if (window.internals) | 10 if (window.internals) |
14 internals.setNavigatorContentUtilsClientMock(document); | 11 internals.setNavigatorContentUtilsClientMock(document); |
15 | 12 |
16 if (window.navigator.isProtocolHandlerRegistered) | 13 if (window.navigator.isProtocolHandlerRegistered) |
17 debug('PASS window.navigator.isProtocolHandlerRegistered is defined.'); | 14 debug('PASS window.navigator.isProtocolHandlerRegistered is defined.'); |
18 else | 15 else |
19 debug('FAIL window.navigator.isProtocolHandlerRegistered is not defined.'); | 16 debug('FAIL window.navigator.isProtocolHandlerRegistered is not defined.'); |
20 | 17 |
21 var invalidUrl = "%S"; | 18 var invalidUrl = "%S"; |
22 var succeeded = false; | 19 var succeeded = false; |
(...skipping 17 matching lines...) Expand all Loading... |
40 succeeded = 'SecurityError' == e.name; | 37 succeeded = 'SecurityError' == e.name; |
41 errorMessage = e.message; | 38 errorMessage = e.message; |
42 } | 39 } |
43 | 40 |
44 if (succeeded) | 41 if (succeeded) |
45 debug('PASS Invalid scheme "' + scheme + '" falied.'); | 42 debug('PASS Invalid scheme "' + scheme + '" falied.'); |
46 else | 43 else |
47 debug('FAIL Invalid scheme "' + scheme + '" allowed. Threw exception: "'
+ errorMessage + '".'); | 44 debug('FAIL Invalid scheme "' + scheme + '" allowed. Threw exception: "'
+ errorMessage + '".'); |
48 }); | 45 }); |
49 | 46 |
| 47 // Test that the API throws SecurityError exception if the URL's origin differs
from the document's origin. |
| 48 succeeded = false; |
| 49 var errorMessage; |
| 50 try { |
| 51 window.navigator.isProtocolHandlerRegistered('web+myprotocol', "http://www.e
xample.com/soup?url=%s"); |
| 52 } catch (e) { |
| 53 succeeded = true; |
| 54 errorMessage = e.message; |
| 55 } |
| 56 |
| 57 if (succeeded) |
| 58 debug('PASS URL with origin different than document origin threw SecurityErr
or exception: "' + errorMessage + '".'); |
| 59 else |
| 60 debug('FAIL URL with origin different than document origin is allowed.'); |
| 61 |
50 debug("\nCheck if isProtocolHandlerRegistered() works correctly. If isProtocolHa
ndlerRegistered() returns 'new' state, it works well."); | 62 debug("\nCheck if isProtocolHandlerRegistered() works correctly. If isProtocolHa
ndlerRegistered() returns 'new' state, it works well."); |
51 debug("'bitcoin' scheme will be registered, and then checks if the 'bitcoin' sch
eme is registered by isProtocolHandlerRegistered().\n"); | 63 debug("'bitcoin' scheme will be registered, and then checks if the 'bitcoin' sch
eme is registered by isProtocolHandlerRegistered().\n"); |
52 try { | 64 try { |
53 // Register 'bitcoin' scheme for testing. | 65 // Register 'bitcoin' scheme for testing. |
54 window.navigator.registerProtocolHandler('bitcoin', 'invalid scheme uri=%s',
'title'); | 66 window.navigator.registerProtocolHandler('bitcoin', 'invalid scheme uri=%s',
'title'); |
55 | 67 |
56 var state = window.navigator.isProtocolHandlerRegistered("bitcoin", "valid s
cheme %s"); | 68 var state = window.navigator.isProtocolHandlerRegistered("bitcoin", "valid s
cheme %s"); |
57 if (state == "registered") | 69 if (state == "registered") |
58 debug("PASS window.navigator.isProtocolHandlerRegistered returns 'regist
ered' state. isProtocolHandlerRegistered() works correctly."); | 70 debug("PASS window.navigator.isProtocolHandlerRegistered returns 'regist
ered' state. isProtocolHandlerRegistered() works correctly."); |
59 else if (state == "new") | 71 else if (state == "new") |
60 debug("FAIL window.navigator.isProtocolHandlerRegistered returns 'new' s
tate."); | 72 debug("FAIL window.navigator.isProtocolHandlerRegistered returns 'new' s
tate."); |
61 else if (state == "declined") | 73 else if (state == "declined") |
62 debug("FAIL window.navigator.isProtocolHandlerRegistered returns 'declin
ed' state."); | 74 debug("FAIL window.navigator.isProtocolHandlerRegistered returns 'declin
ed' state."); |
63 } catch (e) { | 75 } catch (e) { |
64 debug('FAIL window.navigator.isProtocolHandlerRegistered call is failed: "'
+ e.message + '".'); | 76 debug('FAIL window.navigator.isProtocolHandlerRegistered call is failed: "'
+ e.message + '".'); |
65 } | 77 } |
66 debug("\n"); | 78 debug("\n"); |
67 | 79 |
68 </script> | 80 </script> |
69 </body> | 81 </body> |
70 </html> | 82 </html> |
OLD | NEW |