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