Upstream version 11.39.266.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / LayoutTests / fast / dom / script-tests / setPrimitiveValue-exceptions.js
1 description("Test exceptions thrown by the CSSPrimitiveValue APIs. Primitive values are currently immutable (see https://bugs.webkit.org/show_bug.cgi?id=31223)");
2
3 var element = document.createElement('div');
4 element.id = "test-element"
5 document.documentElement.appendChild(element);
6
7 var styleElement = document.createElement('style');
8 styleElement.innerText = "#test-element { position: absolute; left: 10px; font-family: Times; }";
9 document.documentElement.appendChild(styleElement);
10
11 function checkThrows(style) {
12     left = style.getPropertyCSSValue("left");
13
14     shouldBe("left.getFloatValue(CSSPrimitiveValue.CSS_NUMBER)", "10");
15     shouldBe("left.getFloatValue(CSSPrimitiveValue.CSS_DIMENSION)", "10");
16     shouldBe("left.getFloatValue(CSSPrimitiveValue.CSS_PX)", "10");
17
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)");
25
26     shouldThrow("left.getStringValue()");
27     shouldThrow("left.getCounterValue()");
28     shouldThrow("left.getRectValue()");
29     shouldThrow("left.getRGBColorValue()");
30
31     shouldBe("left.getFloatValue(CSSPrimitiveValue.CSS_NUMBER)", "10");
32     shouldBe("left.getFloatValue(CSSPrimitiveValue.CSS_DIMENSION)", "10");
33     shouldBe("left.getFloatValue(CSSPrimitiveValue.CSS_PX)", "10");
34
35     fontFamily = style.getPropertyCSSValue("font-family")[0];
36     
37     shouldBe("fontFamily.getStringValue()", '"Times"'); 
38
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!')");
44
45     shouldThrow("fontFamily.getFloatValue()");
46     shouldThrow("fontFamily.getCounterValue()");
47     shouldThrow("fontFamily.getRectValue()");
48     shouldThrow("fontFamily.getRGBColorValue()");
49     
50     shouldBe("fontFamily.getStringValue()", '"Times"');
51 }
52
53 var style = styleElement.sheet.cssRules[0].style;
54 checkThrows(style);
55
56 var computedStyle = window.getComputedStyle(element, null);
57 checkThrows(computedStyle);