| <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN"> |
| <html> |
| <head> |
| <script src="../../resources/js-test-pre.js"></script> |
| </head> |
| <body> |
| <p id="description"></p> |
| <div id="console"></div> |
| <script> |
| description("Test the parsing of the -webkit-image-set function."); |
| |
| function jsWrapperClass(node) |
| { |
| if (!node) |
| return "[null]"; |
| var string = Object.prototype.toString.apply(node); |
| return string.substr(8, string.length - 9); |
| } |
| |
| function shouldBeType(expression, className, prototypeName, constructorName) |
| { |
| if (!prototypeName) |
| prototypeName = className + "Prototype"; |
| if (!constructorName) |
| constructorName = className + "Constructor"; |
| shouldBe("jsWrapperClass(" + expression + ")", "'" + className + "'"); |
| shouldBe("jsWrapperClass(" + expression + ".__proto__)", "'" + prototypeName + "'"); |
| shouldBe("jsWrapperClass(" + expression + ".constructor)", "'Function'"); |
| } |
| |
| // These have to be global for the test helpers to see them. |
| var imageSetRule, subRule; |
| |
| function testImageSetRule(description, property, rule, expectedLength, expectedTexts) |
| { |
| debug(""); |
| debug(description + " : " + rule); |
| |
| var div = document.createElement("div"); |
| div.setAttribute("style", property + ": -webkit-image-set(" + rule + ")"); |
| document.body.appendChild(div); |
| |
| imageSetRule = div.style.getPropertyCSSValue(property); |
| shouldBeType("imageSetRule", "CSSValueList"); |
| |
| if (imageSetRule) { |
| if (jsWrapperClass(imageSetRule[0]) == "CSSValueList") { |
| // The content property returns a CSSValueList anyway, so to get to the |
| // imageSet CSS value list, we have to look at the first entry in the |
| // content value list. |
| imageSetRule = imageSetRule[0]; |
| } |
| } |
| |
| shouldBe("imageSetRule.length", function() { return expectedLength; }); |
| |
| if (imageSetRule) { |
| for (var i = 0; i < expectedLength; i++) { |
| string = imageSetRule[i]; |
| if (i % 2 == 0) { |
| subRule = string.cssText.split('#')[1].replace('"', ""); |
| subRule = subRule.split(')')[0]; |
| shouldBe("subRule", "'" + expectedTexts[i] + "'"); |
| } else { |
| subRule = string; |
| shouldBe("subRule.cssText", "'" + expectedTexts[i] + "'"); |
| } |
| } |
| } |
| |
| document.body.removeChild(div); |
| } |
| |
| testImageSetRule("Single value for background-image", |
| "background-image", |
| "url('#a') 1x", 2, |
| ["a", "1"]); |
| |
| testImageSetRule("Multiple values for background-image", |
| "background-image", |
| "url('#a') 1x, url('#b') 2x", 4, |
| ["a", "1", "b", "2"]); |
| |
| testImageSetRule("Multiple values for background-image, out of order", |
| "background-image", |
| "url('#c') 3x, url('#b') 2x, url('#a') 1x", 6, |
| ["c", "3", "b", "2", "a", "1"]); |
| |
| testImageSetRule("Single value for content", |
| "content", |
| "url('#a') 1x", 2, |
| ["a", "1"]); |
| |
| testImageSetRule("Multiple values for content", |
| "content", |
| "url('#a') 1x, url('#b') 2x", 4, |
| ["a", "1", "b", "2"]); |
| |
| testImageSetRule("Single value for border-image", |
| "-webkit-border-image", |
| "url('#a') 1x", 2, |
| ["a", "1"]); |
| |
| testImageSetRule("Multiple values for border-image", |
| "-webkit-border-image", |
| "url('#a') 1x, url('#b') 2x", 4, |
| ["a", "1", "b", "2"]); |
| |
| testImageSetRule("Single value for -webkit-mask-box-image", |
| "-webkit-mask-box-image", |
| "url('#a') 1x", 2, |
| ["a", "1"]); |
| |
| testImageSetRule("Multiple values for -webkit-mask-box-image", |
| "-webkit-mask-box-image", |
| "url('#a') 1x, url('#b') 2x", 4, |
| ["a", "1", "b", "2"]); |
| |
| successfullyParsed = true; |
| </script> |
| <script src="../../resources/js-test-post.js"></script> |
| </body> |
| </html> |