test_bug1170334_wbp_xmlstyle.html 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <!DOCTYPE HTML>
  2. <html>
  3. <!--
  4. https://bugzilla.mozilla.org/show_bug.cgi?id=1170334
  5. -->
  6. <head>
  7. <title>Test for Bug 1170334 (nsWebBrowserPersist vs. XML stylesheets)</title>
  8. <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
  9. <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css" />
  10. </head>
  11. <body>
  12. <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1170334">Mozilla Bug 1170334</a>
  13. <p id="display"></p>
  14. <pre id="results"></pre>
  15. <div id="content">
  16. <iframe src="bug1170334_iframe.xml" id="iframe"></iframe>
  17. </div>
  18. <pre id="test">
  19. <script class="testbody" type="text/javascript;version=1.7">
  20. const nameStem="test_bug1170334_" + Date.now();
  21. const { Ci, Cc, Cu, Cr } = SpecialPowers;
  22. let iframe = document.getElementById("iframe");
  23. SimpleTest.waitForExplicitFinish();
  24. iframe.onload = function iframe_onload1() {
  25. let doc = iframe.contentDocument;
  26. ok(doc, "iframe content document exists");
  27. let wbp = Cc["@mozilla.org/embedding/browser/nsWebBrowserPersist;1"]
  28. .createInstance(Ci.nsIWebBrowserPersist);
  29. let ios = Cc["@mozilla.org/network/io-service;1"]
  30. .getService(Ci.nsIIOService);
  31. let tmp = Cc["@mozilla.org/file/directory_service;1"]
  32. .getService(Ci.nsIProperties)
  33. .get("TmpD", Ci.nsIFile);
  34. let tmpFile = tmp.clone();
  35. tmpFile.append(nameStem + "_iframe.xml");
  36. let tmpDir = tmp.clone();
  37. tmpDir.append(nameStem + "_files");
  38. // When the document in the iframe is saved, try to load the result.
  39. wbp.progressListener = {
  40. onProgressChange: function(){},
  41. onLocationChange: function(){},
  42. onStatusChange: function(){},
  43. onSecurityChange: function(){},
  44. onStateChange: function wbp_stateChange(_wbp, _req, state, status) {
  45. if ((state & Ci.nsIWebProgressListener.STATE_STOP) == 0) {
  46. return;
  47. }
  48. is(status, Cr.NS_OK, "nsWebBrowserPersist status");
  49. iframe.onload = function iframe_onload2() {
  50. let elem = iframe.contentDocument.documentElement;
  51. is(elem && elem.tagName, "thing", "document element tag");
  52. if (elem && elem.tagName == "parsererror") {
  53. ok(false, "Parser error: " + elem.textContent);
  54. }
  55. cleanUp();
  56. SimpleTest.finish();
  57. };
  58. iframe.src = ios.newFileURI(tmpFile).spec;
  59. }
  60. };
  61. wbp.saveDocument(doc, tmpFile, tmpDir, null, 0, 0);
  62. function cleanUp() {
  63. if (tmpFile.exists()) {
  64. tmpFile.remove(/* recursive: */ false);
  65. }
  66. if (tmpDir.exists()) {
  67. tmpDir.remove(/* recursive: */ true);
  68. }
  69. }
  70. };
  71. </script>
  72. </pre>
  73. </body>
  74. </html>