test_bug640158_overlay_persist.xul 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?xml version="1.0"?>
  2. <?xml-stylesheet href="chrome://global/skin" type="text/css"?>
  3. <?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css" type="text/css"?>
  4. <!--
  5. https://bugzilla.mozilla.org/show_bug.cgi?id=640158
  6. -->
  7. <window title="Mozilla Bug 640158" id="rootwin"
  8. xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
  9. <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
  10. <!-- test results are displayed in the html:body -->
  11. <body xmlns="http://www.w3.org/1999/xhtml">
  12. <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=640158"
  13. target="_blank">Mozilla Bug 640158</a>
  14. </body>
  15. <!-- test code goes here -->
  16. <script type="application/javascript"><![CDATA[
  17. SimpleTest.waitForExplicitFinish();
  18. window.onload = function onload() {
  19. is($("foo").getAttribute("testattr"), "original", "Attribute should be in original state");
  20. // Change and persist another value:
  21. $("foo").setAttribute("testattr", "changed");
  22. document.persist("foo", "testattr");
  23. $("foo").setAttribute("testattr", "original");
  24. // Hacky times: check that items which are overlaid do get persisted into correctly,
  25. // by first creating an extra element and persisting the value before loading an
  26. // overlay that changes that value - the persisted value should be reinstated.
  27. let root = document.documentElement;
  28. let bar = document.createElement("box");
  29. bar.id = "bar";
  30. bar.setAttribute("testattr", "changed"); // The overlay we load has 'original'
  31. root.appendChild(bar);
  32. document.persist("bar", "testattr");
  33. document.loadOverlay(location.href.replace(/[^\\\/]*.xul/, "overlay_bug640158.xul"), function() {
  34. is($("foo").getAttribute("testattr"), "original",
  35. "Non-overlaid attribute should still be in original state");
  36. is($("bar").getAttribute("testattr"), "changed",
  37. "Overlaid attribute should have been changed.");
  38. SimpleTest.finish();
  39. });
  40. }
  41. ]]></script>
  42. <box id="foo" testattr="original"/>
  43. </window>