1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/editor/libeditor/base/tests/test_bug502673.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,108 @@ 1.4 +<!DOCTYPE HTML> 1.5 +<!-- This Source Code Form is subject to the terms of the Mozilla Public 1.6 + - License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + - file, You can obtain one at http://mozilla.org/MPL/2.0/. --> 1.8 +<html> 1.9 +<!-- 1.10 +https://bugzilla.mozilla.org/show_bug.cgi?id=502673 1.11 +--> 1.12 + 1.13 +<head> 1.14 + <title>Test for Bug 502673</title> 1.15 + <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> 1.16 + <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> 1.17 + <script type="text/javascript" src="/tests/SimpleTest/EventUtils.js"></script> 1.18 +</head> 1.19 + 1.20 +<body onload="doTest();"> 1.21 + <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=502673">Mozilla Bug 502673</a> 1.22 + <p id="display"></p> 1.23 + <div id="content" style="display: none"> 1.24 + </div> 1.25 + 1.26 + <pre id="test"> 1.27 + <script type="application/javascript"> 1.28 + 1.29 + /** Test for Bug 502673 **/ 1.30 + 1.31 + SimpleTest.waitForExplicitFinish(); 1.32 + 1.33 + function listener() { 1.34 + } 1.35 + 1.36 + listener.prototype = 1.37 + { 1.38 + NotifyDocumentWillBeDestroyed: function () { 1.39 + if (this.input instanceof SpecialPowers.Ci.nsIDOMNSEditableElement) { 1.40 + var editor = SpecialPowers.wrap(this.input).editor; 1.41 + editor.removeDocumentStateListener(this); 1.42 + } 1.43 + }, 1.44 + 1.45 + NotifyDocumentCreated: function () { 1.46 + }, 1.47 + 1.48 + NotifyDocumentStateChanged: function (aNowDirty) { 1.49 + if (this.input instanceof SpecialPowers.Ci.nsIDOMNSEditableElement) { 1.50 + var editor = SpecialPowers.wrap(this.input).editor; 1.51 + editor.removeDocumentStateListener(this); 1.52 + } 1.53 + }, 1.54 + 1.55 + QueryInterface: function(iid) { 1.56 + if (iid.equals(SpecialPowers.Ci.nsIDocumentStateListener) || 1.57 + iid.equals(SpecialPowers.Ci.nsISupports)) 1.58 + return this; 1.59 + throw SpecialPowers.Cr.NS_ERROR_NO_INTERFACE; 1.60 + }, 1.61 + }; 1.62 + 1.63 + function doTest() { 1.64 + var input = document.getElementById("ip"); 1.65 + if (input instanceof SpecialPowers.Ci.nsIDOMNSEditableElement) { 1.66 + // Add multiple listeners to the same editor 1.67 + var editor = SpecialPowers.wrap(input).editor; 1.68 + var listener1 = new listener(); 1.69 + listener1.input = input; 1.70 + var listener2 = new listener(); 1.71 + listener2.input = input; 1.72 + var listener3 = new listener(); 1.73 + listener3.input = input; 1.74 + editor.addDocumentStateListener(listener1); 1.75 + editor.addDocumentStateListener(listener2); 1.76 + editor.addDocumentStateListener(listener3); 1.77 + 1.78 + // Test 1. Fire NotifyDocumentStateChanged notifications where the 1.79 + // listeners remove themselves 1.80 + input.value = "mozilla"; 1.81 + editor.undo(1); 1.82 + 1.83 + // Report success if we get here - clearly we didn't crash 1.84 + ok(true, "Multiple listeners removed themselves after " + 1.85 + "NotifyDocumentStateChanged notifications - didn't crash"); 1.86 + 1.87 + // Add the listeners again for the next test 1.88 + editor.addDocumentStateListener(listener1); 1.89 + editor.addDocumentStateListener(listener2); 1.90 + editor.addDocumentStateListener(listener3); 1.91 + 1.92 + } 1.93 + 1.94 + // Test 2. Fire NotifyDocumentWillBeDestroyed notifications where the 1.95 + // listeners remove themselves (though in the real world, listeners 1.96 + // shouldn't do this as nsEditor::PreDestroy removes them as 1.97 + // listeners anyway) 1.98 + document.body.removeChild(input); 1.99 + ok(true, "Multiple listeners removed themselves after " + 1.100 + "NotifyDocumentWillBeDestroyed notifications - didn't crash"); 1.101 + 1.102 + // TODO: Test for NotifyDocumentCreated 1.103 + 1.104 + SimpleTest.finish(); 1.105 + } 1.106 + </script> 1.107 + </pre> 1.108 + 1.109 + <input type="text" id="ip" /> 1.110 +</body> 1.111 +</html>