editor/composer/test/test_bug434998.xul

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/editor/composer/test/test_bug434998.xul	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,109 @@
     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=434998
    1.11 +-->
    1.12 +<window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
    1.13 +        title="Mozilla Bug 434998" 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=434998"
    1.21 +     target="_blank">Mozilla Bug 434998</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 +          // Should not throw
    1.64 +          var threw = false;
    1.65 +          try {
    1.66 +            this.mEditor.contentDocument.execCommand("bold", false, null);
    1.67 +          } catch (e) {
    1.68 +            threw = true;
    1.69 +          }
    1.70 +          ok(!threw, "The execCommand API should work on <xul:editor>");
    1.71 +          progress.removeProgressListener(progressListener, Components.interfaces.nsIWebProgress.NOTIFY_ALL);
    1.72 +          SimpleTest.finish();
    1.73 +        }
    1.74 +      }
    1.75 +    },
    1.76 +
    1.77 +
    1.78 +    onProgressChange : function(aWebProgress, aRequest,
    1.79 +                                aCurSelfProgress, aMaxSelfProgress,
    1.80 +                                aCurTotalProgress, aMaxTotalProgress)
    1.81 +    {
    1.82 +    },
    1.83 +
    1.84 +    onLocationChange : function(aWebProgress, aRequest, aLocation, aFlags)
    1.85 +    {
    1.86 +    },
    1.87 +
    1.88 +    onStatusChange : function(aWebProgress, aRequest, aStatus, aMessage)
    1.89 +    {
    1.90 +    },
    1.91 +
    1.92 +    onSecurityChange : function(aWebProgress, aRequest, aState)
    1.93 +    {
    1.94 +    },
    1.95 +
    1.96 +    mEditor: null
    1.97 +  };
    1.98 +
    1.99 +  var progress, progressListener;
   1.100 +
   1.101 +  function runTest() {
   1.102 +    var newEditorElement = document.getElementById("editor");
   1.103 +    newEditorElement.makeEditable("html", true);
   1.104 +    var docShell = newEditorElement.boxObject.QueryInterface(Components.interfaces.nsIEditorBoxObject).docShell;
   1.105 +    progress = docShell.QueryInterface(Components.interfaces.nsIInterfaceRequestor).getInterface(Components.interfaces.nsIWebProgress);
   1.106 +    progressListener = new EditorContentListener(newEditorElement);
   1.107 +    progress.addProgressListener(progressListener, Components.interfaces.nsIWebProgress.NOTIFY_ALL);
   1.108 +    newEditorElement.setAttribute("src", "data:text/html,");
   1.109 +  }
   1.110 +]]>
   1.111 +</script>
   1.112 +</window>

mercurial