editor/libeditor/html/tests/test_bug607584.xul

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:fc9be7bcf89a
1 <?xml version="1.0"?>
2 <?xml-stylesheet href="chrome://global/skin"
3 type="text/css"?>
4 <?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css"
5 type="text/css"?>
6 <!--
7 https://bugzilla.mozilla.org/show_bug.cgi?id=607584
8 -->
9 <window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
10 title="Mozilla Bug 607584" onload="runTest();">
11 <script type="application/javascript"
12 src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"/>
13 <script type="application/javascript"
14 src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
15
16 <body xmlns="http://www.w3.org/1999/xhtml">
17 <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=607584"
18 target="_blank">Mozilla Bug 607584</a>
19 <p/>
20 <editor xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
21 id="editor"
22 type="content-primary"
23 editortype="html"
24 style="width: 400px; height: 100px; border: thin solid black"/>
25 <p/>
26 <pre id="test">
27 </pre>
28 </body>
29 <script class="testbody" type="application/javascript">
30 <![CDATA[
31
32 SimpleTest.waitForExplicitFinish();
33
34 function EditorContentListener(aEditor)
35 {
36 this.init(aEditor);
37 }
38
39 EditorContentListener.prototype = {
40 init : function(aEditor)
41 {
42 this.mEditor = aEditor;
43 },
44
45 QueryInterface : function(aIID)
46 {
47 if (aIID.equals(Components.interfaces.nsIWebProgressListener) ||
48 aIID.equals(Components.interfaces.nsISupportsWeakReference) ||
49 aIID.equals(Components.interfaces.nsISupports))
50 return this;
51 throw Components.results.NS_NOINTERFACE;
52 },
53
54 onStateChange : function(aWebProgress, aRequest, aStateFlags, aStatus)
55 {
56 if (aStateFlags & Components.interfaces.nsIWebProgressListener.STATE_STOP)
57 {
58 var editor = this.mEditor.getEditor(this.mEditor.contentWindow);
59 if (editor) {
60 this.mEditor.focus();
61 editor instanceof Components.interfaces.nsIHTMLEditor;
62 editor.returnInParagraphCreatesNewParagraph = true;
63 editor.insertHTML("<p id='foo'>this is a paragraph carrying id 'foo'</p>");
64 var p = editor.document.getElementById('foo')
65 editor.beginningOfDocument();
66 sendKey("return");
67 var firstP = p.parentNode.firstElementChild;
68 var lastP = p.parentNode.lastElementChild;
69 var isOk = firstP.nodeName.toLowerCase() == "p" &&
70 firstP.id == "foo" &&
71 lastP.id == "";
72 ok(isOk, "CR in a paragraph with an ID should not create two paragraphs of same ID");
73 progress.removeProgressListener(this);
74 SimpleTest.finish();
75 }
76 }
77
78 },
79
80
81 onProgressChange : function(aWebProgress, aRequest,
82 aCurSelfProgress, aMaxSelfProgress,
83 aCurTotalProgress, aMaxTotalProgress)
84 {
85 },
86
87 onLocationChange : function(aWebProgress, aRequest, aLocation, aFlags)
88 {
89 },
90
91 onStatusChange : function(aWebProgress, aRequest, aStatus, aMessage)
92 {
93 },
94
95 onSecurityChange : function(aWebProgress, aRequest, aState)
96 {
97 },
98
99 mEditor: null
100 };
101
102 var progress, progressListener;
103
104 function runTest() {
105 var newEditorElement = document.getElementById("editor");
106 newEditorElement.makeEditable("html", true);
107 var docShell = newEditorElement.boxObject.QueryInterface(Components.interfaces.nsIEditorBoxObject).docShell;
108 progress = docShell.QueryInterface(Components.interfaces.nsIInterfaceRequestor).getInterface(Components.interfaces.nsIWebProgress);
109 progressListener = new EditorContentListener(newEditorElement);
110 progress.addProgressListener(progressListener, Components.interfaces.nsIWebProgress.NOTIFY_ALL);
111 newEditorElement.setAttribute("src", "data:text/html,");
112 }
113 ]]>
114 </script>
115 </window>

mercurial