usvstring-reflection.https.html (5198B)
1 <!doctype html> 2 <title>USVString test relate to url</title> 3 <script src=/resources/testharness.js></script> 4 <script src=/resources/testharnessreport.js></script> 5 <script src="../../webrtc/RTCPeerConnection-helper.js"></script> 6 <div id=log></div> 7 <script> 8 // Unpaired surrogate codepoints present in USVString are replaced 9 // with U+FFFD. %EF%BF%BD is UTF-8 encoding of U+FFFD. 10 'use strict'; 11 test(() => { 12 location.hash = '\uD999'; 13 assert_equals(location.hash, '#%EF%BF%BD'); 14 }, "location.hash : unpaired surrogate codepoint should be replaced with U+FFFD"); 15 16 test(() => { 17 var w = window.open("about:blank#\uD800"); 18 assert_equals(w.location.href, 'about:blank#%EF%BF%BD'); 19 w.location.href = 'about:blank#\uD999'; 20 assert_equals(w.location.href, 'about:blank#%EF%BF%BD'); 21 }, "location.href : unpaired surrogate codepoint should be replaced with U+FFFD"); 22 23 test(() => { 24 var w = window.open("about:blank#\uD800"); 25 assert_equals(w.location.hash, '#%EF%BF%BD'); 26 }, "window.open : unpaired surrogate codepoint should be replaced with U+FFFD"); 27 28 test(() => { 29 var w = document.open("about:blank#\uD800", "", ""); 30 assert_equals(w.location.hash, '#%EF%BF%BD'); 31 }, "document.open : unpaired surrogate codepoint should be replaced with U+FFFD"); 32 33 test(() => { 34 var element = document.createElement("a"); 35 element.ping = '\uD989'; 36 assert_equals(element.ping, '\uFFFD'); 37 }, "anchor : unpaired surrogate codepoint should be replaced with U+FFFD") 38 39 test(() => { 40 var element = document.createElement("area"); 41 element.ping = '\uDA99'; 42 assert_equals(element.ping, '\uFFFD'); 43 }, "area : unpaired surrogate codepoint should be replaced with U+FFFD") 44 45 test(() => { 46 var element = document.createElement("base"); 47 element.href = '\uD989'; 48 assert_equals(element.href.endsWith('%EF%BF%BD'), true); 49 }, "base : unpaired surrogate codepoint should be replaced with U+FFFD") 50 51 test(() => { 52 var src = new EventSource('\uD899'); 53 assert_equals(src.url.endsWith('%EF%BF%BD'), true); 54 }, "EventSource : unpaired surrogate codepoint should be replaced with U+FFFD") 55 56 test(() => { 57 var element = document.createElement("frame"); 58 element.src = '\uDCA9'; 59 element.longDesc = '\uDCA8'; 60 assert_equals(element.src.endsWith('%EF%BF%BD'), true); 61 assert_equals(element.longDesc.endsWith('%EF%BF%BD'), true); 62 }, "frame : unpaired surrogate codepoint should be replaced with U+FFFD") 63 64 test(() => { 65 var element = document.createElement("iframe"); 66 element.src = '\uDC89'; 67 element.longDesc = '\uDC88'; 68 assert_equals(element.src.endsWith('%EF%BF%BD'), true); 69 assert_equals(element.longDesc.endsWith('%EF%BF%BD'), true); 70 }, "iframe : unpaired surrogate codepoint should be replaced with U+FFFD") 71 72 test(() => { 73 var element = document.createElement("link"); 74 element.href = '\uDB89'; 75 assert_equals(element.href.endsWith('%EF%BF%BD'), true); 76 }, "link : unpaired surrogate codepoint should be replaced with U+FFFD") 77 78 test(() => { 79 var element = document.createElement("source"); 80 element.src = '\uDDDD'; 81 element.srcset = '\uD800'; 82 assert_equals(element.src.endsWith('%EF%BF%BD'), true); 83 assert_equals(element.srcset, '\uFFFD'); 84 }, "source : unpaired surrogate codepoint should be replaced with U+FFFD") 85 86 test(() => { 87 const event = new StorageEvent('storage', { 88 url: window.location.href + '\uD999', 89 }); 90 assert_equals(event.url, window.location.href + "\uFFFD"); 91 }, "storage event : unpaired surrogate codepoint should be replaced with U+FFFD") 92 93 test(() => { 94 var wsocket = new EventSource('ws://www.example.com/socketserve\uD899/'); 95 assert_true(wsocket.url.endsWith('ws://www.example.com/socketserve%EF%BF%BD/')); 96 }, "websocket url : unpaired surrogate codepoint should be replaced with U+FFFD") 97 98 test(() => { 99 try { 100 navigator.sendBeacon("resources/\uD800blank.txt"); 101 assert_true(true); 102 } catch (e) { 103 assert_true(false); 104 } 105 }, "sendBeacon URL: unpaired surrogate codepoint should not make any exceptions.") 106 107 test(() => { 108 // This shouldn't throw an exception. 109 window.navigator.registerProtocolHandler('web+myprotocol', "custom-scheme\uD800/url=%s", "title"); 110 }, "RegisterProtocolHandler URL: unpaired surrogate codepoint should not make any exceptions.") 111 112 test(() => { 113 // This shouldn't throw an exception. 114 window.navigator.unregisterProtocolHandler('web+myprotocol', "custom-scheme\uD800/url=%s"); 115 }, "UnregisterProtocolHandler URL: unpaired surrogate codepoint should not make any exceptions.") 116 117 test(() => { 118 var w = window.open("about:blank#\uD800"); 119 assert_equals(w.document.URL, 'about:blank#%EF%BF%BD'); 120 assert_equals(w.document.documentURI, 'about:blank#%EF%BF%BD'); 121 }, "Document URLs: unpaired surrogate codepoint should be replaced with U+FFFD") 122 123 promise_test(t => { 124 const sendString = 'hello\uD999'; 125 const receiveString = 'hello\uFFFD'; 126 127 return createDataChannelPair(t, {}) 128 .then(([channel1, channel2]) => { 129 channel1.send(sendString); 130 return awaitMessage(channel2) 131 }).then(message => { 132 assert_equals(typeof message, 'string', 133 'Expect message to be a string'); 134 135 assert_equals(message, receiveString); 136 }); 137 }, "RTCDataChannel.send: unpaired surrogate codepoint should be replaced with U+FFFD.") 138 139 </script>