Commit dec07eda authored by Nicolás Peña Moreno's avatar Nicolás Peña Moreno Committed by Commit Bot

[ElementTiming] Add simple test for multi-redirect

Add a redirect chain similar to that being used for ResourceTiming. More
images along with TAO will be added in a followup.

Bug: 1003943
Change-Id: I07a98e6f3b574a1241f33aed60a6bb71e0240a95
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1880539Reviewed-by: default avatarYoav Weiss <yoavweiss@chromium.org>
Commit-Queue: Nicolás Peña Moreno <npm@chromium.org>
Cr-Commit-Position: refs/heads/master@{#710837}
parent 010cb7f6
...@@ -5534,6 +5534,10 @@ crbug.com/783154 [ Linux Debug ] virtual/audio-service/media/controls/doubletap- ...@@ -5534,6 +5534,10 @@ crbug.com/783154 [ Linux Debug ] virtual/audio-service/media/controls/doubletap-
#Sherrif 2019-08-16 #Sherrif 2019-08-16
crbug.com/994692 [ Linux Win ] compositing/reflections/nested-reflection-anchor-point.html [ Pass Failure ] crbug.com/994692 [ Linux Win ] compositing/reflections/nested-reflection-anchor-point.html [ Pass Failure ]
crbug.com/1003943 external/wpt/element-timing/multi-redirect-image.html [ Failure ]
crbug.com/1003943 virtual/scalefactor200/external/wpt/element-timing/multi-redirect-image.html [ Failure ]
crbug.com/1003943 virtual/scalefactor200withoutzoom/external/wpt/element-timing/multi-redirect-image.html [ Failure ]
# Video flakily not being being rendered on Mac # Video flakily not being being rendered on Mac
crbug.com/979298 [ Mac ] media/controls/captions-menu-always-visible.html [ Pass Failure ] crbug.com/979298 [ Mac ] media/controls/captions-menu-always-visible.html [ Pass Failure ]
crbug.com/979298 [ Mac ] media/controls/overflow-menu-always-visible.html [ Pass Failure ] crbug.com/979298 [ Mac ] media/controls/overflow-menu-always-visible.html [ Pass Failure ]
......
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8" />
<title>This test validates element timing information for cross-origin redirect chain images.</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="resources/element-timing-helpers.js"></script>
<script src=/common/get-host-info.sub.js></script>
</head>
<body>
<script>
async_test(t => {
if (!window.PerformanceElementTiming) {
assert_unreached("PerformanceElementTiming is not implemented");
}
let destUrl = get_host_info().HTTP_REMOTE_ORIGIN
+ '/resource-timing/resources/multi_redirect.py?';
destUrl += 'page_origin=' + get_host_info().HTTP_ORIGIN;
destUrl += '&cross_origin=' + get_host_info().HTTP_REMOTE_ORIGIN;
destUrl += '&final_resource=' + '/images/blue.png';
destUrl += '&timing_allow=1';
destUrl += '&tao_steps=';
for (let taoSteps=0; taoSteps < 4; taoSteps++) {
const image = document.createElement('img');
image.src = destUrl + taoSteps;
image.setAttribute('elementtiming', taoSteps);
image.setAttribute('id', 'id' + taoSteps)
document.body.appendChild(image);
}
let numObserved = 0;
let observedMap = [false, false, false, false];
const beforeRender = performance.now();
new PerformanceObserver(t.step_func(entries => {
entries.getEntries().forEach(entry => {
const taoSteps = entry.identifier;
assert_false(observedMap[taoSteps], 'Should observe each image once');
observedMap[taoSteps] = true;
if (taoSteps !== '3') {
assert_equals(entry.renderTime, 0,
'renderTime should be 0 when there is ' + taoSteps + ' tao steps');
}
const bound = taoSteps === '3' ? beforeRender : 0;
checkElement(entry, destUrl + taoSteps, taoSteps, 'id' + taoSteps, bound,
document.getElementById(taoSteps));
});
numObserved += entries.getEntries().length;
if (numObserved === 4)
t.done();
})).observe({type: 'element', buffered: true});
}, 'Cross-origin image without TAO should not have its renderTime set, with full TAO it should.');
</script>
</body>
</html>
// Common checks between checkElement() and checkElementWithoutResourceTiming(). // Common checks between checkElement() and checkElementWithoutResourceTiming().
function checkElementInternal(entry, expectedUrl, expectedIdentifier, expectedID, beforeRender, function checkElementInternal(entry, expectedUrl, expectedIdentifier, expectedID, beforeRender,
expectedElement) { expectedElement) {
assert_equals(entry.entryType, 'element'); assert_equals(entry.entryType, 'element', 'entryType does not match');
assert_equals(entry.url, expectedUrl); assert_equals(entry.url, expectedUrl, 'url does not match');
assert_equals(entry.identifier, expectedIdentifier); assert_equals(entry.identifier, expectedIdentifier, 'identifier does not match');
if (beforeRender != 0) { if (beforeRender != 0) {
// In this case, renderTime is not 0. // In this case, renderTime is not 0.
assert_equals(entry.startTime, entry.renderTime); assert_equals(entry.startTime, entry.renderTime, 'startTime should equal renderTime');
} else { } else {
// In this case, renderTime is 0, so compare to loadTime. // In this case, renderTime is 0, so compare to loadTime.
assert_equals(entry.startTime, entry.loadTime); assert_equals(entry.startTime, entry.loadTime, 'startTime should equal loadTime');
} }
assert_equals(entry.duration, 0); assert_equals(entry.duration, 0, 'duration should be 0');
assert_equals(entry.id, expectedID); assert_equals(entry.id, expectedID, 'id does not match');
assert_greater_than_equal(entry.renderTime, beforeRender); assert_greater_than_equal(entry.renderTime, beforeRender, 'renderTime greater than beforeRender');
assert_greater_than_equal(performance.now(), entry.renderTime); assert_greater_than_equal(performance.now(), entry.renderTime, 'renderTime bounded by now()');
if (expectedElement !== null) { if (expectedElement !== null) {
assert_equals(entry.element, expectedElement); assert_equals(entry.element, expectedElement, 'element does not match');
assert_equals(entry.identifier, expectedElement.elementTiming); assert_equals(entry.identifier, expectedElement.elementTiming,
assert_equals(entry.id, expectedElement.id); 'identifier must be the elementtiming of the element');
assert_equals(entry.id, expectedElement.id, 'id must be the id of the element');
} }
} }
......
...@@ -38,6 +38,7 @@ ...@@ -38,6 +38,7 @@
destUrl += 'page_origin=' + pageOrigin; destUrl += 'page_origin=' + pageOrigin;
destUrl += '&timing_allow=1'; destUrl += '&timing_allow=1';
destUrl += '&cross_origin=' + crossOrigin; destUrl += '&cross_origin=' + crossOrigin;
destUrl += '&final_resource=' + "/resource-timing/resources/blank-with-tao.html";
destUrl += '&tao_steps=3'; destUrl += '&tao_steps=3';
const frameContext = document.getElementById('frameContext'); const frameContext = document.getElementById('frameContext');
frameContext.onload = onload_test; frameContext.onload = onload_test;
......
...@@ -37,6 +37,7 @@ ...@@ -37,6 +37,7 @@
let destUrl = pageOrigin + '/resource-timing/resources/multi_redirect.py?'; let destUrl = pageOrigin + '/resource-timing/resources/multi_redirect.py?';
destUrl += 'page_origin=' + pageOrigin; destUrl += 'page_origin=' + pageOrigin;
destUrl += '&cross_origin=' + crossOrigin; destUrl += '&cross_origin=' + crossOrigin;
destUrl += '&final_resource=' + "/resource-timing/resources/blank-with-tao.html";
const frameContext = document.getElementById('frameContext'); const frameContext = document.getElementById('frameContext');
frameContext.onload = onload_test; frameContext.onload = onload_test;
frameContext.src = destUrl; frameContext.src = destUrl;
......
...@@ -38,6 +38,7 @@ ...@@ -38,6 +38,7 @@
destUrl += 'page_origin=' + pageOrigin; destUrl += 'page_origin=' + pageOrigin;
destUrl += '&timing_allow=1'; destUrl += '&timing_allow=1';
destUrl += '&cross_origin=' + crossOrigin; destUrl += '&cross_origin=' + crossOrigin;
destUrl += '&final_resource=' + "/resource-timing/resources/blank-with-tao.html";
destUrl += '&tao_steps=2'; destUrl += '&tao_steps=2';
const frameContext = document.getElementById('frameContext'); const frameContext = document.getElementById('frameContext');
frameContext.onload = onload_test; frameContext.onload = onload_test;
......
...@@ -37,6 +37,7 @@ ...@@ -37,6 +37,7 @@
let destUrl = get_host_info().HTTP_REMOTE_ORIGIN + '/resource-timing/resources/multi_redirect.py?'; let destUrl = get_host_info().HTTP_REMOTE_ORIGIN + '/resource-timing/resources/multi_redirect.py?';
destUrl += 'page_origin=' + 'http://' + document.location.host; destUrl += 'page_origin=' + 'http://' + document.location.host;
destUrl += '&cross_origin=' + get_host_info().HTTP_REMOTE_ORIGIN; destUrl += '&cross_origin=' + get_host_info().HTTP_REMOTE_ORIGIN;
destUrl += '&final_resource=' + "/resource-timing/resources/blank-with-tao.html";
destUrl += '&tao_steps=3'; destUrl += '&tao_steps=3';
destUrl += '&timing_allow=1'; destUrl += '&timing_allow=1';
const frameContext = document.getElementById('frameContext'); const frameContext = document.getElementById('frameContext');
......
...@@ -37,6 +37,7 @@ ...@@ -37,6 +37,7 @@
let destUrl = get_host_info().HTTP_REMOTE_ORIGIN + '/resource-timing/resources/multi_redirect.py?'; let destUrl = get_host_info().HTTP_REMOTE_ORIGIN + '/resource-timing/resources/multi_redirect.py?';
destUrl += 'page_origin=' + 'http://' + document.location.host; destUrl += 'page_origin=' + 'http://' + document.location.host;
destUrl += '&cross_origin=' + get_host_info().HTTP_REMOTE_ORIGIN; destUrl += '&cross_origin=' + get_host_info().HTTP_REMOTE_ORIGIN;
destUrl += '&final_resource=' + "/resource-timing/resources/blank-with-tao.html";
const frameContext = document.getElementById('frameContext'); const frameContext = document.getElementById('frameContext');
frameContext.onload = onload_test; frameContext.onload = onload_test;
frameContext.src = destUrl; frameContext.src = destUrl;
......
def main(request, response): def main(request, response):
"""Handler that causes multiple redirections. """Handler that causes multiple redirections. Redirect chain is as follows:
The request has two mandatory and one optional query parameters: 1. Initial URL containing multi-redirect.py
2. Redirect to cross-origin URL
3. Redirect to same-origin URL
4. Final URL containing the final same-origin resource.
The request has three mandatory and one optional query parameters:
page_origin - The page origin, used for redirection and to set TAO. This is a mandatory parameter. page_origin - The page origin, used for redirection and to set TAO. This is a mandatory parameter.
cross_origin - The cross origin used to make this a cross-origin redirect. This is a mandatory parameter. cross_origin - The cross origin used to make this a cross-origin redirect. This is a mandatory parameter.
final_resource - Path of the final resource, without origin. This is a mandatory parameter.
timing_allow - Whether TAO should be set or not in the redirect chain. This is an optional parameter. Default: not set. timing_allow - Whether TAO should be set or not in the redirect chain. This is an optional parameter. Default: not set.
Note that |step| is a parameter used internally for the multi-redirect. It's the step we're at in the redirect chain. Note that |step| is a parameter used internally for the multi-redirect. It's the step we're at in the redirect chain.
""" """
...@@ -16,6 +21,7 @@ def main(request, response): ...@@ -16,6 +21,7 @@ def main(request, response):
origin = request.url_parts.scheme + "://" + request.url_parts.hostname + ":" + str(request.url_parts.port) origin = request.url_parts.scheme + "://" + request.url_parts.hostname + ":" + str(request.url_parts.port)
page_origin = request.GET.first("page_origin") page_origin = request.GET.first("page_origin")
cross_origin = request.GET.first("cross_origin") cross_origin = request.GET.first("cross_origin")
final_resource = request.GET.first("final_resource")
tao_steps = 0 tao_steps = 0
if "tao_steps" in request.GET: if "tao_steps" in request.GET:
tao_steps = int(request.GET.first("tao_steps")) tao_steps = int(request.GET.first("tao_steps"))
...@@ -27,6 +33,7 @@ def main(request, response): ...@@ -27,6 +33,7 @@ def main(request, response):
redirect_url_path = "/resource-timing/resources/multi_redirect.py?" redirect_url_path = "/resource-timing/resources/multi_redirect.py?"
redirect_url_path += "page_origin=" + page_origin redirect_url_path += "page_origin=" + page_origin
redirect_url_path += "&cross_origin=" + cross_origin redirect_url_path += "&cross_origin=" + cross_origin
redirect_url_path += "&final_resource=" + final_resource
redirect_url_path += "&timing_allow=" + timing_allow redirect_url_path += "&timing_allow=" + timing_allow
redirect_url_path += "&tao_steps=" + str(next_tao_steps) redirect_url_path += "&tao_steps=" + str(next_tao_steps)
redirect_url_path += "&step=" redirect_url_path += "&step="
...@@ -41,7 +48,7 @@ def main(request, response): ...@@ -41,7 +48,7 @@ def main(request, response):
redirect_url = page_origin + redirect_url_path + "3" redirect_url = page_origin + redirect_url_path + "3"
else: else:
# On the third request, redirect to a static response # On the third request, redirect to a static response
redirect_url = page_origin + "/resource-timing/resources/blank-with-tao.html" redirect_url = page_origin + final_resource
response.status = 302 response.status = 302
response.headers.set("Location", redirect_url) response.headers.set("Location", redirect_url)
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