diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:32:43 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:32:43 +0000 |
commit | 6bf0a5cb5034a7e684dcc3500e841785237ce2dd (patch) | |
tree | a68f146d7fa01f0134297619fbe7e33db084e0aa /devtools/client/netmonitor/test/html_curl-utils.html | |
parent | Initial commit. (diff) | |
download | thunderbird-upstream.tar.xz thunderbird-upstream.zip |
Adding upstream version 1:115.7.0.upstream/1%115.7.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'devtools/client/netmonitor/test/html_curl-utils.html')
-rw-r--r-- | devtools/client/netmonitor/test/html_curl-utils.html | 136 |
1 files changed, 136 insertions, 0 deletions
diff --git a/devtools/client/netmonitor/test/html_curl-utils.html b/devtools/client/netmonitor/test/html_curl-utils.html new file mode 100644 index 0000000000..bd09a63ba5 --- /dev/null +++ b/devtools/client/netmonitor/test/html_curl-utils.html @@ -0,0 +1,136 @@ +<!-- Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ --> +<!doctype html> + +<html> + <head> + <meta charset="utf-8"/> + <meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate" /> + <meta http-equiv="Pragma" content="no-cache" /> + <meta http-equiv="Expires" content="0" /> + <title>Network Monitor test page</title> + </head> + + <body> + <p>Performing requests</p> + + <p> + <canvas width="100" height="100"></canvas> + </p> + + <hr/> + + <form method="post" action="#" enctype="multipart/form-data" target="target" id="post-form"> + <input type="text" name="param1" value="value1"/> + <input type="text" name="param2" value="value2"/> + <input type="text" name="param3" value="value3"/> + <input type="submit"/> + </form> + <iframe name="target"></iframe> + + <script type="text/javascript"> + /* exported performRequests */ + /* eslint-disable max-nested-callbacks */ + "use strict"; + + function ajaxGet(url, callback) { + const xhr = new XMLHttpRequest(); + xhr.open("GET", url + "?param1=value1¶m2=value2¶m3=value3", true); + xhr.setRequestHeader("X-Requested-With", "XMLHttpRequest"); + xhr.onload = function() { + callback(); + }; + xhr.send(); + } + + function ajaxPost(url, callback) { + const xhr = new XMLHttpRequest(); + xhr.open("POST", url, true); + xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); + xhr.setRequestHeader("X-Requested-With", "XMLHttpRequest"); + xhr.onload = function() { + callback(); + }; + const params = "param1=value1¶m2=value2¶m3=value3"; + xhr.send(params); + } + + function ajaxPostJson(url, callback) { + const xhr = new XMLHttpRequest(); + xhr.open("POST", url, true); + xhr.setRequestHeader("Content-Type", "application/json; charset=utf-8"); + xhr.setRequestHeader("X-Requested-With", "XMLHttpRequest"); + xhr.onload = function() { + callback(); + }; + const params = { + param1: "value1", + param2: "value2", + }; + const jsonParams = JSON.stringify(params); + xhr.send(jsonParams); + } + + function ajaxPatch(url, callback) { + const xhr = new XMLHttpRequest(); + xhr.open("PATCH", url, true); + xhr.setRequestHeader("X-Requested-With", "XMLHttpRequest"); + xhr.onload = function() { + callback(); + }; + const params = "param1=value1¶m2=value2¶m3=value3"; + xhr.send(params); + } + + function ajaxMultipart(url, callback) { + const xhr = new XMLHttpRequest(); + xhr.open("POST", url, true); + xhr.setRequestHeader("X-Requested-With", "XMLHttpRequest"); + xhr.onload = function() { + callback(); + }; + + getCanvasElem().toBlob((blob) => { + const formData = new FormData(); + formData.append("param1", "value1"); + formData.append("file", blob, "filename.png"); + xhr.send(formData); + }); + } + + function submitForm() { + const form = document.querySelector("#post-form"); + form.submit(); + } + + function getCanvasElem() { + return document.querySelector("canvas"); + } + + function initCanvas() { + const canvas = getCanvasElem(); + const ctx = canvas.getContext("2d"); + ctx.fillRect(0, 0, 100, 100); + ctx.clearRect(20, 20, 60, 60); + ctx.strokeRect(25, 25, 50, 50); + } + + function performRequests(url) { + ajaxGet(url, () => { + ajaxPost(url, () => { + ajaxPostJson(url, () => { + ajaxPatch(url, () => { + ajaxMultipart(url, () => { + submitForm(); + }); + }); + }); + }); + }); + } + + initCanvas(); + </script> + </body> + +</html> |