pointerevent_capture_mouse-manual.html 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. <!doctype html>
  2. <html>
  3. <head>
  4. <title>Set/Release capture</title>
  5. <meta name="viewport" content="width=device-width">
  6. <link rel="stylesheet" type="text/css" href="pointerevent_styles.css">
  7. <script src="/resources/testharness.js"></script>
  8. <!--script src="/resources/testharnessreport.js"></script-->
  9. <!-- Additional helper script for common checks across event types -->
  10. <script type="text/javascript" src="pointerevent_support.js"></script>
  11. <script type="text/javascript" src="mochitest_support_internal.js"></script>
  12. </head>
  13. <body>
  14. <!--
  15. <h1>Pointer Events capture test</h1>
  16. <h4>
  17. Test Description: This test checks if setCapture/releaseCapture functions works properly. Complete the following actions:
  18. <ol>
  19. <li> Move your mouse over the black rectangle. pointermove event should be logged in the black rectangle</li>
  20. <li> Move your mouse over the purple rectangle. pointerover event should be logged in the purple rectangle</li>
  21. <li> Press and hold left mouse button over "Set Capture" button. "gotpointercapture" should be logged in the black rectangle</li>
  22. <li> Move your mouse anywhere. pointermove should be logged in the black rectangle</li>
  23. <li> Move your mouse over the purple rectangle. Nothig should happen</li>
  24. <li> Move your mouse over the black rectangle. pointermove should be logged in the black rectangle</li>
  25. <li> Release left mouse button. "lostpointercapture" should be logged in the black rectangle</li>
  26. </ol>
  27. </h4>
  28. Test passes if the proper behaviour of the events is observed.
  29. -->
  30. <div id="target0"></div>
  31. <br>
  32. <div id="target1"></div>
  33. <br>
  34. <input type="button" id="btnCapture" value="Set Capture">
  35. <script type='text/javascript'>
  36. var isPointerCapture = false;
  37. var pointermoveNoCaptureGot0 = false;
  38. var pointermoveCaptureGot0 = false;
  39. var pointermoveNoCaptureGot1 = false;
  40. var ownEventForTheCapturedTargetGot = false;
  41. var count=0;
  42. var detected_pointertypes = {};
  43. add_completion_callback(showPointerTypes);
  44. var target0 = document.getElementById('target0');
  45. var target1 = document.getElementById('target1');
  46. var captureButton = document.getElementById('btnCapture');
  47. var test_gotpointercapture = async_test("gotpointercapture event received");
  48. var test_lostpointercapture = async_test("lostpointercapture event received");
  49. window.onload = function() {
  50. on_event(captureButton, 'pointerdown', function(e) {
  51. if(isPointerCapture == false) {
  52. isPointerCapture = true;
  53. sPointerCapture(e);
  54. }
  55. });
  56. on_event(target0, 'gotpointercapture', function(e) {
  57. test_gotpointercapture.done();
  58. log("gotpointercapture", target0);
  59. });
  60. on_event(target0, 'lostpointercapture', function(e) {
  61. test_lostpointercapture.done();
  62. isPointerCapture = false;
  63. log("lostpointercapture", target0);
  64. });
  65. run();
  66. }
  67. function run() {
  68. var test_pointermove0 = async_test("pointerover event for black rectangle received")
  69. var test_pointermove1 = async_test("pointerover event for purple rectangle received")
  70. on_event(target0, "pointermove", function (event) {
  71. detected_pointertypes[ event.pointerType ] = true;
  72. if(!pointermoveNoCaptureGot0) {
  73. test_pointermove0.done();
  74. log("pointermove", document.getElementById('target0'));
  75. pointermoveNoCaptureGot0 = true;
  76. }
  77. if(isPointerCapture) {
  78. if(!pointermoveCaptureGot0) {
  79. test(function() {
  80. assert_true(event.relatedTarget==null, "relatedTarget is null when the capture is set")
  81. }, "relatedTarget is null when the capture is set. relatedTarget is " + event.relatedTarget);
  82. test(function() {
  83. assert_true((event.clientX < target0.getBoundingClientRect().left)||
  84. (event.clientX > target0.getBoundingClientRect().right)||
  85. (event.clientY < target0.getBoundingClientRect().top)||
  86. (event.clientY > target0.getBoundingClientRect().bottom),
  87. "pointermove received for captured element while out of it")
  88. }, "pointermove received for captured element while out of it");
  89. log("pointermove", document.getElementById('target0'));
  90. pointermoveCaptureGot0 = true;
  91. }
  92. if((event.clientX > target0.getBoundingClientRect().left)&&
  93. (event.clientX < target0.getBoundingClientRect().right)&&
  94. (event.clientY > target0.getBoundingClientRect().top)&&
  95. (event.clientY < target0.getBoundingClientRect().bottom)&&
  96. !ownEventForTheCapturedTargetGot) {
  97. test(function() {
  98. assert_true(true, "pointermove received for captured element while inside of it");
  99. }, "pointermove received for captured element while inside of it");
  100. log("pointermove", document.getElementById('target0'));
  101. ownEventForTheCapturedTargetGot = true;
  102. }
  103. }
  104. });
  105. on_event(target1, "pointermove", function (event) {
  106. if(isPointerCapture == true) {
  107. test(function() {
  108. assert_unreached("pointermove shouldn't trigger for this target when capture is enabled");
  109. }, "pointermove shouldn't trigger for the purple rectangle while the black rectangle has capture");
  110. }
  111. if(!pointermoveNoCaptureGot1) {
  112. test_pointermove1.done();
  113. log("pointermove", document.getElementById('target1'));
  114. pointermoveNoCaptureGot1 = true;
  115. }
  116. });
  117. }
  118. </script>
  119. <h1>Pointer Events Capture Test</h1>
  120. <div id="complete-notice">
  121. <p>The following pointer types were detected: <span id="pointertype-log"></span>.</p>
  122. </div>
  123. <div id="log"></div>
  124. </body>
  125. </html>