toolkit/content/tests/chrome/test_menuitem_blink.xul

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

     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"?>
     5 <window title="Blinking Context Menu Item Tests"
     6         xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
     8   <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>      
     9   <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"></script>      
    11   <menulist id="menulist">
    12     <menupopup id="menupopup">
    13       <menuitem label="Menu Item" id="menuitem"/>
    14     </menupopup>
    15   </menulist>
    16 <script class="testbody" type="application/javascript">
    17 <![CDATA[
    19 SimpleTest.waitForExplicitFinish();
    20 SimpleTest.waitForFocus(startTest);
    22 function startTest() {
    23   if (!/Mac/.test(navigator.platform)) {
    24     ok(true, "Nothing to test on non-Mac.");
    25     SimpleTest.finish();
    26     return;
    27   }
    28   // Destroy frame while removing the _moz-menuactive attribute.
    29   test_crash("REMOVAL", test2);
    30 }
    32 function test2() {
    33   // Destroy frame while adding the _moz-menuactive attribute.
    34   test_crash("ADDITION", test3);
    35 }
    37 function test3() {
    38   // Don't mess with the frame, just test whether we've blinked.
    39   test_crash("", SimpleTest.finish);
    40 }
    42 function test_crash(when, andThen) {
    43   var menupopup = document.getElementById("menupopup");
    44   var menuitem = document.getElementById("menuitem");
    45   var attrChanges = { "REMOVAL": 0, "ADDITION": 0 };
    46   var storedEvent = null;
    47   menupopup.addEventListener("popupshown", function () {
    48     menupopup.removeEventListener("popupshown", arguments.callee, false);
    49     menuitem.addEventListener("mouseup", function (e) {
    50       menuitem.removeEventListener("mouseup", arguments.callee, true);
    51       menuitem.addEventListener("DOMAttrModified", function (e) {
    52         if (e.attrName == "_moz-menuactive") {
    53           if (!attrChanges[e.attrChange])
    54             attrChanges[e.attrChange] = 1;
    55           else
    56             attrChanges[e.attrChange]++;
    57           storedEvent = e;
    58           if (e.attrChange == e[when]) {
    59             menuitem.hidden = true;
    60             menuitem.getBoundingClientRect();
    61             ok(true, "Didn't crash on _moz-menuactive " + when.toLowerCase() + " during blinking")
    62             menuitem.hidden = false;
    63             menuitem.removeEventListener("DOMAttrModified", arguments.callee, false);
    64             SimpleTest.executeSoon(function () {
    65               menupopup.hidePopup();
    66             });
    67           }
    68         }
    69       }, false);
    70     }, true);
    71     menupopup.addEventListener("popuphidden", function() {
    72       menupopup.removeEventListener("popuphidden", arguments.callee, false);
    73       if (!when) {
    74         // Test whether we've blinked at all.
    75         var shouldBlink = navigator.platform.match(/Mac/);
    76         var expectedNumRemoval = shouldBlink ? 2 : 1;
    77         var expectedNumAddition = shouldBlink ? 1 : 0;
    78         ok(storedEvent, "got DOMAttrModified events after clicking menuitem")
    79         is(attrChanges[storedEvent.REMOVAL], expectedNumRemoval, "blinking unset attributes correctly");
    80         is(attrChanges[storedEvent.ADDITION], expectedNumAddition, "blinking set attributes correctly");
    81       }
    82       SimpleTest.executeSoon(andThen);
    83     }, false);
    84     synthesizeMouse(menuitem, 10, 5, { type : "mousemove" });
    85     synthesizeMouse(menuitem, 10, 5, { type : "mousemove" });
    86     synthesizeMouse(menuitem, 10, 5, { type : "mousedown" });
    87     SimpleTest.executeSoon(function () {
    88       synthesizeMouse(menuitem, 10, 5, { type : "mouseup" });
    89     });
    90   }, false);
    91   document.getElementById("menulist").open = true;
    92 }
    94 ]]>
    95 </script>
    97 <body xmlns="http://www.w3.org/1999/xhtml">
    98 <p id="display">
    99 </p>
   100 <div id="content" style="display: none">
   101 </div>
   102 <pre id="test">
   103 </pre>
   104 </body>
   106 </window>

mercurial