test_bug592802.html 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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 type="application/javascript" 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=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. /** Test for Bug 592802 **/
  24. SimpleTest.waitForExplicitFinish();
  25. var MockFilePicker = SpecialPowers.MockFilePicker;
  26. MockFilePicker.init(window);
  27. var testData = [
  28. /* visibility | display | multiple */
  29. [ "", "", false ],
  30. [ "hidden", "", false ],
  31. [ "", "none", false ],
  32. [ "", "", true ],
  33. [ "hidden", "", true ],
  34. [ "", "none", true ],
  35. ];
  36. var testCounter = 0;
  37. var testNb = testData.length;
  38. function finished()
  39. {
  40. MockFilePicker.cleanup();
  41. SimpleTest.finish();
  42. }
  43. SimpleTest.waitForFocus(function() {
  44. // mockFilePicker will simulate a cancel for the first time the file picker will be shown.
  45. MockFilePicker.returnValue = MockFilePicker.returnCancel;
  46. var b2 = document.getElementById('b2');
  47. b2.focus(); // Be sure the element is visible.
  48. document.getElementById('b2').addEventListener("change", function(aEvent) {
  49. aEvent.target.removeEventListener("change", arguments.callee, false);
  50. ok(false, "When cancel is received, change should not fire");
  51. }, false);
  52. b2.click();
  53. // Now, we can launch tests when file picker isn't canceled.
  54. MockFilePicker.useBlobFile();
  55. MockFilePicker.returnValue = MockFilePicker.returnOK;
  56. var b = document.getElementById('b');
  57. b.focus(); // Be sure the element is visible.
  58. document.getElementById('a').addEventListener("change", function(aEvent) {
  59. ok(true, "change event correctly sent");
  60. ok(aEvent.bubbles, "change event should bubble");
  61. ok(!aEvent.cancelable, "change event should not be cancelable");
  62. testCounter++;
  63. if (testCounter >= testNb) {
  64. aEvent.target.removeEventListener("change", arguments.callee, false);
  65. SimpleTest.executeSoon(finished);
  66. } else {
  67. var data = testData[testCounter];
  68. var a = document.getElementById('a');
  69. a.style.visibility = data[0];
  70. a.style.display = data[1];
  71. a.multiple = data[2];
  72. SimpleTest.executeSoon(function() {
  73. b.click();
  74. });
  75. }
  76. }, false);
  77. b.click();
  78. });
  79. </script>
  80. </pre>
  81. </body>
  82. </html>