003-manual.html (5735B)
1 <!doctype html> 2 <html> 3 <head> 4 <title>allowTargetOrigin valid syntax</title> 5 <style type="text/css"> 6 div { float: left; height: 100px; width: 100px; margin-right: 10px; background: orange; } 7 iframe { height: 100px; width: 100px; border: none; } 8 .note { float: right; color: silver; } 9 </style> 10 <script type="text/javascript" src="../resources/crossorigin.sub.js"></script> 11 <script type="text/javascript"> 12 function addNote(el,str) { 13 var par = document.createElement(el); 14 par.textContent = str; 15 document.body.appendChild(par); 16 } 17 function testFrame(text,frameorigin,framepath) { 18 var persist = arguments; 19 addNote('p',(done++)+'. '+text); 20 var div = document.createElement('div'); 21 var frame = document.createElement('iframe'); 22 frame.src = frameorigin+framepath; 23 div.draggable = true; 24 div.ondragstart = function (e) { 25 e.dataTransfer.effectAllowed = 'copy'; 26 e.dataTransfer.setData('text','dummy text'); 27 for( var i = 3; i < persist.length; i++ ) { 28 e.dataTransfer.allowTargetOrigin(persist[i]); 29 } 30 }; 31 var par = document.createElement('p'); 32 par.className = 'note'; 33 par.appendChild(document.createTextNode('Target: '+frameorigin)); 34 par.appendChild(document.createElement('br')); 35 par.appendChild(document.createTextNode('Allowing: '+([]).slice.call(persist,3).join(' and '))); 36 if( framepath.match(/\?domain\b/) ) { 37 par.appendChild(document.createElement('br')); 38 par.appendChild(document.createTextNode('document.domain set to parent domain')); 39 } 40 document.body.appendChild(par); 41 document.body.appendChild(div); 42 document.body.appendChild(frame); 43 } 44 var done = 1; 45 window.onload = function () { 46 var allowText = 'Drag the orange box below over the blue box the right, and release it. Fail if nothing happens in the blue box.'; 47 var blockText = 'Drag the orange box below over the pink box the right, and release it. Pass if nothing happens in the pink box.'; 48 var allowHelper = location.pathname.replace(/[^\/]*$/,'HELPER-mustallow.html'); 49 var blockHelper = location.pathname.replace(/[^\/]*$/,'HELPER-mustblock.html'); 50 if( location.hostname != httpHostMain || location.host != httpHostMain ) { 51 addNote('p','This test must be loaded over http:\/\/'+httpHostMain+'\/'); 52 } else { 53 /* 01 */ testFrame(allowText,'http://'+httpHostMain,allowHelper); 54 /* 02 */ testFrame(allowText,'http://'+httpHostAlias,allowHelper); 55 /* 03 */ testFrame(allowText,'http://'+httpHostMain,allowHelper,'*'); 56 /* 04 */ testFrame(allowText,'http://'+httpHostAlias,allowHelper,'*'); 57 /* 05 */ testFrame(allowText,'http://'+httpHostMain,allowHelper,'/'); 58 /* 06 */ testFrame(blockText,'http://'+httpHostAlias,blockHelper,'/'); 59 /* 07 */ testFrame(allowText,'http://'+httpHostMain,allowHelper,'http://'+httpHostMain); 60 /* 08 */ testFrame(blockText,'http://'+httpHostMain+':'+httpPortAlias,blockHelper,'http://'+httpHostMain); 61 /* 09 */ testFrame(blockText,'http://'+httpHostAlias,blockHelper,'http://'+httpHostMain); 62 /* 10 */ testFrame(blockText,'http://'+httpHostAlias,blockHelper,'http://'+httpHostMain); 63 /* 11 */ testFrame(allowText,'http://'+httpHostMain,allowHelper,'http://'+httpHostMain+':80'); 64 /* 12 */ testFrame(blockText,'http://'+httpHostMain+':'+httpPortAlias,blockHelper,'http://'+httpHostMain+':80'); 65 /* 13 */ testFrame(allowText,'http://'+httpHostMain+':'+httpPortAlias,allowHelper,'http://'+httpHostMain+':'+httpPortAlias); 66 /* 14 */ testFrame(blockText,'http://'+httpHostMain,blockHelper,'http://'+httpHostMain+':'+httpPortAlias); 67 /* 15 */ testFrame(blockText,'https://'+httpsHostAlias,blockHelper,'http://'+httpsHostAlias); 68 /* 16 */ testFrame(allowText,'https://'+httpsHostAlias,allowHelper,'https://'+httpsHostAlias); 69 /* 17 */ testFrame(allowText,'http://'+httpHostMain,allowHelper,'http://foo:bar@'+httpHostMain+'/baz'); 70 /* 18 */ testFrame(allowText,'http://foo:bar@'+httpHostMain,allowHelper,'http://'+httpHostMain); 71 /* 19 */ testFrame(allowText,'http://'+httpHostMain,allowHelper,'http://'+httpHostAlias,'/'); 72 /* 20 */ testFrame(allowText,'http://'+httpHostMain,allowHelper,'/','http://'+httpHostAlias); 73 /* 21 */ testFrame(allowText,'http://'+httpHostMain,allowHelper,'http://'+httpHostAlias,'*'); 74 /* 22 */ testFrame(allowText,'http://'+httpHostMain,allowHelper,'http://'+httpHostAlias,'http://'+httpHostMain); 75 /* 23 */ testFrame(allowText,'http://'+httpHostAlias,allowHelper,'http://'+httpHostAlias,'http://'+httpHostMain); 76 /* 24 */ testFrame(blockText,'http://'+httpHostAlias,blockHelper,'http://dummy','http://'+httpHostMain); 77 /* 25 */ testFrame(blockText,'https://'+httpsHostAlias,blockHelper,'https://'+httpsHostAlias+':'+httpsPortAlias); 78 /* 26 */ testFrame(blockText,'https://'+httpsHostAlias+':'+httpsPortAlias,blockHelper,'https://'+httpsHostAlias); 79 /* 27 */ testFrame(allowText,'https://'+httpsHostAlias+':'+httpsPortAlias,allowHelper,'https://'+httpsHostAlias+':'+httpsPortAlias); 80 window.xhr = new XMLHttpRequest(); 81 xhr.open('GET',allowHelper,false); 82 xhr.send(null); 83 /* 28 */ testFrame(allowText,'data:text/html,',escape(xhr.responseText),'http://'+httpHostMain); 84 /* 29 */ testFrame(allowText,'javascript:','parent.xhr.responseText','http://'+httpHostMain); 85 /* 30 */ testFrame(blockText,'http://'+httpHostAlias,blockHelper,'http://'+httpHostAlias.replace(/^[^.]+\./,'')); 86 /* 31 */ testFrame(allowText,'http://'+httpHostAlias,allowHelper+'?domain','http://'+httpHostAlias); 87 /* 32 */ testFrame(blockText,'http://'+httpHostAlias,blockHelper+'?domain','http://'+httpHostAlias.replace(/^[^.]+\./,'')); 88 } 89 }; 90 </script> 91 </head> 92 <body> 93 <noscript><p>Enable JavaScript and reload</p></noscript> 94 </body> 95 </html>