| <!DOCTYPE HTML> |
| <html> |
| <head> |
| <script src="../../resources/js-test.js"></script> |
| </head> |
| <body> |
| <p id="description"></p> |
| <div id="console"></div> |
| <script> |
| description("Test the parsing of the cursor property."); |
| |
| function makeCursorRule(rule) |
| { |
| return 'cursor: ' + rule + ';'; |
| } |
| |
| function testCursorRule(rule) |
| { |
| var cssText = makeCursorRule(rule); |
| shouldBeEqualToString('roundtripCssRule(`' + cssText + '`)', cssText); |
| } |
| |
| function testInvalidCursorRule(rule) |
| { |
| shouldBeEqualToString('roundtripCssRule(`' + makeCursorRule(rule) + '`)', ''); |
| } |
| |
| function roundtripCssRule(cssText) |
| { |
| var div = document.createElement("div"); |
| div.setAttribute("style", cssText); |
| document.body.appendChild(div); |
| var result = div.style.cssText; |
| document.body.removeChild(div); |
| return result; |
| } |
| |
| // Note that any absolute URL will suffice for these tests (can't use relative URLs |
| // since they'll be converted to absolute form in the output). I chose file URLs just |
| // to avoid triggering any network activity. |
| |
| debug('Test a bunch of cursor rules which should round-trip exactly.'); |
| testCursorRule('auto'); |
| testCursorRule('none'); |
| testCursorRule('copy'); |
| testCursorRule('zoom-in'); |
| testCursorRule('zoom-out'); |
| testCursorRule('grab'); |
| testCursorRule('grabbing'); |
| testCursorRule('-webkit-grab'); |
| testCursorRule('-webkit-grabbing'); |
| testCursorRule('-webkit-zoom-in'); |
| testCursorRule('-webkit-zoom-out'); |
| testCursorRule('url("file:///foo.png"), crosshair'); |
| testCursorRule('url("file:///foo.png"), url("file:///foo2.png"), pointer'); |
| testCursorRule('url("file:///foo.png") 12 3, pointer'); |
| testCursorRule('url("file:///foo.png") 0 0, pointer', 'url("file:///foo.png") 0 0, pointer'); |
| testCursorRule('url("file:///foo.png") 12 3, url("file:///foo2.png"), url("file:///foo3.png") 6 7, crosshair'); |
| testCursorRule('url("file:///foo.png") -2 3, pointer'); |
| testCursorRule('url("file:///foo.png") 2 -3, pointer'); |
| testCursorRule('url("file:///foo.png") -1 -1, pointer'); |
| |
| debug(''); |
| debug('Test a bunch of invalid cursor rules which shouldn\'t parse at all.'); |
| testInvalidCursorRule('nonexistent'); |
| testInvalidCursorRule('ltr'); |
| testInvalidCursorRule('inline'); |
| testInvalidCursorRule('hand'); |
| testInvalidCursorRule('url("file:///foo.png")'); |
| testInvalidCursorRule('url("file:///foo.png"),'); |
| testInvalidCursorRule('url("file:///foo.png"), url("file:///foo2.png")'); |
| testInvalidCursorRule('url("file:///foo.png") 12'); |
| testInvalidCursorRule('url("file:///foo.png") 12 3 5'); |
| testInvalidCursorRule('url("file:///foo.png") x y'); |
| testInvalidCursorRule('url("file:///foo.png") auto'); |
| testInvalidCursorRule('url("file:///foo.png") hand'); |
| |
| successfullyParsed = true; |
| </script> |
| </body> |
| </html> |