editor/libeditor/base/tests/test_bug502673.html

branch
TOR_BUG_3246
changeset 7
129ffea94266
equal deleted inserted replaced
-1:000000000000 0:bb62034f010e
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 type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
13 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
14 <script type="text/javascript" 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: function () {
36 if (this.input instanceof SpecialPowers.Ci.nsIDOMNSEditableElement) {
37 var editor = SpecialPowers.wrap(this.input).editor;
38 editor.removeDocumentStateListener(this);
39 }
40 },
41
42 NotifyDocumentCreated: function () {
43 },
44
45 NotifyDocumentStateChanged: function (aNowDirty) {
46 if (this.input instanceof SpecialPowers.Ci.nsIDOMNSEditableElement) {
47 var editor = SpecialPowers.wrap(this.input).editor;
48 editor.removeDocumentStateListener(this);
49 }
50 },
51
52 QueryInterface: function(iid) {
53 if (iid.equals(SpecialPowers.Ci.nsIDocumentStateListener) ||
54 iid.equals(SpecialPowers.Ci.nsISupports))
55 return this;
56 throw SpecialPowers.Cr.NS_ERROR_NO_INTERFACE;
57 },
58 };
59
60 function doTest() {
61 var input = document.getElementById("ip");
62 if (input instanceof SpecialPowers.Ci.nsIDOMNSEditableElement) {
63 // Add multiple listeners to the same editor
64 var editor = SpecialPowers.wrap(input).editor;
65 var listener1 = new listener();
66 listener1.input = input;
67 var listener2 = new listener();
68 listener2.input = input;
69 var listener3 = new listener();
70 listener3.input = input;
71 editor.addDocumentStateListener(listener1);
72 editor.addDocumentStateListener(listener2);
73 editor.addDocumentStateListener(listener3);
74
75 // Test 1. Fire NotifyDocumentStateChanged notifications where the
76 // listeners remove themselves
77 input.value = "mozilla";
78 editor.undo(1);
79
80 // Report success if we get here - clearly we didn't crash
81 ok(true, "Multiple listeners removed themselves after " +
82 "NotifyDocumentStateChanged notifications - didn't crash");
83
84 // Add the listeners again for the next test
85 editor.addDocumentStateListener(listener1);
86 editor.addDocumentStateListener(listener2);
87 editor.addDocumentStateListener(listener3);
88
89 }
90
91 // Test 2. Fire NotifyDocumentWillBeDestroyed notifications where the
92 // listeners remove themselves (though in the real world, listeners
93 // shouldn't do this as nsEditor::PreDestroy removes them as
94 // listeners anyway)
95 document.body.removeChild(input);
96 ok(true, "Multiple listeners removed themselves after " +
97 "NotifyDocumentWillBeDestroyed notifications - didn't crash");
98
99 // TODO: Test for NotifyDocumentCreated
100
101 SimpleTest.finish();
102 }
103 </script>
104 </pre>
105
106 <input type="text" id="ip" />
107 </body>
108 </html>

mercurial