Commit 9806cf54 authored by Yuta Kitamura's avatar Yuta Kitamura Committed by Commit Bot

agent: Add more tests that check agents in frames with different schemes.

This CL adds more tests for Agent generation. They test the following
cases:

  * HTTP frame loading a same-origin HTTPS child frame
  * iframe loaded as data: URL
  * iframe loaded with srcdoc attribute

Bug: 961186
Change-Id: I21eae63c9b6e3d5a2be911cb4cce1eb975e48cb8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1852325
Commit-Queue: Dave Tapuska <dtapuska@chromium.org>
Auto-Submit: Yuta Kitamura <yutak@chromium.org>
Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Reviewed-by: default avatarDave Tapuska <dtapuska@chromium.org>
Cr-Commit-Position: refs/heads/master@{#704716}
parent cf2dfbbe
......@@ -93,8 +93,67 @@ async_test(t => {
t.add_cleanup(() => { document.body.removeChild(iframe); });
}, 'Documents on same-origin-but-different-ports should receive the same agent.');
// TODO(yutak): Add tests for https and other tricky cases (data:// URLs, or
// iframe srcdoc etc.).
async_test(t => {
let iframe = document.createElement('iframe');
iframe.src =
'http://127.0.0.1:8000/security/resources/agent-equality-different-schemes.html';
window.addEventListener(
'message',
t.step_func(evt => {
if (evt.data[0] !== 'different-schemes test') {
return;
}
assert_equals(evt.data.length, 3);
assert_not_equals(evt.data[1], evt.data[2]);
t.done();
}));
document.body.appendChild(iframe);
t.add_cleanup(() => { document.body.removeChild(iframe); });
}, 'Documents with different schemes (HTTP and HTTPS) should receive different agents.');
async_test(t => {
let iframe = document.createElement('iframe');
iframe.src =
'http://127.0.0.1:8000/security/resources/agent-equality-data-url.html';
window.addEventListener(
'message',
t.step_func(evt => {
if (evt.data[0] !== 'data scheme test') {
return;
}
assert_equals(evt.data.length, 3);
assert_not_equals(evt.data[1], evt.data[2]);
t.done();
}));
document.body.appendChild(iframe);
t.add_cleanup(() => { document.body.removeChild(iframe); });
}, 'Frame loaded as data: URL should receive a unique agent that is different from the parent\'s.');
async_test(t => {
let iframe = document.createElement('iframe');
iframe.src =
'http://127.0.0.1:8000/security/resources/agent-equality-srcdoc.html';
window.addEventListener(
'message',
t.step_func(evt => {
if (evt.data[0] !== 'srcdoc iframe test') {
return;
}
assert_equals(evt.data.length, 3);
assert_equals(evt.data[1], evt.data[2]);
t.done();
}));
document.body.appendChild(iframe);
t.add_cleanup(() => { document.body.removeChild(iframe); });
}, 'srcdoc iframe should receive the same agent as the parent\'s.');
// TODO(yutak): Add tests that check agents after navigations.
</script>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<title>data scheme test</title>
</head>
<body>
<iframe src="data:text/html,&lt;script&gt;window.parent.postMessage(internals.getDocumentAgentId(document), '*');&lt;/script&gt;">
</iframe>
<script>
// This test loads an iframe whose src attribute is a data: URL. It posts
// it's agent ID to this frame, and we report the agent IDs of this frame and
// the child iframe.
//
// Success condition: The agent IDs of this frame and the child frame are
// different (the child frame should receive a unique agent because it's on
// an opaque origin).
function onMessage(evt) {
let iframeAgentId = evt.data;
let message = [
'data scheme test',
internals.getDocumentAgentId(document),
iframeAgentId
];
window.parent.postMessage(message, '*');
}
window.addEventListener('message', onMessage, {'once': true});
</script>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<title>Cross-origin test</title>
</head>
<body>
<iframe src="https://127.0.0.1:8443/security/resources/agent-equality-report-to-parent.html">
</iframe>
<script>
// This file should be loaded as an iframe hosted on 127.0.0.1:8000 on HTTP.
// This test creates the following frame tree:
//
// A: http://127.0.0.1:8000 (this file)
// |
// +-- B: https://127.0.0.1:8443
//
// This page posts a message to the parent window, containing two strings
// which correspond to the agent IDs of A and B, respectively.
//
// Success condition: A's agent is not the same as B's.
function onMessage(evt) {
let agentIdB = evt.data;
let message = [
'different-schemes test',
internals.getDocumentAgentId(document),
agentIdB
];
window.parent.postMessage(message, '*');
}
window.addEventListener('message', onMessage, {'once': true});
</script>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<title>srcdoc iframe test</title>
</head>
<body>
<iframe srcdoc="&lt;script&gt;window.parent.postMessage(internals.getDocumentAgentId(document), '*');&lt;/script&gt;">
</iframe>
<script>
// This test loads an iframe whose content is specified as its srcdoc
// attribute. It posts it's agent ID to this frame, and we report the agent
// IDs of this frame and the child iframe.
//
// Success condition: The agent IDs of this frame and the child frame are
// the same (the child frame is same-origin as the parent frame, unlike the
// data: URL's case. See:
// https://html.spec.whatwg.org/C#determining-the-origin )
function onMessage(evt) {
let iframeAgentId = evt.data;
let message = [
'srcdoc iframe test',
internals.getDocumentAgentId(document),
iframeAgentId
];
window.parent.postMessage(message, '*');
}
window.addEventListener('message', onMessage, {'once': true});
</script>
</body>
</html>
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