Bug 1560908 [wpt PR 17412] - [Navigation Timing] Replace TAO restrictions with same-origin ones, a=testonly

Automatic update from web-platform-tests
[Navigation Timing] Replace TAO restrictions with same-origin ones

The NavigationTiming specification changed [1] to replace TAO based opt-in
to get information about unloadStart, unloadEnd and redirectCount with
same origin restrictions.

Our implementation was not aligned with the old spec language, but
isn't aligned with the new one either.

This CL aligns the implementation with the new language.

Change-Id: Ic4f3c7061e7b9a40f960f0bf26ef26823d5fe743
Bug: 977147

[1] https://github.com/w3c/navigation-timing/pull/108

Change-Id: Ic4f3c7061e7b9a40f960f0bf26ef26823d5fe743
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1669355
Commit-Queue: Yoav Weiss <yoavweiss@chromium.org>
Reviewed-by: Nicolás Peña Moreno <npm@chromium.org>
Cr-Commit-Position: refs/heads/master@{#671229}

--

wpt-commits: 94f51553f1413cf2118b9bf89762bfad16d8a18a
wpt-pr: 17412
This commit is contained in:
Yoav Weiss 2019-07-19 12:38:16 +00:00 коммит произвёл James Graham
Родитель 9019f4daff
Коммит cd5238cddf
8 изменённых файлов: 125 добавлений и 355 удалений

Просмотреть файл

@ -1,57 +0,0 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Navigation Timing 2 WPT</title>
<link rel="author" title="Google" href="http://www.google.com/" />
<link rel="help" href="http://www.w3.org/TR/navigation-timing-2/#sec-PerformanceNavigationTiming"/>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/common/utils.js"></script>
<script>
function verifyTimingEventOrder(eventOrder, timingEntry) {
for (var i = 0; i < eventOrder.length - 1; i++) {
assert_true(timingEntry[eventOrder[i]] < timingEntry[eventOrder[i + 1]],
"Expected " + eventOrder[i] + " to be no greater than " + eventOrder[i + 1] + ".");
}
}
function onload_test()
{
var frame_performance = document.getElementById("frameContext").contentWindow.performance;
assert_equals(frame_performance.getEntriesByType("navigation")[0].type,
"navigate",
"Expected navigation type to be navigate.");
assert_equals(frame_performance.getEntriesByType("navigation")[0].redirectCount, 1, "Expected redirectCount to be 1.");
var timgingEvents = [
'startTime',
'redirectStart',
'redirectEnd',
];
verifyTimingEventOrder(timgingEvents, frame_performance.getEntriesByType("navigation")[0]);
done();
}
</script>
</head>
<body>
<h1>Description</h1>
<p>This test validates the values of the window.performance.getEntriesByType("navigation")[0].redirectCount and the
window.performance.getEntriesByType("navigation")[0].redirectStart/End times for a cross-origin server side redirect navigation when the redirect chooses to opt-in.</p>
<iframe id="frameContext" src="" style="width: 250px; height: 250px;"></iframe>
<script>
// combine the page origin and redirect origin into the IFRAME's src URL
var destUrl = make_absolute_url({subdomain: "www",
path: "/common/redirect-opt-in.py",
query: "location=" + make_absolute_url(
{path: "/navigation-timing/resources/blank_page_green.html"})
});
var frameContext = document.getElementById("frameContext");
frameContext.onload = onload_test;
frameContext.src = destUrl;
</script>
</body>
</html>

Просмотреть файл

@ -1,36 +0,0 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Navigation Timing 2 WPT</title>
<link rel="author" title="Google" href="http://www.google.com/" />
<link rel="help" href="http://www.w3.org/TR/navigation-timing/#sec-navigation-timing-interface"/>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
function onload_test()
{
var frame = document.getElementById("frameContext");
assert_equals(frame.contentWindow.performance.getEntriesByType("navigation")[0].type,
"navigate",
"Expected navigation type to be navigate.");
assert_equals(frame.contentWindow.performance.getEntriesByType("navigation")[0].unloadEventStart, 0,
"Expected unloadEventStart to be 0.");
assert_equals(frame.contentWindow.performance.getEntriesByType("navigation")[0].unloadEventEnd, 0,
"Expected unloadEventEnd to be 0.");
done();
}
</script>
</head>
<body>
<h1>Description</h1>
<p>This test validates the unload event times are 0 when there is no previous document.</p>
<iframe id="frameContext" onload="onload_test();" src="resources/blank_page_green.html" style="width: 250px; height: 250px;"></iframe>
</body>
</html>

Просмотреть файл

@ -1,45 +0,0 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Navigation Timing 2 WPT</title>
<link rel="author" title="Google" href="http://www.google.com/" />
<link rel="help" href="http://www.w3.org/TR/navigation-timing-2/#sec-PerformanceNavigationTiming"/>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/common/utils.js"></script>
<script>
function onload_test()
{
var reload_frame = document.getElementById("frameContext");
reload_frame.onload = do_test;
reload_frame.contentWindow.location.href = "resources/blank_page_green.html";
}
function do_test()
{
var newNavTiming = document.getElementById("frameContext").contentWindow.performance.getEntriesByType("navigation")[0];
assert_equals(newNavTiming.type, "navigate", "Expected navigation type to be navigate.");
assert_equals(newNavTiming.unloadEventStart, 0, "Expected unloadEventStart to be 0.");
assert_equals(newNavTiming.unloadEventEnd, 0, "Expected unloadEventEnd to be 0.");
done();
}
</script>
</head>
<body>
<h1>Description</h1>
<p>This test validates the value of window.performance.getEntriesByType("navigation")[0].(type/unloadEventEnd/unloadEventStart) with a navigation on top of a cross-origin document.</p>
<p>This page should be loaded with a green background frame below. The frame will be automatically reloaded
and then verified that
<ul>
<li>The window.performance.getEntriesByType("navigation").type = "navigate"</li>
<li>The window.performance.getEntriesByType("navigation").unloadEventStart = 0</li>
<li>The window.performance.getEntriesByType("navigation").unloadEventEnd = 0</li>
</ul>
</p>
<iframe id="frameContext" onload="onload_test();" src="{{location[scheme]}}://{{domains[www2]}}:{{ports[http][0]}}/common/blank.html" style="width: 250px; height: 250px;"></iframe>
</body>
</html>

Просмотреть файл

@ -1,61 +0,0 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Navigation Timing 2 WPT</title>
<link rel="author" title="Google" href="http://www.google.com/" />
<link rel="help" href="http://www.w3.org/TR/navigation-timing-2/#sec-PerformanceNavigationTiming"/>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/common/utils.js"></script>
<script>
let reload_frame;
function onload_test()
{
reload_frame = document.getElementById("frameContext");
reload_frame.onload = do_test;
setTimeout("reload_the_frame();", 100);
}
function reload_the_frame()
{
const destUrl_first = make_absolute_url({subdomain: "www",
path: "/common/redirect-opt-in.py",
query: "location=" + make_absolute_url(
{path: "/navigation-timing/resources/blank_page_yellow.html"})
});
const destUrl = make_absolute_url({subdomain: "www",
path: "/common/redirect.py",
query: "location=" + destUrl_first
});
reload_frame.contentWindow.location.href = destUrl;
}
function do_test()
{
const newNavTiming = document.getElementById("frameContext").contentWindow.performance.getEntriesByType("navigation")[0];
assert_equals(newNavTiming.type, "navigate", "Expected navigation type to be navigate.");
assert_equals(newNavTiming.unloadEventStart, 0, "Expected unloadEventStart to be 0.");
assert_equals(newNavTiming.unloadEventEnd, 0, "Expected unloadEventEnd to be 0.");
done();
}
</script>
</head>
<body>
<h1>Description</h1>
<p>This test validates the value of window.performance.getEntriesByType("navigation")[0].(type/unloadEventEnd/unloadEventStart) with a reloaded navigation.</p>
<p>This page should be loaded with a green background frame below. The frame will be automatically reloaded
and then verified that
<ul>
<li>The window.performance.getEntriesByType("navigation").type = "navigate"</li>
<li>The window.performance.getEntriesByType("navigation").unloadEventStart == 0</li>
<li>The window.performance.getEntriesByType("navigation").unloadEventEnd == 0</li>
</ul>
</p>
<iframe id="frameContext" onload="onload_test();" src="resources/blank_page_green.html" style="width: 250px; height: 250px;"></iframe>
</body>
</html>

Просмотреть файл

@ -1,57 +0,0 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Navigation Timing 2 WPT</title>
<link rel="author" title="Google" href="http://www.google.com/" />
<link rel="help" href="http://www.w3.org/TR/navigation-timing-2/#sec-PerformanceNavigationTiming"/>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/common/utils.js"></script>
<script>
let reload_frame;
function onload_test()
{
reload_frame = document.getElementById("frameContext");
reload_frame.onload = do_test;
setTimeout("reload_the_frame();", 100);
}
function reload_the_frame()
{
const destUrl = make_absolute_url({subdomain: "www",
path: "/common/redirect-opt-in.py",
query: "location=" + make_absolute_url(
{path: "/navigation-timing/resources/blank_page_yellow.html"})
});
reload_frame.contentWindow.location.href = destUrl;
}
function do_test()
{
const newNavTiming = document.getElementById("frameContext").contentWindow.performance.getEntriesByType("navigation")[0];
assert_equals(newNavTiming.type, "navigate", "Expected navigation type to be navigate.");
assert_not_equals(newNavTiming.unloadEventStart, 0, "Expected unloadEventStart to not be 0.");
assert_not_equals(newNavTiming.unloadEventEnd, 0, "Expected unloadEventEnd to not be 0.");
done();
}
</script>
</head>
<body>
<h1>Description</h1>
<p>This test validates the value of window.performance.getEntriesByType("navigation")[0].(type/unloadEventEnd/unloadEventStart) with a reloaded navigation.</p>
<p>This page should be loaded with a green background frame below. The frame will be automatically reloaded
and then verified that
<ul>
<li>The window.performance.getEntriesByType("navigation").type = "navigate"</li>
<li>The window.performance.getEntriesByType("navigation").unloadEventStart == 0</li>
<li>The window.performance.getEntriesByType("navigation").unloadEventEnd == 0</li>
</ul>
</p>
<iframe id="frameContext" onload="onload_test();" src="resources/blank_page_green.html" style="width: 250px; height: 250px;"></iframe>
</body>
</html>

Просмотреть файл

@ -1,57 +0,0 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Navigation Timing 2 WPT</title>
<link rel="author" title="Google" href="http://www.google.com/" />
<link rel="help" href="http://www.w3.org/TR/navigation-timing-2/#sec-PerformanceNavigationTiming"/>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/common/utils.js"></script>
<script>
var reload_frame;
function onload_test()
{
reload_frame = document.getElementById("frameContext");
reload_frame.onload = do_test;
setTimeout("reload_the_frame();", 100);
}
function reload_the_frame()
{
var destUrl = make_absolute_url({subdomain: "www",
path: "/common/redirect.py",
query: "location=" + make_absolute_url(
{path: "/navigation-timing/resources/blank_page_yellow.html"})
});
reload_frame.contentWindow.location.href = destUrl;
}
function do_test()
{
var newNavTiming = document.getElementById("frameContext").contentWindow.performance.getEntriesByType("navigation")[0];
assert_equals(newNavTiming.type, "navigate", "Expected navigation type to be navigate.");
assert_equals(newNavTiming.unloadEventStart, 0, "Expected unloadEventStart to be 0.");
assert_equals(newNavTiming.unloadEventEnd, 0, "Expected unloadEventEnd to be 0.");
done();
}
</script>
</head>
<body>
<h1>Description</h1>
<p>This test validates the value of window.performance.getEntriesByType("navigation")[0].(type/unloadEventEnd/unloadEventStart) with a reloaded navigation.</p>
<p>This page should be loaded with a green background frame below. The frame will be automatically reloaded
and then verified that
<ul>
<li>The window.performance.getEntriesByType("navigation").type = "navigate"</li>
<li>The window.performance.getEntriesByType("navigation").unloadEventStart == 0</li>
<li>The window.performance.getEntriesByType("navigation").unloadEventEnd == 0</li>
</ul>
</p>
<iframe id="frameContext" onload="onload_test();" src="resources/blank_page_green.html" style="width: 250px; height: 250px;"></iframe>
</body>
</html>

Просмотреть файл

@ -1,42 +0,0 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Navigation Timing 2 WPT</title>
<link rel="author" title="Google" href="http://www.google.com/" />
<link rel="help" href="http://www.w3.org/TR/navigation-timing-2/#sec-PerformanceNavigationTiming"/>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
function onload_test()
{
var reload_frame = document.getElementById("frameContext");
reload_frame.onload = do_test;
reload_frame.contentWindow.location.reload(true);
}
function do_test()
{
var newNavTiming = document.getElementById("frameContext").contentWindow.performance.getEntriesByType("navigation")[0];
assert_true(newNavTiming.unloadEventStart > 0, "Expected unloadEventStart to be greater than 0.");
assert_true(newNavTiming.unloadEventEnd > 0, "Expected unloadEventEnd to be greater than 0.");
done();
}
</script>
</head>
<body>
<h1>Description</h1>
<p>This test validates the value of window.performance.getEntriesByType("navigation")[0].(type/unloadEventEnd/unloadEventStart) with a reloaded navigation.</p>
<p>This page should be loaded with a green background frame below. The frame will be automatically reloaded
and then verified that
<ul>
<li>The window.performance.getEntriesByType("navigation").unloadEventStart > 0 after reload</li>
<li>The window.performance.getEntriesByType("navigation").unloadEventEnd > 0 after reload</li>
</ul>
</p>
<iframe id="frameContext" onload="onload_test();" src="resources/blank_page_green.html" style="width: 250px; height: 250px;"></iframe>
</body>
</html>

Просмотреть файл

@ -0,0 +1,125 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Navigation Timing 2 WPT</title>
<link rel="author" title="Google" href="http://www.google.com/" />
<link rel="help" href="http://www.w3.org/TR/navigation-timing-2/#sec-PerformanceNavigationTiming"/>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/common/get-host-info.sub.js"></script>
</head>
<body>
<script>
const start_page = "/navigation-timing/resources/blank_page_green.html";
const end_page = "/navigation-timing/resources/blank_page_yellow.html";
const host_info = get_host_info();
const redirect_chain_partial_tao = () => {
let url = host_info["HTTP_REMOTE_ORIGIN"];
url += "/common/redirect.py";
url += "?location=";
url += host_info["HTTP_REMOTE_ORIGIN"];
url += "/common/redirect-opt-in.py";
url += "?location=";
url += host_info["ORIGIN"];
url += end_page;
return url;
};
const redirect_chain_full_tao = () => {
let url = host_info["HTTP_REMOTE_ORIGIN"];
url += "/common/redirect-opt-in.py";
url += "?location=";
url += host_info["ORIGIN"];
url += end_page;
return url;
};
const redirect_chain_no_tao = () => {
let url = host_info["HTTP_REMOTE_ORIGIN"];
url += "/common/redirect.py";
url += "?location=";
url += host_info["ORIGIN"];
url += end_page;
return url;
};
const same_origin_redirect_chain = () => {
let url = host_info["ORIGIN"];
url += "/common/redirect.py";
url += "?location=";
url += host_info["ORIGIN"];
url += end_page;
return url;
};
const cross_origin_start = host_info["HTTP_REMOTE_ORIGIN"] + start_page;
const test_cases = [
{ start_url : start_page, end_url: redirect_chain_partial_tao(), unload_exposed: false, redirects: 0, name: "Redirect chain with a partial TAO opt-in" },
{ start_url : start_page, end_url: redirect_chain_full_tao(), unload_exposed: false, redirects: 0, name: "Redirect chain with full TAO opt-in" },
{ start_url : start_page, end_url: redirect_chain_no_tao(), unload_exposed: false, redirects: 0, name: "Same-cross-same redirect chain with no TAO opt-in" },
{ start_url : cross_origin_start, end_url: redirect_chain_no_tao(), unload_exposed: false, redirects: 0, name: "cross-cross-same Redirect chain with no TAO opt-in" },
{ start_url : cross_origin_start, end_url: end_page, unload_exposed: false, redirects: 0, name: "Previous document cross origin" },
{ start_url : start_page, end_url: end_page, unload_exposed: true, redirects: 0, name: "Previous document same origin" },
{ start_url : start_page, end_url: null, unload_exposed: false, redirects: 0, name: "No previous document" },
{ start_url : start_page, end_url: same_origin_redirect_chain(), unload_exposed: true, redirects: 1, name: "Same origin previous document with same origin redirect" },
{ start_url : same_origin_redirect_chain(), end_url: null, unload_exposed: false, redirects: 1, name: "No previous document with same origin redirect" },
{ start_url : redirect_chain_no_tao(), end_url: null, unload_exposed: false, redirects: 0, name: "No previous document with cross origin redirect" },
{ start_url : redirect_chain_full_tao(), end_url: null, unload_exposed: false, redirects: 0, name: "No previous document with cross origin redirect with partial TAO" },
{ start_url : redirect_chain_partial_tao(), end_url: null, unload_exposed: false, redirects: 0, name: "No previous document with cross origin redirect with TAO" },
];
const frame_id = "frameContext";
const create_frame = (start_url, end_url) => {
return new Promise(resolve => {
let frame = document.getElementById("frameContext");
if (frame) {
document.body.removeChild(frame);
}
frame = document.createElement("iframe");
frame.onload = () => {
if (end_url) {
frame.onload = resolve;
step_timeout(() => {frame.contentWindow.location.href = end_url;}, 10);
} else {
resolve();
}
};
frame.id = "frameContext";
frame.src = start_url;
document.body.appendChild(frame);
});
};
const run_test = (unload_exposed, redirects) => {
const entry = document.getElementById("frameContext").contentWindow.performance.getEntriesByType("navigation")[0];
assert_equals(entry.type, "navigate", "Expected navigation type to be navigate.");
if (!unload_exposed) {
assert_equals(entry.unloadEventStart, 0, "Expected unloadEventStart to be 0.");
assert_equals(entry.unloadEventEnd, 0, "Expected unloadEventEnd to be 0.");
} else {
assert_greater_than(entry.unloadEventStart, 0, "Expected unloadEventStart to not be 0.");
assert_greater_than(entry.unloadEventEnd, 0, "Expected unloadEventEnd to not be 0.");
}
assert_equals(entry.redirectCount, redirects, "Expected redirectCount to be " + redirects);
};
const create_test = async test_case => {
return new Promise(async (resolve, reject) => {
await create_frame(test_case.start_url, test_case.end_url);
try {
run_test(test_case.unload_exposed, test_case.redirects);
resolve();
} catch (e) {
reject(e);
}
});
};
for (const test_case of test_cases) {
promise_test(() => { return create_test(test_case)}, test_case.name);
}
</script>
<h1>Description</h1>
<p>This test validates that the values of window.performance.getEntriesByType("navigation")[0].(type/unloadEventEnd/unloadEventStart) are only exposed when the same-origin test passes.</p>
</body>
</html>