forked from WebKit/WebKit-http
-
Notifications
You must be signed in to change notification settings - Fork 158
Expand file tree
/
Copy pathasync-image-background-image.html
More file actions
61 lines (57 loc) · 2.15 KB
/
async-image-background-image.html
File metadata and controls
61 lines (57 loc) · 2.15 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
<!DOCTYPE html>
<html>
<style>
.box {
width: 300px;
height: 300px;
}
.image-background {
background-position: -300px 0px;
}
@media (-webkit-min-device-pixel-ratio: 2) {
.box {
width: 150px;
height: 150px;
}
.image-background {
background-position: -150px 0px;
background-size: 450px, 150px;
}
}
</style>
<body>
<div class="box image-background"></div>
<script>
(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 element.
var element = document.getElementsByClassName("image-background")[0];
element.style.backgroundImage = 'url(' + image.src + ')';
if (window.internals && window.testRunner) {
// Force layout and display so the image frame starts decoding.
document.body.offsetHeight;
testRunner.display();
// Wait for the image frame to finish decoding before finishing the test.
element.addEventListener("webkitImageFrameReady", function() {
// Ensure internals.destroyDecodedDataForAllImages() will not destroy
// the image's decoded data because it is inside the viewport.
internals.destroyDecodedDataForAllImages();
testRunner.notifyDone();
}, false);
}
}
image.src = "resources/red-green-blue-900-300.png";
})();
</script>
</body>
</html>