test_bug592802.html (2961B)
1 <!DOCTYPE HTML> 2 <html> 3 <!-- 4 https://bugzilla.mozilla.org/show_bug.cgi?id=592802 5 --> 6 <head> 7 <title>Test for Bug 592802</title> 8 <script src="/tests/SimpleTest/SimpleTest.js"></script> 9 <script 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=592802">Mozilla Bug 592802</a> 14 <p id="display"></p> 15 <div id="content"> 16 <input id='a' type='file'> 17 <input id='a2' type='file'> 18 </div> 19 <button id='b' onclick="document.getElementById('a').click();">Show Filepicker</button> 20 <button id='b2' onclick="document.getElementById('a2').click();">Show Filepicker</button> 21 <pre id="test"> 22 <script type="application/javascript"> 23 24 /** Test for Bug 592802 */ 25 26 SimpleTest.waitForExplicitFinish(); 27 28 var MockFilePicker = SpecialPowers.MockFilePicker; 29 MockFilePicker.init(SpecialPowers.wrap(window).browsingContext); 30 31 var testData = [ 32 /* visibility | display | multiple */ 33 [ "", "", false ], 34 [ "hidden", "", false ], 35 [ "", "none", false ], 36 [ "", "", true ], 37 [ "hidden", "", true ], 38 [ "", "none", true ], 39 ]; 40 41 var testCounter = 0; 42 var testNb = testData.length; 43 44 function finished() 45 { 46 MockFilePicker.cleanup(); 47 SimpleTest.finish(); 48 } 49 50 SimpleTest.waitForFocus(function() { 51 // mockFilePicker will simulate a cancel for the first time the file picker will be shown. 52 MockFilePicker.returnValue = MockFilePicker.returnCancel; 53 54 var b2 = document.getElementById('b2'); 55 b2.focus(); // Be sure the element is visible. 56 document.getElementById('b2').addEventListener("change", function(aEvent) { 57 ok(false, "When cancel is received, change should not fire"); 58 }, {once: true}); 59 60 SpecialPowers.wrap(document).notifyUserGestureActivation(); 61 b2.click(); 62 63 // Now, we can launch tests when file picker isn't canceled. 64 MockFilePicker.useBlobFile(); 65 MockFilePicker.returnValue = MockFilePicker.returnOK; 66 67 var b = document.getElementById('b'); 68 b.focus(); // Be sure the element is visible. 69 70 document.getElementById('a').addEventListener("change", function(aEvent) { 71 ok(true, "change event correctly sent"); 72 ok(aEvent.bubbles, "change event should bubble"); 73 ok(!aEvent.cancelable, "change event should not be cancelable"); 74 testCounter++; 75 76 if (testCounter >= testNb) { 77 aEvent.target.removeEventListener("change", arguments.callee); 78 SimpleTest.executeSoon(finished); 79 } else { 80 var data = testData[testCounter]; 81 var a = document.getElementById('a'); 82 a.style.visibility = data[0]; 83 a.style.display = data[1]; 84 a.multiple = data[2]; 85 86 SimpleTest.executeSoon(function() { 87 SpecialPowers.wrap(document).notifyUserGestureActivation(); 88 b.click(); 89 }); 90 } 91 }); 92 93 SpecialPowers.wrap(document).notifyUserGestureActivation(); 94 b.click(); 95 }); 96 97 </script> 98 </pre> 99 </body> 100 </html>