test_bug434998.xul 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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=434998
  8. -->
  9. <window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
  10. title="Mozilla Bug 434998" 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. <body xmlns="http://www.w3.org/1999/xhtml">
  16. <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=434998"
  17. target="_blank">Mozilla Bug 434998</a>
  18. <p/>
  19. <editor xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
  20. id="editor"
  21. type="content-primary"
  22. editortype="html"
  23. style="width: 400px; height: 100px; border: thin solid black"/>
  24. <p/>
  25. <pre id="test">
  26. </pre>
  27. </body>
  28. <script class="testbody" type="application/javascript">
  29. <![CDATA[
  30. SimpleTest.waitForExplicitFinish();
  31. function EditorContentListener(aEditor)
  32. {
  33. this.init(aEditor);
  34. }
  35. EditorContentListener.prototype = {
  36. init : function(aEditor)
  37. {
  38. this.mEditor = aEditor;
  39. },
  40. QueryInterface : function(aIID)
  41. {
  42. if (aIID.equals(Components.interfaces.nsIWebProgressListener) ||
  43. aIID.equals(Components.interfaces.nsISupportsWeakReference) ||
  44. aIID.equals(Components.interfaces.nsISupports))
  45. return this;
  46. throw Components.results.NS_NOINTERFACE;
  47. },
  48. onStateChange : function(aWebProgress, aRequest, aStateFlags, aStatus)
  49. {
  50. if (aStateFlags & Components.interfaces.nsIWebProgressListener.STATE_STOP)
  51. {
  52. var editor = this.mEditor.getEditor(this.mEditor.contentWindow);
  53. if (editor) {
  54. // Should not throw
  55. var threw = false;
  56. try {
  57. this.mEditor.contentDocument.execCommand("bold", false, null);
  58. } catch (e) {
  59. threw = true;
  60. }
  61. ok(!threw, "The execCommand API should work on <xul:editor>");
  62. progress.removeProgressListener(progressListener, Components.interfaces.nsIWebProgress.NOTIFY_ALL);
  63. SimpleTest.finish();
  64. }
  65. }
  66. },
  67. onProgressChange : function(aWebProgress, aRequest,
  68. aCurSelfProgress, aMaxSelfProgress,
  69. aCurTotalProgress, aMaxTotalProgress)
  70. {
  71. },
  72. onLocationChange : function(aWebProgress, aRequest, aLocation, aFlags)
  73. {
  74. },
  75. onStatusChange : function(aWebProgress, aRequest, aStatus, aMessage)
  76. {
  77. },
  78. onSecurityChange : function(aWebProgress, aRequest, aState)
  79. {
  80. },
  81. mEditor: null
  82. };
  83. var progress, progressListener;
  84. function runTest() {
  85. var newEditorElement = document.getElementById("editor");
  86. newEditorElement.makeEditable("html", true);
  87. var docShell = newEditorElement.boxObject.docShell;
  88. progress = docShell.QueryInterface(Components.interfaces.nsIInterfaceRequestor).getInterface(Components.interfaces.nsIWebProgress);
  89. progressListener = new EditorContentListener(newEditorElement);
  90. progress.addProgressListener(progressListener, Components.interfaces.nsIWebProgress.NOTIFY_ALL);
  91. newEditorElement.setAttribute("src", "data:text/html,");
  92. }
  93. ]]>
  94. </script>
  95. </window>