touch_test.js 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. // Copyright 2013 The Closure Library Authors. All Rights Reserved.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS-IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. /**
  15. * @fileoverview Unit tests for goog.labs.events.touch.
  16. */
  17. goog.provide('goog.labs.events.touchTest');
  18. goog.require('goog.labs.events.touch');
  19. goog.require('goog.testing.jsunit');
  20. goog.setTestOnly('goog.labs.events.touchTest');
  21. function testMouseEvent() {
  22. var fakeTarget = {};
  23. var fakeMouseMove = {
  24. 'clientX': 1,
  25. 'clientY': 2,
  26. 'screenX': 3,
  27. 'screenY': 4,
  28. 'target': fakeTarget,
  29. 'type': 'mousemove'
  30. };
  31. var data = goog.labs.events.touch.getTouchData(fakeMouseMove);
  32. assertEquals(1, data.clientX);
  33. assertEquals(2, data.clientY);
  34. assertEquals(3, data.screenX);
  35. assertEquals(4, data.screenY);
  36. assertEquals(fakeTarget, data.target);
  37. }
  38. function testTouchEvent() {
  39. var fakeTarget = {};
  40. var fakeTouch = {
  41. 'clientX': 1,
  42. 'clientY': 2,
  43. 'screenX': 3,
  44. 'screenY': 4,
  45. 'target': fakeTarget
  46. };
  47. var fakeTouchStart = {
  48. 'targetTouches': [fakeTouch],
  49. 'target': fakeTarget,
  50. 'type': 'touchstart'
  51. };
  52. var data = goog.labs.events.touch.getTouchData(fakeTouchStart);
  53. assertEquals(1, data.clientX);
  54. assertEquals(2, data.clientY);
  55. assertEquals(3, data.screenX);
  56. assertEquals(4, data.screenY);
  57. assertEquals(fakeTarget, data.target);
  58. }
  59. function testTouchChangeEvent() {
  60. var fakeTarget = {};
  61. var fakeTouch = {
  62. 'clientX': 1,
  63. 'clientY': 2,
  64. 'screenX': 3,
  65. 'screenY': 4,
  66. 'target': fakeTarget
  67. };
  68. var fakeTouchStart =
  69. {'changedTouches': [fakeTouch], 'target': fakeTarget, 'type': 'touchend'};
  70. var data = goog.labs.events.touch.getTouchData(fakeTouchStart);
  71. assertEquals(1, data.clientX);
  72. assertEquals(2, data.clientY);
  73. assertEquals(3, data.screenX);
  74. assertEquals(4, data.screenY);
  75. assertEquals(fakeTarget, data.target);
  76. }