Skip to content

Commit

Permalink
Merge pull request #1234 from zcorpan/img-picture
Browse files Browse the repository at this point in the history
Some tests for <img>/<picture>
  • Loading branch information
zcorpan committed Sep 18, 2014
2 parents a87f389 + 87823b5 commit a5a715a
Show file tree
Hide file tree
Showing 9 changed files with 922 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<!doctype html>
<title>img current pixel density basic</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<div id=log></div>
<img src="/images/green-256x256.png" data-expect="256">
<img srcset="/images/green-256x256.png 1x" data-expect="256">
<img srcset="/images/green-256x256.png 1.6x" data-expect="160">
<img srcset="/images/green-256x256.png 2x" data-expect="128">
<img srcset="/images/green-256x256.png 10000x" data-expect="0">
<img srcset="/images/green-256x256.png 9e99999999999999999999999x" data-expect="0">
<img srcset="/images/green-256x256.png 256w" sizes="256px" data-expect="256">
<img srcset="/images/green-256x256.png 512w" sizes="256px" data-expect="128">
<img srcset="/images/green-256x256.png 256w" sizes="512px" data-expect="512">
<img srcset="/images/green-256x256.png 256w" sizes="1px" data-expect="1">
<img srcset="/images/green-256x256.png 256w" sizes="0px" data-expect="0">
<script>
setup({explicit_done:true});
onload = function() {
[].forEach.call(document.images, function(img) {
var expected = parseFloat(img.dataset.expect);
test(function() {
assert_equals(img.width, expected, 'width');
assert_equals(img.height, expected, 'height');
assert_equals(img.clientWidth, expected, 'clientWidth');
assert_equals(img.clientHeight, expected, 'clientHeight');
assert_equals(img.naturalWidth, 256, 'naturalWidth');
assert_equals(img.naturalHeight, 256, 'naturalHeight');
}, img.outerHTML);
});
done();
};
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<!doctype html>
<title>img current pixel density error</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<div id=log></div>
<img id=ref src="404" alt="testing">
<img srcset="404" alt="testing">
<img srcset="404 0.5x" alt="testing">
<img srcset="404 2x" alt="testing">
<img srcset="404 100w" alt="testing">
<img srcset="404 100w" sizes="500px" alt="testing">
<picture><img src="404 100w" sizes="500px" alt="testing"></picture>
<script>
setup({explicit_done:true});
onload = function() {
var expected_width = ref.width;
var expected_height = ref.height;
[].forEach.call(document.images, function(img) {
test(function() {
assert_not_equals(expected_width, 0, 'expected_width');
assert_not_equals(expected_height, 0, 'expected_height');
assert_equals(img.width, expected_width, 'width');
assert_equals(img.height, expected_height, 'height');
assert_equals(img.naturalWidth, 0, 'naturalWidth');
assert_equals(img.naturalHeight, 0, 'naturalHeight');
}, img.outerHTML);
});
done();
};
</script>
Loading

0 comments on commit a5a715a

Please sign in to comment.