test_bug468176.xul 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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=468176
  6. -->
  7. <window title="Test for Bug 468176"
  8. id="test_bug468176_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=468176">Mozilla Bug 468176</a>
  15. <xul:hbox id="b1" value="foo"/>
  16. <xul:hbox id="o1">
  17. <xul:observes id="inner" element="b1" attribute="*"/>
  18. </xul:hbox>
  19. <pre id="test">
  20. <script class="testbody" type="text/javascript">
  21. <![CDATA[
  22. SimpleTest.waitForExplicitFinish();
  23. var broadcastCount = 0;
  24. function b_listener(evt) {
  25. ++broadcastCount;
  26. }
  27. function do_test() {
  28. var b1 = document.getElementById("b1");
  29. var o1 = document.getElementById("o1");
  30. var inner = document.getElementById("inner");
  31. is(o1.getAttribute("value"), b1.getAttribute("value"), "Wrong value (1)");
  32. inner.addEventListener("broadcast", b_listener, true);
  33. b1.setAttribute("value", "bar");
  34. is(o1.getAttribute("value"), b1.getAttribute("value"), "Wrong value (2)");
  35. is(broadcastCount, 1, "Wrong value (3)");
  36. b1.removeAttribute("value");
  37. is(o1.hasAttribute("value"), b1.hasAttribute("value"), "Wrong value (4)");
  38. is(broadcastCount, 2, "Wrong value (5)");
  39. o1.setAttribute("value", "foo");
  40. isnot(o1.getAttribute("value"), b1.getAttribute("value"), "Wrong value (6)");
  41. is(broadcastCount, 2, "Wrong value (7)");
  42. b1.setAttribute("value", "foobar");
  43. is(o1.getAttribute("value"), b1.getAttribute("value"), "Wrong value (8)");
  44. is(broadcastCount, 3, "Wrong value (9)");
  45. b1.removeAttribute("value");
  46. is(o1.getAttribute("value"), b1.getAttribute("value"), "Wrong value (10)");
  47. is(broadcastCount, 4, "Wrong value (11)");
  48. b1.removeAttribute("value");
  49. is(o1.getAttribute("value"), b1.getAttribute("value"), "Wrong value (12)");
  50. is(broadcastCount, 4, "Wrong value (13)");
  51. o1.setAttribute("value", "bar");
  52. b1.setAttribute("value", "bar"); // This should still dispatch 'broadcast'
  53. is(o1.getAttribute("value"), b1.getAttribute("value"), "Wrong value (14)");
  54. is(broadcastCount, 5, "Wrong value (15)");
  55. //After removing listener, changes to broadcaster shouldn't have any effect.
  56. o1.parentNode.removeChild(o1);
  57. b1.setAttribute("value", "foo");
  58. isnot(o1.getAttribute("value"), b1.getAttribute("value"), "Wrong value (16)");
  59. is(broadcastCount, 5, "Wrong value (17)");
  60. SimpleTest.finish();
  61. }
  62. addLoadEvent(do_test);
  63. ]]>
  64. </script>
  65. </pre>
  66. </body>
  67. </window>