Commit ae1255b2 authored by Takashi Toyoshima's avatar Takashi Toyoshima Committed by Commit Bot

Fix link-rel-prefetch.html not to depend on server logs

misc/link-rel-prefetch.html and css/mask-image-loading.html
use the same server logging infra, network-simulator.php,
and the access logs for them are sometime mixed and randomly
failed due to that.

This patch updates link-rel-prefetch.html not to depend on
the server logs as we can verify the behavior via client
side callbacks.

Bug: 1140244, 1140251
Change-Id: I092e092c7c9310b815b09419a206b1517ebd21f5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2521975
Commit-Queue: Takashi Toyoshima <toyoshim@chromium.org>
Reviewed-by: default avatarHiroki Nakagawa <nhiroki@chromium.org>
Cr-Commit-Position: refs/heads/master@{#825260}
parent b4af68b7
CONSOLE WARNING: line 5: Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user's experience. For more help, check https://xhr.spec.whatwg.org/. CONSOLE WARNING: line 8: Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user's experience. For more help, check https://xhr.spec.whatwg.org/.
Resource requests: Resource requests:
border2.jpg border2.jpg
CONSOLE WARNING: line 5: Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user's experience. For more help, check https://xhr.spec.whatwg.org/. CONSOLE WARNING: line 8: Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user's experience. For more help, check https://xhr.spec.whatwg.org/.
item item
Resource requests: Resource requests:
......
CONSOLE WARNING: line 5: Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user's experience. For more help, check https://xhr.spec.whatwg.org/. CONSOLE WARNING: line 8: Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user's experience. For more help, check https://xhr.spec.whatwg.org/.
Resource requests: Resource requests:
mask2.jpg mask2.jpg
CONSOLE WARNING: line 5: Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user's experience. For more help, check https://xhr.spec.whatwg.org/. CONSOLE WARNING: line 8: Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user's experience. For more help, check https://xhr.spec.whatwg.org/.
Resource requests: Resource requests:
mask2.jpg mask2.jpg
// Do not use for new tests as this logging functionalities are not maintained,
// and are not safe to run tests in parallel. Accesses for other tests may be
// merged, or other commands may trim the log.
function CallCommand(cmd) function CallCommand(cmd)
{ {
try { try {
...@@ -16,7 +19,7 @@ function startTest() ...@@ -16,7 +19,7 @@ function startTest()
testRunner.dumpAsText(); testRunner.dumpAsText();
testRunner.waitUntilDone(); testRunner.waitUntilDone();
} }
window.setTimeout(endTest, 0); window.setTimeout(endTest, 0);
} }
......
CONSOLE WARNING: line 8: Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user's experience. For more help, check https://xhr.spec.whatwg.org/.
Resource requests:
1st.jpg
2nd.jpg
3rd.jpg
<html> <html>
<head> <head>
<script> <script>
function CallCommand(cmd) window.addEventListener('load', e => {
{ if (window.testRunner) {
try { testRunner.dumpAsText();
var req = new XMLHttpRequest; testRunner.waitUntilDone();
req.open("GET", "/resources/network-simulator.php?command=" + cmd, false); }
req.send(null); }, false);
return req.responseText;
} catch (ex) { var linkLoadCount = 3;
return ""; function decrementLinkLoadCount()
} {
} linkLoadCount--;
if (linkLoadCount == 0 && window.testRunner)
function startTest() window.testRunner.notifyDone();
{
if (window.testRunner) {
testRunner.dumpAsText();
testRunner.waitUntilDone();
} }
}
function endTest()
{
getResourceLog();
CallCommand("clear-resource-request-log");
if (window.testRunner)
testRunner.notifyDone();
}
function getResourceLog()
{
var log = CallCommand("get-resource-request-log");
var logLines = log.split('\n');
logLines.sort();
document.getElementById('result').innerText = logLines.join('\n');
}
CallCommand("start-resource-request-log");
window.addEventListener('load', startTest, false);
</script> </script>
<link rel=prefetch onload="decrementLinkLoadCount()" href="/resources/square100.png">
<script> <link rel=prefetch onload="decrementLinkLoadCount()" href="/resources/square200.png">
var linkLoadCount = 3; <link rel=prefetch onload="decrementLinkLoadCount()" href="/resources/square20.png">
function decrementLinkLoadCount()
{
linkLoadCount--;
if (linkLoadCount == 0) {
endTest();
}
}
</script>
<link rel=prefetch onload="decrementLinkLoadCount()" href="/resources/network-simulator.php?command=log-resource-request&path=1st.jpg">
<link rel=prefetch onload="decrementLinkLoadCount()" href="/resources/network-simulator.php?command=log-resource-request&path=2nd.jpg">
<link rel=prefetch onload="decrementLinkLoadCount()" href="/resources/network-simulator.php?command=log-resource-request&path=3rd.jpg">
</head> </head>
<body>
<div class="box bordered"></div>
<h2>Resource requests:</h2>
<pre id="result">Request log goes here in DRT</pre>
</body>
</html> </html>
...@@ -79,7 +79,7 @@ function generateResponse($path) ...@@ -79,7 +79,7 @@ function generateResponse($path)
if (file_exists($path)) { if (file_exists($path)) {
header("Last-Modified: " . gmdate("D, d M Y H:i:s T", filemtime($path))); header("Last-Modified: " . gmdate("D, d M Y H:i:s T", filemtime($path)));
header("Content-Type: " . contentType($path)); header("Content-Type: " . contentType($path));
print file_get_contents($path); print file_get_contents($path);
} else { } else {
header('HTTP/1.1 404 Not Found'); header('HTTP/1.1 404 Not Found');
...@@ -124,6 +124,9 @@ function handleGetResourceCountCommand($path) ...@@ -124,6 +124,9 @@ function handleGetResourceCountCommand($path)
} }
} }
# Do not use for new tests as this logging functionalities are not maintained,
# and are not safe to run tests in parallel. Accesses for other tests may be
# merged, or other commands may trim the log.
function handleStartResourceRequestsLog() function handleStartResourceRequestsLog()
{ {
$resourceLogFile = sys_get_temp_dir() . "/resource-log"; $resourceLogFile = sys_get_temp_dir() . "/resource-log";
...@@ -149,7 +152,7 @@ function handleGetResourceRequestsLog() ...@@ -149,7 +152,7 @@ function handleGetResourceRequestsLog()
function handleLogResourceRequest($path) function handleLogResourceRequest($path)
{ {
$resourceLogFile = sys_get_temp_dir() . "/resource-log"; $resourceLogFile = sys_get_temp_dir() . "/resource-log";
$newData = "\n".$path; $newData = "\n".$path;
file_put_contents($resourceLogFile, $newData, FILE_APPEND | LOCK_EX); file_put_contents($resourceLogFile, $newData, FILE_APPEND | LOCK_EX);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment