test_bug445177.xul 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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=445177
  6. -->
  7. <window title="Test for Bug 445177"
  8. id="test_bug445177_xul"
  9. xmlns:html="http://www.w3.org/1999/xhtml"
  10. xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
  11. xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
  12. <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
  13. <body id="body" xmlns="http://www.w3.org/1999/xhtml">
  14. <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=445177">Mozilla Bug 445177</a>
  15. <hbox id="b1" value="foo"/>
  16. <hbox id="o1" observes="b1"/>
  17. <pre id="test">
  18. <script class="testbody" type="text/javascript">
  19. <![CDATA[
  20. SimpleTest.waitForExplicitFinish();
  21. function do_test() {
  22. var b1 = document.getElementById("b1");
  23. var o1 = document.getElementById("o1");
  24. is(o1.getAttribute("value"), b1.getAttribute("value"), "Wrong value (1)");
  25. b1.setAttribute("value", "bar");
  26. is(o1.getAttribute("value"), b1.getAttribute("value"), "Wrong value (2)");
  27. b1.removeAttribute("value");
  28. is(o1.hasAttribute("value"), b1.hasAttribute("value"), "Wrong value (3)");
  29. o1.setAttribute("value", "foo");
  30. isnot(o1.getAttribute("value"), b1.getAttribute("value"), "Wrong value (4)");
  31. b1.setAttribute("value", "foobar");
  32. is(o1.getAttribute("value"), b1.getAttribute("value"), "Wrong value (5)");
  33. //After removing listener, changes to broadcaster shouldn't have any effect.
  34. o1.parentNode.removeChild(o1);
  35. b1.setAttribute("value", "foo");
  36. isnot(o1.getAttribute("value"), b1.getAttribute("value"), "Wrong value (6)");
  37. b1.parentNode.appendChild(o1);
  38. is(o1.getAttribute("value"), b1.getAttribute("value"), "Wrong value (7)");
  39. o1.parentNode.removeChild(o1);
  40. o1.removeAttribute("observes");
  41. o1.removeAttribute("value");
  42. b1.parentNode.appendChild(o1);
  43. isnot(o1.getAttribute("value"), b1.getAttribute("value"), "Wrong value (8)");
  44. document.addBroadcastListenerFor(b1, o1, "value");
  45. is(o1.getAttribute("value"), b1.getAttribute("value"), "Wrong value (9)");
  46. o1.parentNode.removeChild(o1);
  47. b1.setAttribute("value", "foobar");
  48. is(o1.getAttribute("value"), b1.getAttribute("value"), "Wrong value (10)");
  49. b1.parentNode.appendChild(o1);
  50. is(o1.getAttribute("value"), b1.getAttribute("value"), "Wrong value (11)");
  51. o1.setAttribute("observes", "b1");
  52. is(o1.getAttribute("value"), b1.getAttribute("value"), "Wrong value (12)");
  53. // When broadcaster isn't in document, changes to its attributes aren't
  54. // reflected to listener.
  55. b1.parentNode.removeChild(b1);
  56. b1.setAttribute("value", "foo");
  57. isnot(o1.getAttribute("value"), b1.getAttribute("value"), "Wrong value (13)");
  58. SimpleTest.finish();
  59. }
  60. addLoadEvent(do_test);
  61. ]]>
  62. </script>
  63. </pre>
  64. </body>
  65. </window>