content/xul/document/test/test_bug468176.xul

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/content/xul/document/test/test_bug468176.xul	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,84 @@
     1.4 +<?xml version="1.0"?>
     1.5 +<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
     1.6 +<?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css" type="text/css"?>
     1.7 +<!--
     1.8 +https://bugzilla.mozilla.org/show_bug.cgi?id=468176
     1.9 +-->
    1.10 +<window title="Test for Bug 468176"
    1.11 +  id="test_bug468176_xul"
    1.12 +  xmlns:html="http://www.w3.org/1999/xhtml"
    1.13 +  xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
    1.14 +  xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
    1.15 +
    1.16 +  <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
    1.17 +
    1.18 +<body id="body" xmlns="http://www.w3.org/1999/xhtml">
    1.19 +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=468176">Mozilla Bug 468176</a>
    1.20 +
    1.21 +<xul:hbox id="b1" value="foo"/>
    1.22 +
    1.23 +<xul:hbox id="o1">
    1.24 +  <xul:observes id="inner" element="b1" attribute="*"/>
    1.25 +</xul:hbox>
    1.26 +
    1.27 +<pre id="test">
    1.28 +  <script class="testbody" type="text/javascript">
    1.29 +<![CDATA[
    1.30 +  SimpleTest.waitForExplicitFinish();
    1.31 +
    1.32 +  var broadcastCount = 0;
    1.33 +  function b_listener(evt) {
    1.34 +    ++broadcastCount;
    1.35 +  }
    1.36 +
    1.37 +  function do_test() {
    1.38 +    var b1 = document.getElementById("b1");
    1.39 +    var o1 = document.getElementById("o1");
    1.40 +    var inner = document.getElementById("inner");
    1.41 +    is(o1.getAttribute("value"), b1.getAttribute("value"), "Wrong value (1)");
    1.42 +
    1.43 +    inner.addEventListener("broadcast", b_listener, true);
    1.44 +    b1.setAttribute("value", "bar");
    1.45 +    is(o1.getAttribute("value"), b1.getAttribute("value"), "Wrong value (2)");
    1.46 +    is(broadcastCount, 1, "Wrong value (3)");
    1.47 +
    1.48 +    b1.removeAttribute("value");
    1.49 +    is(o1.hasAttribute("value"), b1.hasAttribute("value"), "Wrong value (4)");
    1.50 +    is(broadcastCount, 2, "Wrong value (5)");
    1.51 +
    1.52 +    o1.setAttribute("value", "foo");
    1.53 +    isnot(o1.getAttribute("value"), b1.getAttribute("value"), "Wrong value (6)");
    1.54 +    is(broadcastCount, 2, "Wrong value (7)");
    1.55 +
    1.56 +    b1.setAttribute("value", "foobar");
    1.57 +    is(o1.getAttribute("value"), b1.getAttribute("value"), "Wrong value (8)");
    1.58 +    is(broadcastCount, 3, "Wrong value (9)");
    1.59 +
    1.60 +    b1.removeAttribute("value");
    1.61 +    is(o1.getAttribute("value"), b1.getAttribute("value"), "Wrong value (10)");
    1.62 +    is(broadcastCount, 4, "Wrong value (11)");
    1.63 +
    1.64 +    b1.removeAttribute("value");
    1.65 +    is(o1.getAttribute("value"), b1.getAttribute("value"), "Wrong value (12)");
    1.66 +    is(broadcastCount, 4, "Wrong value (13)");
    1.67 +
    1.68 +    o1.setAttribute("value", "bar");
    1.69 +    b1.setAttribute("value", "bar"); // This should still dispatch 'broadcast'
    1.70 +    is(o1.getAttribute("value"), b1.getAttribute("value"), "Wrong value (14)");
    1.71 +    is(broadcastCount, 5, "Wrong value (15)");
    1.72 +
    1.73 +    //After removing listener, changes to broadcaster shouldn't have any effect.
    1.74 +    o1.parentNode.removeChild(o1);
    1.75 +    b1.setAttribute("value", "foo");
    1.76 +    isnot(o1.getAttribute("value"), b1.getAttribute("value"), "Wrong value (16)");
    1.77 +    is(broadcastCount, 5, "Wrong value (17)");
    1.78 +
    1.79 +    SimpleTest.finish();
    1.80 +  }
    1.81 +
    1.82 +  addLoadEvent(do_test);
    1.83 +]]>
    1.84 +  </script>
    1.85 +</pre>
    1.86 +</body>
    1.87 +</window>

mercurial