test_bug1192654.html 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <!DOCTYPE HTML>
  2. <html>
  3. <!--
  4. https://bugzilla.mozilla.org/show_bug.cgi?id=1192654
  5. -->
  6. <head>
  7. <title>Test for Bug 1192654 (nsWebBrowser vs. nonpersistable subdocuments)</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=1192654">Mozilla Bug 1192654</a>
  13. <p id="display"></p>
  14. <pre id="results"></pre>
  15. <div id="content">
  16. <!-- The outer iframe uses a data URI for simplicity; this would
  17. also work if it were loaded from a support file by relative
  18. URI. The inner iframe (the one nsWebBrowserPersist traverses)
  19. uses a data URI because data: is a non-persistable scheme and
  20. thus triggers the bug.
  21. -->
  22. <iframe src="data:text/html,<iframe%20src=%22data:text/plain,Example%22>"
  23. id="iframe"></iframe>
  24. </div>
  25. <pre id="test">
  26. <script class="testbody" type="text/javascript;version=1.7">
  27. const nameStem="test_bug1192654_" + Date.now();
  28. const { Ci, Cc, Cu, Cr } = SpecialPowers;
  29. let iframe = document.getElementById("iframe");
  30. SimpleTest.waitForExplicitFinish();
  31. iframe.onload = function iframe_onload1() {
  32. let doc = iframe.contentDocument;
  33. ok(doc, "iframe content document exists");
  34. let wbp = Cc["@mozilla.org/embedding/browser/nsWebBrowserPersist;1"]
  35. .createInstance(Ci.nsIWebBrowserPersist);
  36. let tmp = Cc["@mozilla.org/file/directory_service;1"]
  37. .getService(Ci.nsIProperties)
  38. .get("TmpD", Ci.nsIFile);
  39. let tmpFile = tmp.clone();
  40. tmpFile.append(nameStem + "_iframe.xml");
  41. let tmpDir = tmp.clone();
  42. tmpDir.append(nameStem + "_files");
  43. wbp.progressListener = {
  44. onProgressChange: function(){},
  45. onLocationChange: function(){},
  46. onStatusChange: function(){},
  47. onSecurityChange: function(){},
  48. onStateChange: wbp_stateChange,
  49. };
  50. SimpleTest.registerCleanupFunction(cleanUp);
  51. wbp.saveDocument(doc, tmpFile, tmpDir, null, 0, 0);
  52. function wbp_stateChange(_wbp, _req, state, status) {
  53. if ((state & Ci.nsIWebProgressListener.STATE_STOP) == 0) {
  54. return;
  55. }
  56. is(status, Cr.NS_OK, "nsWebBrowserPersist status");
  57. SimpleTest.finish();
  58. }
  59. function cleanUp() {
  60. if (tmpFile.exists()) {
  61. tmpFile.remove(/* recursive: */ false);
  62. }
  63. if (tmpDir.exists()) {
  64. tmpDir.remove(/* recursive: */ true);
  65. }
  66. }
  67. };
  68. </script>
  69. </pre>
  70. </body>
  71. </html>