summaryrefslogtreecommitdiffstats
path: root/toolkit/content/tests/chrome/test_menuitem_blink.xul
blob: 319c284fd718e666cb54c9504bf777f86c6d7129 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
<?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css" type="text/css"?>

<window title="Blinking Context Menu Item Tests"
        xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">

  <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>      
  <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"></script>      

  <menulist id="menulist">
    <menupopup id="menupopup">
      <menuitem label="Menu Item" id="menuitem"/>
    </menupopup>
  </menulist>
<script class="testbody" type="application/javascript">
<![CDATA[

SimpleTest.waitForExplicitFinish();
SimpleTest.waitForFocus(startTest);

function startTest() {
  if (!/Mac/.test(navigator.platform)) {
    ok(true, "Nothing to test on non-Mac.");
    SimpleTest.finish();
    return;
  }
  // Destroy frame while removing the _moz-menuactive attribute.
  test_crash("REMOVAL", test2);
}

function test2() {
  // Destroy frame while adding the _moz-menuactive attribute.
  test_crash("ADDITION", test3);
}

function test3() {
  // Don't mess with the frame, just test whether we've blinked.
  test_crash("", SimpleTest.finish);
}

function test_crash(when, andThen) {
  var menupopup = document.getElementById("menupopup");
  var menuitem = document.getElementById("menuitem");
  var attrChanges = { "REMOVAL": 0, "ADDITION": 0 };
  var storedEvent = null;
  menupopup.addEventListener("popupshown", function () {
    menupopup.removeEventListener("popupshown", arguments.callee, false);
    menuitem.addEventListener("mouseup", function (e) {
      menuitem.removeEventListener("mouseup", arguments.callee, true);
      menuitem.addEventListener("DOMAttrModified", function (e) {
        if (e.attrName == "_moz-menuactive") {
          if (!attrChanges[e.attrChange])
            attrChanges[e.attrChange] = 1;
          else
            attrChanges[e.attrChange]++;
          storedEvent = e;
          if (e.attrChange == e[when]) {
            menuitem.hidden = true;
            menuitem.getBoundingClientRect();
            ok(true, "Didn't crash on _moz-menuactive " + when.toLowerCase() + " during blinking")
            menuitem.hidden = false;
            menuitem.removeEventListener("DOMAttrModified", arguments.callee, false);
            SimpleTest.executeSoon(function () {
              menupopup.hidePopup();
            });
          }
        }
      }, false);
    }, true);
    menupopup.addEventListener("popuphidden", function() {
      menupopup.removeEventListener("popuphidden", arguments.callee, false);
      if (!when) {
        // Test whether we've blinked at all.
        var shouldBlink = navigator.platform.match(/Mac/);
        var expectedNumRemoval = shouldBlink ? 2 : 1;
        var expectedNumAddition = shouldBlink ? 1 : 0;
        ok(storedEvent, "got DOMAttrModified events after clicking menuitem")
        is(attrChanges[storedEvent.REMOVAL], expectedNumRemoval, "blinking unset attributes correctly");
        is(attrChanges[storedEvent.ADDITION], expectedNumAddition, "blinking set attributes correctly");
      }
      SimpleTest.executeSoon(andThen);
    }, false);
    synthesizeMouse(menuitem, 10, 5, { type : "mousemove" });
    synthesizeMouse(menuitem, 10, 5, { type : "mousemove" });
    synthesizeMouse(menuitem, 10, 5, { type : "mousedown" });
    SimpleTest.executeSoon(function () {
      synthesizeMouse(menuitem, 10, 5, { type : "mouseup" });
    });
  }, false);
  document.getElementById("menulist").open = true;
}

]]>
</script>

<body xmlns="http://www.w3.org/1999/xhtml">
<p id="display">
</p>
<div id="content" style="display: none">
</div>
<pre id="test">
</pre>
</body>

</window>