Skip to content

Commit

Permalink
Merge pull request #8 from w3c/master
Browse files Browse the repository at this point in the history
Catch up to base repo.
  • Loading branch information
engelke authored Aug 22, 2016
2 parents 8cb6e3b + 0ca1ea3 commit 20753a5
Show file tree
Hide file tree
Showing 1,747 changed files with 71,354 additions and 18,942 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<!DOCTYPE html>
<!-- DO NOT EDIT! This test has been generated by tools/gentest.py. -->
<title>Canvas test: 2d.text.draw.fill.maxWidth.NaN</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/common/canvas-tests.js"></script>
<link rel="stylesheet" href="/common/canvas-tests.css">
<body class="show_output">

<h1>2d.text.draw.fill.maxWidth.NaN</h1>
<p class="desc">fillText handles maxWidth correctly</p>


<p class="output">Actual output:</p>
<canvas id="c" class="output" width="100" height="50"><p class="fallback">FAIL (fallback content)</p></canvas>
<p class="output expectedtext">Expected output:<p><img src="/images/green-100x50.png" class="output expected" id="expected" alt="">
<ul id="d"></ul>
<script>
var t = async_test("fillText handles maxWidth correctly");
_addTest(function(canvas, ctx) {

ctx.fillStyle = '#0f0';
ctx.fillRect(0, 0, 100, 50);
ctx.fillStyle = '#f00';
ctx.font = '35px Arial, sans-serif';
ctx.fillText('fail fail fail fail fail', 5, 35, NaN);
_assertGreen(ctx, 100, 50);


});
</script>

Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ <h1>2d.gradient.interpolate.colouralpha</h1>
g.addColorStop(1, 'rgba(0,0,255, 1)');
ctx.fillStyle = g;
ctx.fillRect(0, 0, 100, 50);
_assertPixelApprox(canvas, 25,25, 191,191,63,63, "25,25", "191,191,63,63", 3);
_assertPixelApprox(canvas, 50,25, 127,127,127,127, "50,25", "127,127,127,127", 3);
_assertPixelApprox(canvas, 75,25, 63,63,191,191, "75,25", "63,63,191,191", 3);
_assertPixelApprox(canvas, 25,25, 190,190,65,65, "25,25", "190,190,65,65", 3);
_assertPixelApprox(canvas, 50,25, 126,126,128,128, "50,25", "126,126,128,128", 3);
_assertPixelApprox(canvas, 75,25, 62,62,192,192, "75,25", "62,62,192,192", 3);


});
Expand Down
162 changes: 118 additions & 44 deletions 2dcontext/image-smoothing/imagesmoothing.html
Original file line number Diff line number Diff line change
@@ -1,45 +1,119 @@
<!DOCTYPE html>
<html>
<head>
<title>CanvasRenderingContext2D imageSmoothingEnabled test</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<link rel="author" title="ShinHyunjin" href="mailto:jini7927@gmail.com">
<link rel="help" href="http://www.w3.org/html/wg/drafts/2dcontext/html5_canvas/#image-smoothing">
</head>
<body>
<div id="log"></div>
<canvas id="test_canvas_1"></canvas>
<canvas id="test_canvas_2"></canvas>
<canvas id="test_canvas_3"></canvas>

<script>
(function() {
test(function() {
var canvas = document.getElementById('test_canvas_1');
var ctx = canvas.getContext('2d');

assert_true(ctx.imageSmoothingEnabled);
}, "When the CanvasRenderingContext2D object is created, the attribute must be set to true.");

test(function() {
var canvas = document.getElementById('test_canvas_2');
var ctx = canvas.getContext('2d');

ctx.imageSmoothingEnabled = false;
assert_false(ctx.imageSmoothingEnabled);
}, "On getting the imageSmoothingEnabled attribute, the user agent must return the last value it was set to.");

test(function() {
var canvas = document.getElementById('test_canvas_3');
var ctx = canvas.getContext('2d');

ctx.imageSmoothingEnabled = false;
assert_equals(ctx.imageSmoothingEnabled, false);
}, "On setting the imageSmoothingEnabled attribute, it must be set to the new value.");
})();


</script>
</body>
</html>
<meta charset="utf-8">
<title>CanvasRenderingContext2D imageSmoothingEnabled test</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<link rel="help" href="https://html.spec.whatwg.org/multipage/scripting.html#image-smoothing">
<script>
function createTestImage() {
var image = document.createElement('canvas');
var imgctx = image.getContext('2d');
imgctx.fillStyle = "#F00";
imgctx.fillRect(0, 0, 2, 2);
imgctx.fillStyle = "#0F0";
imgctx.fillRect(0, 0, 1, 1);
return image;
}

test(function() {
var ctx = document.createElement('canvas').getContext('2d');
assert_true(ctx.imageSmoothingEnabled);
}, "When the canvas context is created, imageSmoothingEnabled must be set to true.");

test(function() {
var ctx = document.createElement('canvas').getContext('2d');
ctx.imageSmoothingEnabled = false;
assert_false(ctx.imageSmoothingEnabled);
}, "On getting imageSmoothingEnabled, the user agent must return the last value it was set to.");

test(function() {
var ctx = document.createElement('canvas').getContext('2d');
var image = createTestImage();
ctx.scale(10, 10);
ctx.drawImage(image, 0, 0);
var pixels = ctx.getImageData(9, 9, 1, 1).data;
assert_not_equals(pixels[0], 0);
assert_not_equals(pixels[1], 255);
}, "Test that image smoothing is actually on by default and just the attribute value.");

test(function() {
var ctx = document.createElement('canvas').getContext('2d');
ctx.imageSmoothingEnabled = true;
var image = createTestImage();
ctx.scale(10, 10);
ctx.drawImage(image, 0, 0);
var pixels = ctx.getImageData(9, 9, 1, 1).data;
assert_not_equals(pixels[0], 0);
assert_not_equals(pixels[1], 255);
}, "Test that image smoothing works when imageSmoothingEnabled is set to true");

test(function() {
var ctx = document.createElement('canvas').getContext('2d');
var image = createTestImage();
ctx.imageSmoothingEnabled = false;
ctx.scale(10, 10);
ctx.drawImage(image, 0, 0);
var pixels = ctx.getImageData(9, 9, 1, 1).data;
assert_array_equals(pixels, [0, 255, 0, 255]);
}, "Test that imageSmoothingEnabled = false (nearest-neighbor interpolation) works with drawImage().");

test(function() {
var ctx = document.createElement('canvas').getContext('2d');
var image = createTestImage();
ctx.imageSmoothingEnabled = false;
ctx.scale(10, 10);
ctx.fillStyle = ctx.createPattern(image, 'repeat');
ctx.fillRect(0, 0, 10, 10);
var pixels = ctx.getImageData(9, 9, 1, 1).data;
assert_array_equals(pixels, [0, 255, 0, 255]);
}, "Test that imageSmoothingEnabled = false (nearest-neighbor interpolation) works with fillRect and createPattern().");

test(function() {
var ctx = document.createElement('canvas').getContext('2d');
var image = createTestImage();
ctx.imageSmoothingEnabled = false;
ctx.fillStyle = ctx.createPattern(image, 'repeat');
ctx.scale(10, 10);
ctx.rect(0, 0, 10, 10);
ctx.fill();
var pixels = ctx.getImageData(9, 9, 1, 1).data;
assert_array_equals(pixels, [0, 255, 0, 255]);
}, "Test that imageSmoothingEnabled = false (nearest-neighbor interpolation) works with fill() and createPattern().");

test(function() {
var ctx = document.createElement('canvas').getContext('2d');
var image = createTestImage();
ctx.strokeStyle = ctx.createPattern(image, 'repeat');
ctx.lineWidth = 5;
ctx.imageSmoothingEnabled = false;
ctx.scale(10, 10);
ctx.beginPath();
ctx.moveTo(0, 0);
ctx.lineTo(10, 10);
ctx.stroke();
var pixels = ctx.getImageData(9, 9, 1, 1).data;
assert_array_equals(pixels, [0, 255, 0, 255]);
}, "Test that imageSmoothingEnabled = false (nearest-neighbor interpolation) works with stroke() and createPattern().");

test(function() {
var repaints = 5;
var ctx = document.createElement('canvas').getContext('2d');

function draw() {
ctx.clearRect(0, 0, 10, 10);
ctx.setTransform(1, 0, 0, 1, 0, 0);
var image = createTestImage();
ctx.imageSmoothingEnabled = false;
ctx.scale(10, 10);
ctx.drawImage(image, 0, 0);
var pixels = ctx.getImageData(9, 9, 1, 1).data;
assert_array_equals(pixels, [0, 255, 0, 255]);
}

while (repaints > 0) {
draw();
repaints = repaints - 1;
}

}, "Test that imageSmoothingEnabled = false (nearest-neighbor interpolation) still works after repaints.");
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<!DOCTYPE html>
<meta charset="utf-8">
<title>CanvasRenderingContext2D imageSmoothingEnabled save/restore test</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<link rel="help" href="https://html.spec.whatwg.org/multipage/scripting.html#image-smoothing">
<script>
function createTestImage() {
var image = document.createElement('canvas');
var imgctx = image.getContext('2d');
imgctx.fillStyle = "#F00";
imgctx.fillRect(0, 0, 2, 2);
imgctx.fillStyle = "#0F0";
imgctx.fillRect(0, 0, 1, 1);
return image;
}

test(function() {
var ctx = document.createElement('canvas').getContext('2d');
ctx.save();
ctx.imageSmoothingEnabled = false;
ctx.restore();
assert_equals(ctx.imageSmoothingEnabled, true);
}, "Test that restore() undoes any modifications to imageSmoothingEnabled.");

test(function() {
var ctx = document.createElement('canvas').getContext('2d');
ctx.imageSmoothingEnabled = false;
var old = ctx.imageSmoothingEnabled;
ctx.save();
assert_equals(ctx.imageSmoothingEnabled, old);
ctx.restore();
}, "Test that save() doesn't modify the values of imageSmoothingEnabled.");

test(function() {
var ctx = document.createElement('canvas').getContext('2d');
ctx.imageSmoothingEnabled = false;
ctx.save();
ctx.imageSmoothingEnabled = true;
ctx.restore();
var image = createTestImage();
ctx.scale(10, 10);
ctx.drawImage(image, 0, 0);
var pixels = ctx.getImageData(0, 0, 1, 1).data;
assert_array_equals(pixels, [0, 255, 0, 255]);
}, "Test that restoring actually changes smoothing and not just the attribute value.");
</script>
10 changes: 5 additions & 5 deletions 2dcontext/tools/gentest.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,18 +128,18 @@ def f(c, start, depth):
doctest.testmod()
sys.exit()

templates = yaml.load(open('templates.yaml').read())
name_mapping = yaml.load(open('name2dir.yaml').read())
templates = yaml.load(open('templates.yaml', "r").read())
name_mapping = yaml.load(open('name2dir.yaml', "r").read())

spec_assertions = []
for s in yaml.load(open('spec.yaml').read())['assertions']:
for s in yaml.load(open('spec.yaml', "r").read())['assertions']:
if 'meta' in s:
eval(compile(s['meta'], '<meta spec assertion>', 'exec'), {}, {'assertions':spec_assertions})
else:
spec_assertions.append(s)

tests = []
for t in sum([ yaml.load(open(f).read()) for f in ['tests.yaml', 'tests2d.yaml', 'tests2dtext.yaml']], []):
for t in sum([ yaml.load(open(f, "r").read()) for f in ['tests.yaml', 'tests2d.yaml', 'tests2dtext.yaml']], []):
if 'DISABLED' in t:
continue
if 'meta' in t:
Expand Down Expand Up @@ -543,7 +543,7 @@ def write_results():
if not os.path.exists('results.yaml'):
print "Can't find results.yaml"
else:
for resultset in yaml.load(open('results.yaml').read()):
for resultset in yaml.load(open('results.yaml', "r").read()):
#title = "%s (%s)" % (resultset['ua'], resultset['time'])
title = resultset['name']
#assert title not in uas # don't allow repetitions
Expand Down
2 changes: 1 addition & 1 deletion 2dcontext/tools/specextract.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

def extract():
parser = html5lib.html5parser.HTMLParser(tree=html5lib.treebuilders.dom.TreeBuilder)
doc = parser.parse(open('current-work'), encoding='utf-8')
doc = parser.parse(open('current-work', "r"), encoding='utf-8')

head = doc.getElementsByTagName('head')[0]
for n in head.childNodes:
Expand Down
6 changes: 3 additions & 3 deletions 2dcontext/tools/tests2d.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1668,9 +1668,9 @@
g.addColorStop(1, 'rgba(0,0,255, 1)');
ctx.fillStyle = g;
ctx.fillRect(0, 0, 100, 50);
@assert pixel 25,25 ==~ 191,191,63,63 +/- 3;
@assert pixel 50,25 ==~ 127,127,127,127 +/- 3;
@assert pixel 75,25 ==~ 63,63,191,191 +/- 3;
@assert pixel 25,25 ==~ 190,190,65,65 +/- 3;
@assert pixel 50,25 ==~ 126,126,128,128 +/- 3;
@assert pixel 75,25 ==~ 62,62,192,192 +/- 3;
expected: |
size 100 50
g = cairo.LinearGradient(0, 0, 100, 0)
Expand Down
13 changes: 13 additions & 0 deletions 2dcontext/tools/tests2dtext.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,19 @@
_assertGreen(ctx, 100, 50);
expected: green

- name: 2d.text.draw.fill.maxWidth.NaN
desc: fillText handles maxWidth correctly
testing:
- 2d.text.draw.maxwidth
code: |
ctx.fillStyle = '#0f0';
ctx.fillRect(0, 0, 100, 50);
ctx.fillStyle = '#f00';
ctx.font = '35px Arial, sans-serif';
ctx.fillText('fail fail fail fail fail', 5, 35, NaN);
_assertGreen(ctx, 100, 50);
expected: green

- name: 2d.text.draw.stroke.basic
desc: strokeText draws stroked text
manual:
Expand Down
7 changes: 0 additions & 7 deletions FileAPI/historical.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,6 @@
assert_false(prefixes[i]+'BlobBuilder' in window, prefixes[i]+'BlobBuilder');
}
}, 'BlobBuilder should not be supported.');

test(function() {
var reader = new FileReader();
assert_false('readAsBinaryString' in reader, 'should not be in reader');
assert_equals(reader.readAsBinaryString, undefined,
'should be undefined on getting')
}, 'FileReader should not support readAsBinaryString');
</script>
</body>
</html>
Loading

0 comments on commit 20753a5

Please sign in to comment.