1
    2
    3
    4
    5
    6
    7
    8
    9
   10
   11
   12
   13
   14
   15
   16
   17
   18
   19
   20
   21
   22
   23
   24
   25
   26
   27
   28
   29
   30
   31
   32
   33
   34
   35
   36
   37
   38
   39
   40

content / test / data / service_worker / form.html [blame]

<!DOCTYPE html>
<!-- This page has a form that submits to the "target" param of the search part
     of this page's URL. For example if this page's URL is
     "form.html?target=//example.com/upload", the form submits to
     //example.com/upload.
-->
<meta charset="utf-8">
<head>
<title>form</title>
</head>
<form id="form" method="POST" enctype="multipart/form-data">
<input id="text1" type="text" name="text1" value="textValue1">
<input id="text2" type="text" name="text2" value="textValue2">
<input id="file" type="file" name="file">
</form>
<script>
// Submits using XHR. Used for the subresource test.
async function submitXhr() {
  const xhr = new XMLHttpRequest();
  const loaded = new Promise(resolve => {
    xhr.onload = resolve;
  });
  const loadEnded = new Promise(resolve => {
    xhr.onloadend = resolve;
  });

  xhr.open("post", form.action);
  xhr.send(new FormData(form));
  await loaded;
  await loadEnded;
  return xhr.responseText;
}

const fileInput = document.querySelector('#file');
const form = document.querySelector('#form');

// Set the form to submit to the |target| param.
const documentUrl = new URL(window.location);
form.action = documentUrl.searchParams.get('target');
</script>