test_bug502673.html (3291B)
1 <!DOCTYPE HTML> 2 <!-- This Source Code Form is subject to the terms of the Mozilla Public 3 - License, v. 2.0. If a copy of the MPL was not distributed with this 4 - file, You can obtain one at http://mozilla.org/MPL/2.0/. --> 5 <html> 6 <!-- 7 https://bugzilla.mozilla.org/show_bug.cgi?id=502673 8 --> 9 10 <head> 11 <title>Test for Bug 502673</title> 12 <script src="/tests/SimpleTest/SimpleTest.js"></script> 13 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> 14 <script src="/tests/SimpleTest/EventUtils.js"></script> 15 </head> 16 17 <body onload="doTest();"> 18 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=502673">Mozilla Bug 502673</a> 19 <p id="display"></p> 20 <div id="content" style="display: none"> 21 </div> 22 23 <pre id="test"> 24 <script type="application/javascript"> 25 26 /** Test for Bug 502673 */ 27 28 SimpleTest.waitForExplicitFinish(); 29 30 function listener() { 31 } 32 33 listener.prototype = 34 { 35 NotifyDocumentWillBeDestroyed() { 36 var editor = SpecialPowers.wrap(this.input).editor; 37 editor.removeDocumentStateListener(this); 38 }, 39 40 NotifyDocumentStateChanged() { 41 var editor = SpecialPowers.wrap(this.input).editor; 42 editor.removeDocumentStateListener(this); 43 }, 44 45 QueryInterface: SpecialPowers.wrapCallback(function(iid) { 46 if (iid.equals(SpecialPowers.Ci.nsIDocumentStateListener) || 47 iid.equals(SpecialPowers.Ci.nsISupports)) 48 return this; 49 throw SpecialPowers.Cr.NS_ERROR_NO_INTERFACE; 50 }), 51 }; 52 53 function doTest() { 54 var input = document.getElementById("ip"); 55 56 // Add multiple listeners to the same editor 57 var editor = SpecialPowers.wrap(input).editor; 58 var listener1 = new listener(); 59 listener1.input = input; 60 var listener2 = new listener(); 61 listener2.input = input; 62 var listener3 = new listener(); 63 listener3.input = input; 64 editor.addDocumentStateListener(listener1); 65 editor.addDocumentStateListener(listener2); 66 editor.addDocumentStateListener(listener3); 67 68 // Test 1. Fire NotifyDocumentStateChanged notifications where the 69 // listeners remove themselves 70 input.value = "mozilla"; 71 editor.undo(); 72 73 // Report success if we get here - clearly we didn't crash 74 ok(true, "Multiple listeners removed themselves after " + 75 "NotifyDocumentStateChanged notifications - didn't crash"); 76 77 // Add the listeners again for the next test 78 editor.addDocumentStateListener(listener1); 79 editor.addDocumentStateListener(listener2); 80 editor.addDocumentStateListener(listener3); 81 82 // Test 2. Fire NotifyDocumentWillBeDestroyed notifications where the 83 // listeners remove themselves (though in the real world, listeners 84 // shouldn't do this as nsEditor::PreDestroy removes them as 85 // listeners anyway) 86 document.body.removeChild(input); 87 ok(true, "Multiple listeners removed themselves after " + 88 "NotifyDocumentWillBeDestroyed notifications - didn't crash"); 89 90 SimpleTest.finish(); 91 } 92 </script> 93 </pre> 94 95 <input type="text" id="ip" /> 96 </body> 97 </html>