editor/libeditor/html/tests/test_bug607584.xul

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/editor/libeditor/html/tests/test_bug607584.xul	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,115 @@
     1.4 +<?xml version="1.0"?>
     1.5 +<?xml-stylesheet href="chrome://global/skin"
     1.6 +                 type="text/css"?>
     1.7 +<?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css"
     1.8 +                 type="text/css"?>
     1.9 +<!--
    1.10 +https://bugzilla.mozilla.org/show_bug.cgi?id=607584
    1.11 +-->
    1.12 +<window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
    1.13 +        title="Mozilla Bug 607584" onload="runTest();">
    1.14 +  <script type="application/javascript"
    1.15 +    src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"/>
    1.16 +  <script type="application/javascript"
    1.17 +          src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
    1.18 +
    1.19 +  <body xmlns="http://www.w3.org/1999/xhtml">
    1.20 +  <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=607584"
    1.21 +     target="_blank">Mozilla Bug 607584</a>
    1.22 +  <p/>
    1.23 +  <editor xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
    1.24 +          id="editor"
    1.25 +          type="content-primary"
    1.26 +          editortype="html"
    1.27 +          style="width: 400px; height: 100px; border: thin solid black"/>
    1.28 +  <p/>
    1.29 +  <pre id="test">
    1.30 +  </pre>
    1.31 +  </body>
    1.32 +  <script class="testbody" type="application/javascript">
    1.33 +  <![CDATA[
    1.34 +
    1.35 +  SimpleTest.waitForExplicitFinish();
    1.36 +
    1.37 +  function EditorContentListener(aEditor)
    1.38 +  {
    1.39 +    this.init(aEditor);
    1.40 +  }
    1.41 +  
    1.42 +  EditorContentListener.prototype = {
    1.43 +    init : function(aEditor)
    1.44 +      {
    1.45 +        this.mEditor = aEditor;
    1.46 +      },
    1.47 +  
    1.48 +    QueryInterface : function(aIID)
    1.49 +      {
    1.50 +        if (aIID.equals(Components.interfaces.nsIWebProgressListener) ||
    1.51 +            aIID.equals(Components.interfaces.nsISupportsWeakReference) ||
    1.52 +            aIID.equals(Components.interfaces.nsISupports))
    1.53 +          return this;
    1.54 +        throw Components.results.NS_NOINTERFACE;
    1.55 +      },
    1.56 +  
    1.57 +    onStateChange : function(aWebProgress, aRequest, aStateFlags, aStatus)
    1.58 +    {
    1.59 +        if (aStateFlags & Components.interfaces.nsIWebProgressListener.STATE_STOP)
    1.60 +        {
    1.61 +          var editor = this.mEditor.getEditor(this.mEditor.contentWindow);
    1.62 +          if (editor) {
    1.63 +              this.mEditor.focus();
    1.64 +              editor instanceof Components.interfaces.nsIHTMLEditor;
    1.65 +              editor.returnInParagraphCreatesNewParagraph = true;
    1.66 +              editor.insertHTML("<p id='foo'>this is a paragraph carrying id 'foo'</p>");
    1.67 +              var p = editor.document.getElementById('foo')
    1.68 +              editor.beginningOfDocument();
    1.69 +              sendKey("return");
    1.70 +              var firstP = p.parentNode.firstElementChild;
    1.71 +              var lastP  = p.parentNode.lastElementChild;
    1.72 +              var isOk = firstP.nodeName.toLowerCase() == "p" &&
    1.73 +	                       firstP.id == "foo" &&
    1.74 +	                       lastP.id == "";
    1.75 +              ok(isOk, "CR in a paragraph with an ID should not create two paragraphs of same ID");
    1.76 +              progress.removeProgressListener(this);
    1.77 +              SimpleTest.finish();
    1.78 +          }
    1.79 +        }
    1.80 +  
    1.81 +    },
    1.82 +  
    1.83 +  
    1.84 +    onProgressChange : function(aWebProgress, aRequest,
    1.85 +                                aCurSelfProgress, aMaxSelfProgress,
    1.86 +                                aCurTotalProgress, aMaxTotalProgress)
    1.87 +      {
    1.88 +      },
    1.89 +  
    1.90 +    onLocationChange : function(aWebProgress, aRequest, aLocation, aFlags)
    1.91 +      {
    1.92 +      },
    1.93 +  
    1.94 +    onStatusChange : function(aWebProgress, aRequest, aStatus, aMessage)
    1.95 +      {
    1.96 +      },
    1.97 +  
    1.98 +    onSecurityChange : function(aWebProgress, aRequest, aState)
    1.99 +      {
   1.100 +      },
   1.101 +  
   1.102 +      mEditor: null
   1.103 +  };
   1.104 +
   1.105 +  var progress, progressListener;
   1.106 +
   1.107 +  function runTest() {
   1.108 +    var newEditorElement = document.getElementById("editor");
   1.109 +    newEditorElement.makeEditable("html", true);
   1.110 +    var docShell = newEditorElement.boxObject.QueryInterface(Components.interfaces.nsIEditorBoxObject).docShell;
   1.111 +    progress = docShell.QueryInterface(Components.interfaces.nsIInterfaceRequestor).getInterface(Components.interfaces.nsIWebProgress);
   1.112 +    progressListener = new EditorContentListener(newEditorElement);
   1.113 +    progress.addProgressListener(progressListener, Components.interfaces.nsIWebProgress.NOTIFY_ALL);
   1.114 +    newEditorElement.setAttribute("src", "data:text/html,");
   1.115 +  }
   1.116 +]]>
   1.117 +</script>
   1.118 +</window>

mercurial