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 @@ ...@@ -3,32 +3,23 @@
<head> <head>
<script> <script>
function run() { function run() {
var kPolicy = 1; const params = new URLSearchParams(document.location.search);
var kRedirect = 2; const policy = params.get('policy');
var kLink = 3; const destination = params.get('redirect');
var kTarget = 4; const shouldUseLink = params.get('link');
var re = new RegExp("policy=(.*)&redirect=(.*)&link=(.*)&target=(.*)"); const target = params.get('target');
var matches = re.exec(document.location.search);
if (matches == null) { if (policy != "no-meta") {
document.body.innerText = "Could not parse parameters!"; const meta = document.createElement("meta");
return;
}
if (matches[kPolicy] != "no-meta") {
var meta = document.createElement("meta");
meta.name = "referrer"; meta.name = "referrer";
meta.content = matches[kPolicy]; meta.content = policy;
document.head.appendChild(meta); document.head.appendChild(meta);
} }
var destination = matches[kRedirect]; if (shouldUseLink == "true") {
var redirectMatches; const link = document.createElement("a");
if (matches[kLink] == "true") {
var link = document.createElement("a");
link.innerText = "link"; link.innerText = "link";
link.target = matches[kTarget]; link.target = target;
link.href = destination; link.href = destination;
document.body.appendChild(link); document.body.appendChild(link);
} else { } else {
......
...@@ -3,25 +3,17 @@ ...@@ -3,25 +3,17 @@
<head> <head>
<script> <script>
function run() { function run() {
const kPolicy = 1; const params = new URLSearchParams(document.location.search);
const kRedirect = 2; const policy = params.get('policy');
const re = new RegExp("policy=(.*)&redirect=(.*)"); const destination = params.get('redirect');
const matches = re.exec(document.location.search);
if (matches == null) { if (policy != "no-meta") {
document.body.innerText = "Could not parse parameters!";
return;
}
if (matches[kPolicy] != "no-meta") {
const meta = document.createElement("meta"); const meta = document.createElement("meta");
meta.name = "referrer"; meta.name = "referrer";
meta.content = matches[kPolicy]; meta.content = policy;
document.head.appendChild(meta); document.head.appendChild(meta);
} }
const destination = matches[kRedirect];
const image = document.createElement("img"); const image = document.createElement("img");
image.src = destination; image.src = destination;
image.onload = function() { document.title = 'loaded'; }; 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