Commit fc34c7c5 authored by David Van Cleve's avatar David Van Cleve Committed by Commit Bot

Update referrer policy test javascript

Currently the referrer policy browsertests' JS files read
query params by dead-reckoning using a regex. This causes
browser blackscreens when you add additional query params.

This change fixes this problem by updating the tests to use
JS's URLSearchParams (which didn't exist when they were
originally written).

Change-Id: Iab72ae6b5e213d841f896294117662d23c4cca4c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2000963Reviewed-by: default avatarAvi Drissman <avi@chromium.org>
Commit-Queue: David Van Cleve <davidvc@chromium.org>
Cr-Commit-Position: refs/heads/master@{#731797}
parent fd11a91a
......@@ -3,32 +3,23 @@
<head>
<script>
function run() {
var kPolicy = 1;
var kRedirect = 2;
var kLink = 3;
var kTarget = 4;
var re = new RegExp("policy=(.*)&redirect=(.*)&link=(.*)&target=(.*)");
var matches = re.exec(document.location.search);
const params = new URLSearchParams(document.location.search);
const policy = params.get('policy');
const destination = params.get('redirect');
const shouldUseLink = params.get('link');
const target = params.get('target');
if (matches == null) {
document.body.innerText = "Could not parse parameters!";
return;
}
if (matches[kPolicy] != "no-meta") {
var meta = document.createElement("meta");
if (policy != "no-meta") {
const meta = document.createElement("meta");
meta.name = "referrer";
meta.content = matches[kPolicy];
meta.content = policy;
document.head.appendChild(meta);
}
var destination = matches[kRedirect];
var redirectMatches;
if (matches[kLink] == "true") {
var link = document.createElement("a");
if (shouldUseLink == "true") {
const link = document.createElement("a");
link.innerText = "link";
link.target = matches[kTarget];
link.target = target;
link.href = destination;
document.body.appendChild(link);
} else {
......
......@@ -3,25 +3,17 @@
<head>
<script>
function run() {
const kPolicy = 1;
const kRedirect = 2;
const re = new RegExp("policy=(.*)&redirect=(.*)");
const matches = re.exec(document.location.search);
const params = new URLSearchParams(document.location.search);
const policy = params.get('policy');
const destination = params.get('redirect');
if (matches == null) {
document.body.innerText = "Could not parse parameters!";
return;
}
if (matches[kPolicy] != "no-meta") {
if (policy != "no-meta") {
const meta = document.createElement("meta");
meta.name = "referrer";
meta.content = matches[kPolicy];
meta.content = policy;
document.head.appendChild(meta);
}
const destination = matches[kRedirect];
const image = document.createElement("img");
image.src = destination;
image.onload = function() { document.title = 'loaded'; };
......
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