test_bug574596.html (3473B)
1 <!DOCTYPE HTML> 2 <html> 3 <!-- 4 https://bugzilla.mozilla.org/show_bug.cgi?id=574596 5 --> 6 <head> 7 <title>Test for Bug 574596</title> 8 <script src="/tests/SimpleTest/SimpleTest.js"></script> 9 <script type="application/javascript" src="/tests/SimpleTest/EventUtils.js"></script> 10 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> 11 </head> 12 <body> 13 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=574596">Mozilla Bug 574596</a> 14 <style type="text/css"> 15 #link1 a { user-select:none; } 16 </style> 17 <div id="link1"><a href="http://www.mozilla.org/">link1</a></div> 18 <div id="link2"><a href="http://www.mozilla.org/">link2</a></div> 19 <p id="display"></p> 20 <div id="content" style="display: none"> 21 22 </div> 23 <pre id="test"> 24 <script type="application/javascript"> 25 26 /** Test for Bug 574596 */ 27 28 function ignoreFunc(actualData, expectedData) { 29 return true; 30 } 31 32 const includeCommonAncestor = SpecialPowers.getBoolPref( 33 "dom.serializer.includeCommonAncestor.enabled" 34 ); 35 var dragLinkText = [[ 36 { type:"text/x-moz-url", data:"", eqTest:ignoreFunc }, 37 { type:"text/x-moz-url-data", data:"http://www.mozilla.org/" }, 38 { type:"text/x-moz-url-desc", data:"link1" }, 39 { type:"text/uri-list", data:"http://www.mozilla.org/" }, 40 { type:"text/_moz_htmlcontext", data:"", eqTest:ignoreFunc }, 41 { type:"text/_moz_htmlinfo", data:"", eqTest:ignoreFunc }, 42 { type:"text/html", data:`${includeCommonAncestor ? '<div id="link1">' : ''}` + 43 `<a href="http://www.mozilla.org/">link1</a>` + 44 `${includeCommonAncestor ? '</div>' : ''}` }, 45 { type:"text/plain", data:"http://www.mozilla.org/" } 46 ]]; 47 48 49 function dumpTransfer(dataTransfer,expect) { 50 dataTransfer = SpecialPowers.wrap(dataTransfer); 51 dtData = dataTransfer.mozItemCount + "items:\n"; 52 for (var i = 0; i < dataTransfer.mozItemCount; i++) { 53 var dtTypes = dataTransfer.mozTypesAt(i); 54 for (var j = 0; j < dtTypes.length; j++) { 55 var actualData = dataTransfer.mozGetDataAt(dtTypes[j],i) 56 if (expect && expect[i] && expect[i][j]) { 57 if (expect[i][j].eqTest) 58 dtData += expect[i][j].eqTest(actualData,expect[i][j].data) ? "ok" : "fail"; 59 else 60 dtData += (actualData == expect[i][j].data) ? "ok" : "fail"; 61 } 62 dtData += "["+i+"]" + "["+j+"]: " + '"' + dtTypes[j] + '" "' + actualData + '"\n'; 63 } 64 } 65 alert(dtData); 66 } 67 68 async function runTest() { 69 var result = await synthesizePlainDragAndCancel( 70 { 71 srcElement: $('link1').firstChild, 72 finalY: -10, // Avoid clicking the link 73 }, 74 dragLinkText); 75 ok(result === true, "Drag user-select:none link (#link1)"); 76 // if (result) dumpTransfer(result,dragLinkText); 77 78 dragLinkText[0][2].data = "link2"; 79 dragLinkText[0][6].data = `${includeCommonAncestor ? '<div id="link2">' : ''}` + 80 `<a href="http://www.mozilla.org/">link2</a>` + 81 `${includeCommonAncestor ? '</div>' : ''}`; 82 var result = await synthesizePlainDragAndCancel( 83 { 84 srcElement: $('link2').firstChild, 85 finalY: -10, // Avoid clicking the link 86 }, 87 dragLinkText); 88 ok(result === true, "Drag link (#link2)"); 89 // if (result) dumpTransfer(result,dragLinkText); 90 91 SimpleTest.finish(); 92 } 93 94 SimpleTest.waitForExplicitFinish(); 95 SimpleTest.waitForFocus(runTest); 96 97 98 </script> 99 </pre> 100 </body> 101 </html>