chromium/third_party/blink/web_tests/fast/events/mouseup-from-button2.html

<p>This test verifies that a right mousebutton click generates a mousedown, context and mouseup event.</p>

</p>
<p>If the test passes, you'll see a PASS message below.
</p>

<p>To run this test in Safari:
<ol>
    <li>Right mouse down inside the box.</li>
    <li>Right mouse up.</li>
</ol>
</p>
<hr>
<style id="mystyle">
  .test-box {
    border: solid;
  }
</style>
<div class="test-box" id="click_target-1">box</div>
<pre id="log"></pre>

<script id="cody">

/**
 * Base namespace for test
 */
var rlightclickbug = rlightclickbug || {}; 

/**
 * Swallows an event.
 */
rlightclickbug.swallow = function(event) {
  event.preventDefault && event.preventDefault();
  event.stopImmediatePropagation && event.stopImmediatePropagation();
  event.stopPropagation && event.stopPropagation();
  event.preventBubble && event.preventBubble();
  return false;
};

/**
 * Dumps out a single line summary of a mouse event
 */
rlightclickbug.dumpShortEvent = function(event) {
  var values = []
  var keys = ['type', 'button'];
  for (var i = 0; i < keys.length; i++) {
    values.push(keys[i]);
    values.push(': ');
    values.push(event[keys[i]]);
    values.push(', ');
  }
  return values.join('');
};

/**
 * Writes a log message to the screen.
 */
rlightclickbug.logme = function(m) {
  var loggy = document.getElementById('log');
  loggy.innerHTML += ('\n' + m);
};

var _captureMouseEvents = function(event) {
  rlightclickbug.logme(rlightclickbug.dumpShortEvent(event));
  return rlightclickbug.swallow(event);
};


function main()
{
  var targetBox = document.getElementById('click_target-1');
  
  targetBox.addEventListener("mouseup", _captureMouseEvents, false);
  targetBox.addEventListener("mousedown", _captureMouseEvents, false);
  targetBox.addEventListener("click", _captureMouseEvents, false);
  targetBox.addEventListener("contextmenu", _captureMouseEvents, false);
    
  if (window.testRunner)
      testRunner.dumpAsText();
      
  if (window.eventSender) {
      // Confirm that left button works properly     
      eventSender.mouseMoveTo(targetBox.offsetLeft + 5,
          targetBox.offsetTop + 5); // in box
      eventSender.mouseDown();
      eventSender.mouseUp();
      
      // Confirm that right button works properly
      eventSender.mouseDown(2);
      eventSender.mouseUp(2);
      
      // Confirm that moving mouse while down outside of box 
      // does not fire a mouseup event.
      eventSender.mouseDown(2);
      eventSender.mouseMoveTo(0, 0); // outside of box
      eventSender.mouseUp(2);

      // order in IE is mousedown contextmenu mouseup
  }
}


main();
</script>