Commit 619bcca4 authored by antti@apple.com's avatar antti@apple.com
Browse files

https://bugs.webkit.org/show_bug.cgi?id=31223

Make primitive values immutable.
        
Patch by Antti Koivisto <koivisto@iki.fi> on 2010-11-16
Reviewed by Adam Barth.

Update test cases for behavior change and test computed style too. Note that there are some
failures in the results demonstrating unrelated bugs in CSSPrimitiveValues.

* fast/dom/script-tests/setPrimitiveValue-exceptions.js:
(checkThrows):
* fast/dom/setPrimitiveValue.html:
* fast/dom/setPrimitiveValue-exceptions-expected.txt
* fast/dom/setPrimitiveValue-expected.txt



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@72166 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent c8f310c0
2010-11-16 Antti Koivisto <koivisto@iki.fi>
Reviewed by Adam Barth.
https://bugs.webkit.org/show_bug.cgi?id=31223
Make primitive values immutable.
Update test cases for behavior change and test computed style too. Note that there are some
failures in the results demonstrating unrelated bugs in CSSPrimitiveValues.
* fast/dom/script-tests/setPrimitiveValue-exceptions.js:
(checkThrows):
* fast/dom/setPrimitiveValue.html:
* fast/dom/setPrimitiveValue-exceptions-expected.txt
* fast/dom/setPrimitiveValue-expected.txt
2010-11-16 Mihai Parparita <mihaip@chromium.org>
 
Update the pixel expectations for fast/reflections, fast/replaced, fast/ruby, fast/runin, and fast/text for the Mac port.
description("This test ensures that setting primitive values to an inappropriate unit type will throw an exception.");
description("Test exceptions thrown by the CSSPrimitiveValue APIs. Primitive values are currently immutable (see https://bugs.webkit.org/show_bug.cgi?id=31223)");
var element = document.createElement('div');
element.id = "test-element"
document.documentElement.appendChild(element);
var styleElement = document.createElement('style');
styleElement.innerText = "#test-element { left: 10px; font-family: Times; }";
styleElement.innerText = "#test-element { position: absolute; left: 10px; font-family: Times; }";
document.documentElement.appendChild(styleElement);
var style = styleElement.sheet.cssRules[0].style;
var left = style.getPropertyCSSValue("left");
left.setFloatValue(CSSPrimitiveValue.CSS_NUMBER, 25);
shouldBe("left.getFloatValue(CSSPrimitiveValue.CSS_NUMBER)", "25");
left.setFloatValue(CSSPrimitiveValue.CSS_DIMENSION, 25);
shouldBe("left.getFloatValue(CSSPrimitiveValue.CSS_DIMENSION)", "25");
// Work around <http://webkit.org/b/31223> / <rdar://problem/7374538>.
left.setFloatValue(CSSPrimitiveValue.CSS_PX, 10);
shouldThrow("left.setFloatValue(CSSPrimitiveValue.CSS_UNKNOWN, 25)");
shouldThrow("left.setFloatValue(CSSPrimitiveValue.CSS_STRING, 25)");
shouldThrow("left.getFloatValue(CSSPrimitiveValue.CSS_UNKNOWN)");
shouldThrow("left.getFloatValue(CSSPrimitiveValue.CSS_STRING)");
function checkThrows(style) {
left = style.getPropertyCSSValue("left");
shouldBe("left.getFloatValue(CSSPrimitiveValue.CSS_NUMBER)", "10");
shouldBe("left.getFloatValue(CSSPrimitiveValue.CSS_DIMENSION)", "10");
shouldBe("left.getFloatValue(CSSPrimitiveValue.CSS_PX)", "10");
shouldThrow("left.setFloatValue(CSSPrimitiveValue.CSS_NUMBER, 25)");
shouldThrow("left.setFloatValue(CSSPrimitiveValue.CSS_DIMENSION, 25)");
shouldThrow("left.setFloatValue(CSSPrimitiveValue.CSS_PX, 25)");
shouldThrow("left.setFloatValue(CSSPrimitiveValue.CSS_UNKNOWN, 25)");
shouldThrow("left.setFloatValue(CSSPrimitiveValue.CSS_STRING, 25)");
shouldThrow("left.getFloatValue(CSSPrimitiveValue.CSS_UNKNOWN)");
shouldThrow("left.getFloatValue(CSSPrimitiveValue.CSS_STRING)");
shouldThrow("left.getStringValue()");
shouldThrow("left.getCounterValue()");
shouldThrow("left.getRectValue()");
shouldThrow("left.getRGBColorValue()");
shouldBe("left.getFloatValue(CSSPrimitiveValue.CSS_NUMBER)", "10");
shouldBe("left.getFloatValue(CSSPrimitiveValue.CSS_DIMENSION)", "10");
shouldBe("left.getFloatValue(CSSPrimitiveValue.CSS_PX)", "10");
fontFamily = style.getPropertyCSSValue("font-family")[0];
shouldBe("fontFamily.getStringValue()", '"Times"');
shouldThrow("fontFamily.setStringValue(CSSPrimitiveValue.CSS_STRING, 'Hi there!')");
shouldThrow("fontFamily.setStringValue(CSSPrimitiveValue.CSS_ATTR, \"G'day!\")");
shouldThrow("fontFamily.setStringValue(CSSPrimitiveValue.CSS_UNKNOWN, 'Hi there!')");
shouldThrow("fontFamily.setStringValue(CSSPrimitiveValue.CSS_DIMENSION, \"G'day!\")");
shouldThrow("fontFamily.setStringValue(CSSPrimitiveValue.CSS_COUNTER, 'Hello, world!')");
shouldThrow("fontFamily.getFloatValue()");
shouldThrow("fontFamily.getCounterValue()");
shouldThrow("fontFamily.getRectValue()");
shouldThrow("fontFamily.getRGBColorValue()");
shouldBe("fontFamily.getStringValue()", '"Times"');
}
shouldThrow("left.getStringValue()");
shouldThrow("left.getCounterValue()");
shouldThrow("left.getRectValue()");
shouldThrow("left.getRGBColorValue()");
var fontFamily = style.getPropertyCSSValue("font-family")[0];
fontFamily.setStringValue(CSSPrimitiveValue.CSS_STRING, "Hi there!");
shouldBe("fontFamily.getStringValue()", '"Hi there!"');
fontFamily.setStringValue(CSSPrimitiveValue.CSS_ATTR, "G'day!");
shouldBe("fontFamily.getStringValue()", '"G\'day!"');
shouldThrow("fontFamily.setStringValue(CSSPrimitiveValue.CSS_UNKNOWN, 'Hi there!')");
shouldThrow("fontFamily.setStringValue(CSSPrimitiveValue.CSS_DIMENSION, \"G'day!\")");
shouldThrow("fontFamily.setStringValue(CSSPrimitiveValue.CSS_COUNTER, 'Hello, world!')");
var style = styleElement.sheet.cssRules[0].style;
checkThrows(style);
shouldThrow("fontFamily.getFloatValue()");
shouldThrow("fontFamily.getCounterValue()");
shouldThrow("fontFamily.getRectValue()");
shouldThrow("fontFamily.getRGBColorValue()");
var computedStyle = window.getComputedStyle(element, null);
checkThrows(computedStyle);
successfullyParsed = true;
This test ensures that setting primitive values to an inappropriate unit type will throw an exception.
Test exceptions thrown by the CSSPrimitiveValue APIs. Primitive values are currently immutable (see https://bugs.webkit.org/show_bug.cgi?id=31223)
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
PASS left.getFloatValue(CSSPrimitiveValue.CSS_NUMBER) is 25
PASS left.getFloatValue(CSSPrimitiveValue.CSS_DIMENSION) is 25
PASS left.setFloatValue(CSSPrimitiveValue.CSS_UNKNOWN, 25) threw exception Error: INVALID_ACCESS_ERR: DOM Exception 15.
PASS left.setFloatValue(CSSPrimitiveValue.CSS_STRING, 25) threw exception Error: INVALID_ACCESS_ERR: DOM Exception 15.
PASS left.getFloatValue(CSSPrimitiveValue.CSS_NUMBER) is 10
PASS left.getFloatValue(CSSPrimitiveValue.CSS_DIMENSION) is 10
PASS left.getFloatValue(CSSPrimitiveValue.CSS_PX) is 10
PASS left.setFloatValue(CSSPrimitiveValue.CSS_NUMBER, 25) threw exception Error: NO_MODIFICATION_ALLOWED_ERR: DOM Exception 7.
PASS left.setFloatValue(CSSPrimitiveValue.CSS_DIMENSION, 25) threw exception Error: NO_MODIFICATION_ALLOWED_ERR: DOM Exception 7.
PASS left.setFloatValue(CSSPrimitiveValue.CSS_PX, 25) threw exception Error: NO_MODIFICATION_ALLOWED_ERR: DOM Exception 7.
PASS left.setFloatValue(CSSPrimitiveValue.CSS_UNKNOWN, 25) threw exception Error: NO_MODIFICATION_ALLOWED_ERR: DOM Exception 7.
PASS left.setFloatValue(CSSPrimitiveValue.CSS_STRING, 25) threw exception Error: NO_MODIFICATION_ALLOWED_ERR: DOM Exception 7.
PASS left.getFloatValue(CSSPrimitiveValue.CSS_UNKNOWN) threw exception Error: INVALID_ACCESS_ERR: DOM Exception 15.
PASS left.getFloatValue(CSSPrimitiveValue.CSS_STRING) threw exception Error: INVALID_ACCESS_ERR: DOM Exception 15.
PASS left.getStringValue() threw exception Error: INVALID_ACCESS_ERR: DOM Exception 15.
PASS left.getCounterValue() threw exception Error: INVALID_ACCESS_ERR: DOM Exception 15.
PASS left.getRectValue() threw exception Error: INVALID_ACCESS_ERR: DOM Exception 15.
PASS left.getRGBColorValue() threw exception Error: INVALID_ACCESS_ERR: DOM Exception 15.
PASS fontFamily.getStringValue() is "Hi there!"
PASS fontFamily.getStringValue() is "G'day!"
PASS fontFamily.setStringValue(CSSPrimitiveValue.CSS_UNKNOWN, 'Hi there!') threw exception Error: INVALID_ACCESS_ERR: DOM Exception 15.
PASS fontFamily.setStringValue(CSSPrimitiveValue.CSS_DIMENSION, "G'day!") threw exception Error: INVALID_ACCESS_ERR: DOM Exception 15.
PASS fontFamily.setStringValue(CSSPrimitiveValue.CSS_COUNTER, 'Hello, world!') threw exception Error: INVALID_ACCESS_ERR: DOM Exception 15.
PASS left.getFloatValue(CSSPrimitiveValue.CSS_NUMBER) is 10
PASS left.getFloatValue(CSSPrimitiveValue.CSS_DIMENSION) is 10
PASS left.getFloatValue(CSSPrimitiveValue.CSS_PX) is 10
FAIL fontFamily.getStringValue() should be Times. Was .
PASS fontFamily.setStringValue(CSSPrimitiveValue.CSS_STRING, 'Hi there!') threw exception Error: NO_MODIFICATION_ALLOWED_ERR: DOM Exception 7.
PASS fontFamily.setStringValue(CSSPrimitiveValue.CSS_ATTR, "G'day!") threw exception Error: NO_MODIFICATION_ALLOWED_ERR: DOM Exception 7.
PASS fontFamily.setStringValue(CSSPrimitiveValue.CSS_UNKNOWN, 'Hi there!') threw exception Error: NO_MODIFICATION_ALLOWED_ERR: DOM Exception 7.
PASS fontFamily.setStringValue(CSSPrimitiveValue.CSS_DIMENSION, "G'day!") threw exception Error: NO_MODIFICATION_ALLOWED_ERR: DOM Exception 7.
PASS fontFamily.setStringValue(CSSPrimitiveValue.CSS_COUNTER, 'Hello, world!') threw exception Error: NO_MODIFICATION_ALLOWED_ERR: DOM Exception 7.
PASS fontFamily.getFloatValue() threw exception Error: INVALID_ACCESS_ERR: DOM Exception 15.
PASS fontFamily.getCounterValue() threw exception Error: INVALID_ACCESS_ERR: DOM Exception 15.
PASS fontFamily.getRectValue() threw exception Error: INVALID_ACCESS_ERR: DOM Exception 15.
PASS fontFamily.getRGBColorValue() threw exception Error: INVALID_ACCESS_ERR: DOM Exception 15.
FAIL fontFamily.getStringValue() should be Times. Was .
PASS left.getFloatValue(CSSPrimitiveValue.CSS_NUMBER) is 10
PASS left.getFloatValue(CSSPrimitiveValue.CSS_DIMENSION) is 10
PASS left.getFloatValue(CSSPrimitiveValue.CSS_PX) is 10
PASS left.setFloatValue(CSSPrimitiveValue.CSS_NUMBER, 25) threw exception Error: NO_MODIFICATION_ALLOWED_ERR: DOM Exception 7.
PASS left.setFloatValue(CSSPrimitiveValue.CSS_DIMENSION, 25) threw exception Error: NO_MODIFICATION_ALLOWED_ERR: DOM Exception 7.
PASS left.setFloatValue(CSSPrimitiveValue.CSS_PX, 25) threw exception Error: NO_MODIFICATION_ALLOWED_ERR: DOM Exception 7.
PASS left.setFloatValue(CSSPrimitiveValue.CSS_UNKNOWN, 25) threw exception Error: NO_MODIFICATION_ALLOWED_ERR: DOM Exception 7.
PASS left.setFloatValue(CSSPrimitiveValue.CSS_STRING, 25) threw exception Error: NO_MODIFICATION_ALLOWED_ERR: DOM Exception 7.
PASS left.getFloatValue(CSSPrimitiveValue.CSS_UNKNOWN) threw exception Error: INVALID_ACCESS_ERR: DOM Exception 15.
PASS left.getFloatValue(CSSPrimitiveValue.CSS_STRING) threw exception Error: INVALID_ACCESS_ERR: DOM Exception 15.
PASS left.getStringValue() threw exception Error: INVALID_ACCESS_ERR: DOM Exception 15.
PASS left.getCounterValue() threw exception Error: INVALID_ACCESS_ERR: DOM Exception 15.
PASS left.getRectValue() threw exception Error: INVALID_ACCESS_ERR: DOM Exception 15.
PASS left.getRGBColorValue() threw exception Error: INVALID_ACCESS_ERR: DOM Exception 15.
PASS left.getFloatValue(CSSPrimitiveValue.CSS_NUMBER) is 10
PASS left.getFloatValue(CSSPrimitiveValue.CSS_DIMENSION) is 10
PASS left.getFloatValue(CSSPrimitiveValue.CSS_PX) is 10
FAIL fontFamily.getStringValue() should be Times. Threw exception TypeError: 'undefined' is not an object (evaluating 'fontFamily.getStringValue')
PASS fontFamily.setStringValue(CSSPrimitiveValue.CSS_STRING, 'Hi there!') threw exception TypeError: 'undefined' is not an object (evaluating 'fontFamily.setStringValue').
PASS fontFamily.setStringValue(CSSPrimitiveValue.CSS_ATTR, "G'day!") threw exception TypeError: 'undefined' is not an object (evaluating 'fontFamily.setStringValue').
PASS fontFamily.setStringValue(CSSPrimitiveValue.CSS_UNKNOWN, 'Hi there!') threw exception TypeError: 'undefined' is not an object (evaluating 'fontFamily.setStringValue').
PASS fontFamily.setStringValue(CSSPrimitiveValue.CSS_DIMENSION, "G'day!") threw exception TypeError: 'undefined' is not an object (evaluating 'fontFamily.setStringValue').
PASS fontFamily.setStringValue(CSSPrimitiveValue.CSS_COUNTER, 'Hello, world!') threw exception TypeError: 'undefined' is not an object (evaluating 'fontFamily.setStringValue').
PASS fontFamily.getFloatValue() threw exception TypeError: 'undefined' is not an object (evaluating 'fontFamily.getFloatValue').
PASS fontFamily.getCounterValue() threw exception TypeError: 'undefined' is not an object (evaluating 'fontFamily.getCounterValue').
PASS fontFamily.getRectValue() threw exception TypeError: 'undefined' is not an object (evaluating 'fontFamily.getRectValue').
PASS fontFamily.getRGBColorValue() threw exception TypeError: 'undefined' is not an object (evaluating 'fontFamily.getRGBColorValue').
FAIL fontFamily.getStringValue() should be Times. Threw exception TypeError: 'undefined' is not an object (evaluating 'fontFamily.getStringValue')
PASS successfullyParsed is true
TEST COMPLETE
......
......@@ -5,45 +5,54 @@ div.test {
position: absolute;
left: 250px;
top: 100px;
background-image: url(stars.gif);
background-image: url(stars.gif);
}
</style>
<script>
if (window.layoutTestController)
layoutTestController.dumpAsText();
function runTest()
{
var helloText = document.getElementById("hello");
var positionField = document.getElementById("style position");
var position = 50.0;
var textRule = document.styleSheets[0].cssRules[0];
var s = textRule.style;
var leftValue = s.getPropertyCSSValue("left");
var bgImageValue = s.getPropertyCSSValue("background-image");
try
{
leftValue.setFloatValue(leftValue.primitiveType, parseFloat(position));
}
catch (e)
{
alert("setFloatValue " + e.message);
}
var helloText = document.getElementById("hello");
var positionField = document.getElementById("style position");
var position = 50.0;
var textRule = document.styleSheets[0].cssRules[0];
var s = textRule.style;
var leftValue = s.getPropertyCSSValue("left");
var bgImageValue = s.getPropertyCSSValue("background-image");
var console = document.getElementById("console");
try
{
leftValue.setFloatValue(leftValue.primitiveType, parseFloat(position));
}
catch (e)
{
var line = document.createElement("div");
line.innerText = "setFloatValue " + e.message;
console.appendChild(line);
}
try
{
bgImageValue.setStringValue(bgImageValue.primitiveType, "stripes.gif");
}
catch (e)
{
alert("setStringValue " + e.message);
}
try
{
bgImageValue.setStringValue(bgImageValue.primitiveType, "stripes.gif");
}
catch (e)
{
var line = document.createElement("div");
line.innerText = "setStringValue " + e.message;
console.appendChild(line);
}
}
</script>
</head>
<body onload="runTest();">
This test checks that a primitive CSS values can be set without generating an exception.
<div class="test" id="hello">Hello world</div>
Test CSSPrimitiveValue setters.
<div class="test" id="hello"></div>
<pre id="console"></pre>
</body>
</html>
......
layer at (0,0) size 800x600
RenderView at (0,0) size 800x600
layer at (0,0) size 800x600
RenderBlock {HTML} at (0,0) size 800x600
RenderBody {BODY} at (8,8) size 784x579
RenderBlock (anonymous) at (0,0) size 784x18
RenderText {#text} at (0,0) size 551x18
text run at (0,0) width 551: "This test checks that a primitive CSS values can be set without generating an exception."
RenderText {#text} at (0,0) size 0x0
RenderBlock {PRE} at (0,31) size 784x0
layer at (250,100) size 76x18
RenderBlock (positioned) {DIV} at (250,100) size 76x18
RenderText {#text} at (0,0) size 76x18
text run at (0,0) width 76: "Hello world"
Test CSSPrimitiveValue setters.
setFloatValue NO_MODIFICATION_ALLOWED_ERR: DOM Exception 7
setStringValue NO_MODIFICATION_ALLOWED_ERR: DOM Exception 7
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment