cursor_test.js 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. // Copyright 2009 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. goog.provide('goog.style.cursorTest');
  15. goog.setTestOnly('goog.style.cursorTest');
  16. goog.require('goog.style.cursor');
  17. goog.require('goog.testing.jsunit');
  18. goog.require('goog.userAgent');
  19. var baseCursorUrl = '/images/2/';
  20. var origWindowsUserAgentValue;
  21. var origGeckoUserAgentValue;
  22. var origWebkitUserAgentValue;
  23. function setUp() {
  24. origWindowsUserAgentValue = goog.userAgent.WINDOWS;
  25. origGeckoUserAgentValue = goog.userAgent.GECKO;
  26. origWebkitUserAgentValue = goog.userAgent.WEBKIT;
  27. }
  28. function tearDown() {
  29. goog.userAgent.WINDOWS = origWindowsUserAgentValue;
  30. goog.userAgent.GECKO = origGeckoUserAgentValue;
  31. goog.userAgent.WEBKIT = origWebkitUserAgentValue;
  32. }
  33. function testGetCursorStylesWebkit() {
  34. goog.userAgent.GECKO = false;
  35. goog.userAgent.WEBKIT = true;
  36. assertEquals(
  37. 'Webkit should get a cursor style with moved hot-spot.',
  38. 'url("/images/2/openhand.cur") 7 5, default',
  39. goog.style.cursor.getDraggableCursorStyle(baseCursorUrl));
  40. assertEquals(
  41. 'Webkit should get a cursor style with moved hot-spot.',
  42. 'url("/images/2/openhand.cur") 7 5, default',
  43. goog.style.cursor.getDraggableCursorStyle(baseCursorUrl, true));
  44. assertEquals(
  45. 'Webkit should get a cursor style with moved hot-spot.',
  46. 'url("/images/2/closedhand.cur") 7 5, move',
  47. goog.style.cursor.getDraggingCursorStyle(baseCursorUrl));
  48. assertEquals(
  49. 'Webkit should get a cursor style with moved hot-spot.',
  50. 'url("/images/2/closedhand.cur") 7 5, move',
  51. goog.style.cursor.getDraggingCursorStyle(baseCursorUrl, true));
  52. }
  53. function testGetCursorStylesFireFoxNonWin() {
  54. goog.userAgent.GECKO = true;
  55. goog.userAgent.WEBKIT = false;
  56. goog.userAgent.WINDOWS = false;
  57. assertEquals(
  58. 'FireFox on non Windows should get a custom cursor style.', '-moz-grab',
  59. goog.style.cursor.getDraggableCursorStyle(baseCursorUrl));
  60. assertEquals(
  61. 'FireFox on non Windows should get a custom cursor style and ' +
  62. 'no !important modifier.',
  63. '-moz-grab',
  64. goog.style.cursor.getDraggableCursorStyle(baseCursorUrl, true));
  65. assertEquals(
  66. 'FireFox on non Windows should get a custom cursor style.',
  67. '-moz-grabbing', goog.style.cursor.getDraggingCursorStyle(baseCursorUrl));
  68. assertEquals(
  69. 'FireFox on non Windows should get a custom cursor style and ' +
  70. 'no !important modifier.',
  71. '-moz-grabbing',
  72. goog.style.cursor.getDraggingCursorStyle(baseCursorUrl, true));
  73. }
  74. function testGetCursorStylesFireFoxWin() {
  75. goog.userAgent.GECKO = true;
  76. goog.userAgent.WEBKIT = false;
  77. goog.userAgent.WINDOWS = true;
  78. assertEquals(
  79. 'FireFox should get a cursor style with URL.',
  80. 'url("/images/2/openhand.cur"), default',
  81. goog.style.cursor.getDraggableCursorStyle(baseCursorUrl));
  82. assertEquals(
  83. 'FireFox should get a cursor style with URL and no !important' +
  84. ' modifier.',
  85. 'url("/images/2/openhand.cur"), default',
  86. goog.style.cursor.getDraggableCursorStyle(baseCursorUrl, true));
  87. assertEquals(
  88. 'FireFox should get a cursor style with URL.',
  89. 'url("/images/2/closedhand.cur"), move',
  90. goog.style.cursor.getDraggingCursorStyle(baseCursorUrl));
  91. assertEquals(
  92. 'FireFox should get a cursor style with URL and no !important' +
  93. ' modifier.',
  94. 'url("/images/2/closedhand.cur"), move',
  95. goog.style.cursor.getDraggingCursorStyle(baseCursorUrl, true));
  96. }
  97. function testGetCursorStylesOther() {
  98. goog.userAgent.GECKO = false;
  99. goog.userAgent.WEBKIT = false;
  100. assertEquals(
  101. 'Other browsers (IE) should get a cursor style with URL.',
  102. 'url("/images/2/openhand.cur"), default',
  103. goog.style.cursor.getDraggableCursorStyle(baseCursorUrl));
  104. assertEquals(
  105. 'Other browsers (IE) should get a cursor style with URL.',
  106. 'url("/images/2/openhand.cur"), default',
  107. goog.style.cursor.getDraggableCursorStyle(baseCursorUrl, true));
  108. assertEquals(
  109. 'Other browsers (IE) should get a cursor style with URL.',
  110. 'url("/images/2/closedhand.cur"), move',
  111. goog.style.cursor.getDraggingCursorStyle(baseCursorUrl));
  112. assertEquals(
  113. 'Other browsers (IE) should get a cursor style with URL.',
  114. 'url("/images/2/closedhand.cur"), move',
  115. goog.style.cursor.getDraggingCursorStyle(baseCursorUrl, true));
  116. }