Skip to content

Commit

Permalink
Make fast/canvas/canvas-strokePath-shadow.html allow for pixel tolerance
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=79488

Patch by Elliot Poger <epoger@google.com> on 2012-02-24
Reviewed by Adam Barth.

* fast/canvas/script-tests/canvas-strokePath-shadow.js:
(shouldBeAlmost):
* fast/js/resources/js-test-pre.js:
(shouldBeCloseTo):

Canonical link: https://commits.webkit.org/96609@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@108835 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
Elliot Poger authored and webkit-commit-queue committed Feb 24, 2012
1 parent 7f413fd commit caf6cc3
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 64 deletions.
12 changes: 12 additions & 0 deletions LayoutTests/ChangeLog
@@ -1,3 +1,15 @@
2012-02-24 Elliot Poger <epoger@google.com>

Make fast/canvas/canvas-strokePath-shadow.html allow for pixel tolerance
https://bugs.webkit.org/show_bug.cgi?id=79488

Reviewed by Adam Barth.

* fast/canvas/script-tests/canvas-strokePath-shadow.js:
(shouldBeAlmost):
* fast/js/resources/js-test-pre.js:
(shouldBeCloseTo):

2012-02-24 Tim Horton <timothy_horton@apple.com>

SVG should be supported in Dashboard compatibility mode
Expand Down
56 changes: 28 additions & 28 deletions LayoutTests/fast/canvas/canvas-strokePath-shadow-expected.txt
Expand Up @@ -3,34 +3,34 @@ Ensure correct behavior of canvas with path stroke shadow
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".


PASS data[0] is 255
PASS data[1] is 20
PASS data[2] is 0
PASS data[0] is 255
PASS data[1] is 20
PASS data[2] is 0
PASS data[0] is 255
PASS data[1] is 20
PASS data[2] is 0
PASS data[0] is 255
PASS data[1] is 20
PASS data[2] is 0
PASS data[0] is 255
PASS data[1] is 0
PASS data[2] is 0
PASS data[3] should not be 255 and it's not.
PASS data[0] is 255
PASS data[1] is 0
PASS data[2] is 0
PASS data[3] should not be 255 and it's not.
PASS data[0] is 255
PASS data[1] is 0
PASS data[2] is 0
PASS data[3] should not be 255 and it's not.
PASS data[0] is 255
PASS data[1] is 0
PASS data[2] is 0
PASS data[3] should not be 255 and it's not.
PASS data[0] is within 2 of 255
PASS data[1] is within 2 of 20
PASS data[2] is within 2 of 0
PASS data[0] is within 2 of 255
PASS data[1] is within 2 of 20
PASS data[2] is within 2 of 0
PASS data[0] is within 2 of 255
PASS data[1] is within 2 of 20
PASS data[2] is within 2 of 0
PASS data[0] is within 2 of 255
PASS data[1] is within 2 of 20
PASS data[2] is within 2 of 0
PASS data[0] is within 2 of 255
PASS data[1] is within 2 of 0
PASS data[2] is within 2 of 0
PASS data[3] is not 255
PASS data[0] is within 2 of 255
PASS data[1] is within 2 of 0
PASS data[2] is within 2 of 0
PASS data[3] is not 255
PASS data[0] is within 2 of 255
PASS data[1] is within 2 of 0
PASS data[2] is within 2 of 0
PASS data[3] is not 255
PASS data[0] is within 2 of 255
PASS data[1] is within 2 of 0
PASS data[2] is within 2 of 0
PASS data[3] is not 255
PASS successfullyParsed is true

TEST COMPLETE
Expand Down
63 changes: 27 additions & 36 deletions LayoutTests/fast/canvas/script-tests/canvas-strokePath-shadow.js
Expand Up @@ -10,19 +10,10 @@ function print(message, color)
document.getElementById("console").appendChild(paragraph);
}

function shouldNotBe(a, b)
// Level of tolerance we expect of most pixel comparisons in this test.
function shouldBeAlmost(_a, _b)
{
var evalA;
try {
evalA = eval(a);
} catch(e) {
evalA = e;
}

if (evalA != b)
print("PASS " + a + " should not be " + b + " and it's not.", "green")
else
print("FAIL " + a + " should not be " + b + " but it is.", "red");
shouldBeCloseTo(_a, _b, 2);
}

var canvas = document.createElement('canvas');
Expand Down Expand Up @@ -62,53 +53,53 @@ var imageData, data;
// Verify solid shadow.
imageData = ctx.getImageData(650, 300, 1, 1);
data = imageData.data;
shouldBe('data[0]', '255');
shouldBe('data[1]', '20');
shouldBe('data[2]', '0');
shouldBeAlmost('data[0]', 255);
shouldBeAlmost('data[1]', 20);
shouldBeAlmost('data[2]', 0);

imageData = ctx.getImageData(650, 50, 1, 1);
data = imageData.data;
shouldBe('data[0]', '255');
shouldBe('data[1]', '20');
shouldBe('data[2]', '0');
shouldBeAlmost('data[0]', 255);
shouldBeAlmost('data[1]', 20);
shouldBeAlmost('data[2]', 0);

imageData = ctx.getImageData(380, 30, 1, 1);
data = imageData.data;
shouldBe('data[0]', '255');
shouldBe('data[1]', '20');
shouldBe('data[2]', '0');
shouldBeAlmost('data[0]', 255);
shouldBeAlmost('data[1]', 20);
shouldBeAlmost('data[2]', 0);

imageData = ctx.getImageData(400, 40, 1, 1);
data = imageData.data;
shouldBe('data[0]', '255');
shouldBe('data[1]', '20');
shouldBe('data[2]', '0');
shouldBeAlmost('data[0]', 255);
shouldBeAlmost('data[1]', 20);
shouldBeAlmost('data[2]', 0);

// Verify blurry shadow.
imageData = ctx.getImageData(640, 640, 1, 1);
data = imageData.data;
shouldBe('data[0]', '255');
shouldBe('data[1]', '0');
shouldBe('data[2]', '0');
shouldBeAlmost('data[0]', 255);
shouldBeAlmost('data[1]', 0);
shouldBeAlmost('data[2]', 0);
shouldNotBe('data[3]', '255');

imageData = ctx.getImageData(650, 400, 1, 1);
data = imageData.data;
shouldBe('data[0]', '255');
shouldBe('data[1]', '0');
shouldBe('data[2]', '0');
shouldBeAlmost('data[0]', 255);
shouldBeAlmost('data[1]', 0);
shouldBeAlmost('data[2]', 0);
shouldNotBe('data[3]', '255');

imageData = ctx.getImageData(380, 380, 1, 1);
data = imageData.data;
shouldBe('data[0]', '255');
shouldBe('data[1]', '0');
shouldBe('data[2]', '0');
shouldBeAlmost('data[0]', 255);
shouldBeAlmost('data[1]', 0);
shouldBeAlmost('data[2]', 0);
shouldNotBe('data[3]', '255');

imageData = ctx.getImageData(350, 380, 1, 1);
data = imageData.data;
shouldBe('data[0]', '255');
shouldBe('data[1]', '0');
shouldBe('data[2]', '0');
shouldBeAlmost('data[0]', 255);
shouldBeAlmost('data[1]', 0);
shouldBeAlmost('data[2]', 0);
shouldNotBe('data[3]', '255');
39 changes: 39 additions & 0 deletions LayoutTests/fast/js/resources/js-test-pre.js
Expand Up @@ -187,6 +187,45 @@ function shouldBe(_a, _b, quiet)
testFailed(_a + " should be " + _bv + " (of type " + typeof _bv + "). Was " + _av + " (of type " + typeof _av + ").");
}

// Variant of shouldBe()--confirms that result of eval(_to_eval) is within
// numeric _tolerance of numeric _target.
function shouldBeCloseTo(_to_eval, _target, _tolerance, quiet)
{
if (typeof _to_eval != "string") {
testFailed("shouldBeCloseTo() requires string argument _to_eval. was type " + typeof _to_eval);
return;
}
if (typeof _target != "number") {
testFailed("shouldBeCloseTo() requires numeric argument _target. was type " + typeof _target);
return;
}
if (typeof _tolerance != "number") {
testFailed("shouldBeCloseTo() requires numeric argument _tolerance. was type " + typeof _tolerance);
return;
}

var _result;
try {
_result = eval(_to_eval);
} catch (e) {
testFailed(_to_eval + " should be within " + _tolerance + " of "
+ _target + ". Threw exception " + e);
return;
}

if (typeof(_result) != typeof(_target)) {
testFailed(_to_eval + " should be of type " + typeof _target
+ " but was of type " + typeof _result);
} else if (Math.abs(_result - _target) <= _tolerance) {
if (!quiet) {
testPassed(_to_eval + " is within " + _tolerance + " of " + _target);
}
} else {
testFailed(_to_eval + " should be within " + _tolerance + " of " + _target
+ ". Was " + _result + ".");
}
}

function shouldNotBe(_a, _b, quiet)
{
if (typeof _a != "string" || typeof _b != "string")
Expand Down

0 comments on commit caf6cc3

Please sign in to comment.