blob: 3854f21229ce70b4312f8338870657bb52f5342a (
plain)
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
|
<head>
<style>
@font-face {
font-family: 'webfont';
src: url(http://localhost:8000/css/resources/webfont-request.php?mode=getFont&filename=webfontRequestCount.txt) format('truetype');
}
</style>
<script>
if (window.testRunner) {
testRunner.dumpAsText();
testRunner.waitUntilDone();
}
var filename = 'filename=webfontRequestCount.txt';
var xhr;
function startTest() {
// Resets request count before starting the test.
xhr = new XMLHttpRequest;
xhr.onerror = function() {
document.getElementById('result').innerText = 'FAIL: Network error.';
if (window.testRunner)
testRunner.notifyDone();
};
xhr.onreadystatechange = function() {
if (xhr.readyState == xhr.DONE)
forceStyleSelectorRecreation();
};
xhr.open('GET', '/resources/reset-temp-file.php?' + filename, true);
xhr.send();
}
function forceStyleSelectorRecreation() {
document.head.appendChild(document.createElement("style"));
// Pauses for a moment to see whether font re-fetching occurs.
setTimeout(getRequestCount, 100);
}
function getRequestCount() {
xhr.onreadystatechange = function() {
if (xhr.readyState == xhr.DONE)
checkRequestCount();
};
xhr.open('GET', 'http://localhost:8000/css/resources/webfont-request.php?mode=getRequestCount&' + filename, true);
xhr.send();
}
function checkRequestCount() {
var numRequest = xhr.responseText;
var result = document.getElementById('result');
result.innerHTML = 'Number of requests after recalculation: ' + numRequest + '<br />';
if (numRequest == '0')
result.innerHTML += 'SUCCESS';
else
result.innerHTML += 'FAIL';
if (window.testRunner)
testRunner.notifyDone();
};
</script>
</head>
<body onload="startTest()">
<p>This test ensures that webfonts are not re-fetched after style recalculation.</p>
<div style="font-family: webfont;">Text</div>
<div id="result"></div>
<script>
document.body.offsetTop;
</script>
</body>
|