1 description("Test exceptions thrown by the CSSPrimitiveValue APIs. Primitive values are currently immutable (see https://bugs.webkit.org/show_bug.cgi?id=31223)");
3 var element = document.createElement('div');
4 element.id = "test-element"
5 document.documentElement.appendChild(element);
7 var styleElement = document.createElement('style');
8 styleElement.innerText = "#test-element { position: absolute; left: 10px; font-family: Times; }";
9 document.documentElement.appendChild(styleElement);
11 function checkThrows(style) {
12 left = style.getPropertyCSSValue("left");
14 shouldBe("left.getFloatValue(CSSPrimitiveValue.CSS_NUMBER)", "10");
15 shouldBe("left.getFloatValue(CSSPrimitiveValue.CSS_DIMENSION)", "10");
16 shouldBe("left.getFloatValue(CSSPrimitiveValue.CSS_PX)", "10");
18 shouldThrow("left.setFloatValue(CSSPrimitiveValue.CSS_NUMBER, 25)");
19 shouldThrow("left.setFloatValue(CSSPrimitiveValue.CSS_DIMENSION, 25)");
20 shouldThrow("left.setFloatValue(CSSPrimitiveValue.CSS_PX, 25)");
21 shouldThrow("left.setFloatValue(CSSPrimitiveValue.CSS_UNKNOWN, 25)");
22 shouldThrow("left.setFloatValue(CSSPrimitiveValue.CSS_STRING, 25)");
23 shouldThrow("left.getFloatValue(CSSPrimitiveValue.CSS_UNKNOWN)");
24 shouldThrow("left.getFloatValue(CSSPrimitiveValue.CSS_STRING)");
26 shouldThrow("left.getStringValue()");
27 shouldThrow("left.getCounterValue()");
28 shouldThrow("left.getRectValue()");
29 shouldThrow("left.getRGBColorValue()");
31 shouldBe("left.getFloatValue(CSSPrimitiveValue.CSS_NUMBER)", "10");
32 shouldBe("left.getFloatValue(CSSPrimitiveValue.CSS_DIMENSION)", "10");
33 shouldBe("left.getFloatValue(CSSPrimitiveValue.CSS_PX)", "10");
35 fontFamily = style.getPropertyCSSValue("font-family")[0];
37 shouldBe("fontFamily.getStringValue()", '"Times"');
39 shouldThrow("fontFamily.setStringValue(CSSPrimitiveValue.CSS_STRING, 'Hi there!')");
40 shouldThrow("fontFamily.setStringValue(CSSPrimitiveValue.CSS_ATTR, \"G'day!\")");
41 shouldThrow("fontFamily.setStringValue(CSSPrimitiveValue.CSS_UNKNOWN, 'Hi there!')");
42 shouldThrow("fontFamily.setStringValue(CSSPrimitiveValue.CSS_DIMENSION, \"G'day!\")");
43 shouldThrow("fontFamily.setStringValue(CSSPrimitiveValue.CSS_COUNTER, 'Hello, world!')");
45 shouldThrow("fontFamily.getFloatValue()");
46 shouldThrow("fontFamily.getCounterValue()");
47 shouldThrow("fontFamily.getRectValue()");
48 shouldThrow("fontFamily.getRGBColorValue()");
50 shouldBe("fontFamily.getStringValue()", '"Times"');
53 var style = styleElement.sheet.cssRules[0].style;
56 var computedStyle = window.getComputedStyle(element, null);
57 checkThrows(computedStyle);