forked from WebKit/WebKit-http
-
Notifications
You must be signed in to change notification settings - Fork 157
Expand file tree
/
Copy pathasync-image-background-image-repeated.html
More file actions
78 lines (72 loc) · 2.78 KB
/
async-image-background-image-repeated.html
File metadata and controls
78 lines (72 loc) · 2.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<!DOCTYPE html>
<html>
<meta name="fuzzy" content="maxDifference=0-1;totalPixels=28600-29000" />
<style>
.box {
height: 50px;
display: inline-block;
zoom: 2;
image-rendering: crisp-edges;
}
.green-box {
width: 100px;
background-position: -50px -16500px;
}
.repeat-box {
width: 400px;
background-position: 0px -16500px;
background-repeat: repeat-x;
}
.image-background {
}
</style>
<body>
<div class="box green-box image-background"></div>
<br>
<div class="box repeat-box image-background"></div>
<script>
function setElementImageBackground(element, image) {
return new Promise((resolve) => {
element.style.backgroundImage = 'url(' + image.src + ')';
// Force layout and display so the image frame starts decoding.
document.body.offsetHeight;
testRunner.display();
element.addEventListener("webkitImageFrameReady", function() {
resolve();
}, false);
});
}
(function() {
if (window.internals && window.testRunner) {
internals.clearMemoryCache();
internals.settings.setWebkitImageReadyEventEnabled(true);
internals.settings.setLargeImageAsyncDecodingEnabled(true);
testRunner.waitUntilDone();
}
var image = new Image();
image.onload = function() {
// Force async image decoding for this image.
if (window.internals)
internals.setAsyncDecodingEnabledForTesting(image, true);
// Change the background of the elements.
var elements = document.getElementsByClassName("image-background");
if (window.internals && window.testRunner) {
var promises = [];
for (var index = 0; index < elements.length; ++index)
promises.push(setElementImageBackground(elements[index], image));
Promise.all(promises).then(() => {
// Ensure internals.destroyDecodedDataForAllImages() will not destroy
// the images' decoded data because it is inside the viewport.
internals.destroyDecodedDataForAllImages();
testRunner.notifyDone();
});
} else {
for (var index = 0; index < elements.length; ++index)
elements[index].style.backgroundImage = 'url(' + image.src + ')';
}
}
image.src = "resources/sprite-sheet-red-green-blue.png";
})();
</script>
</body>
</html>