summaryrefslogtreecommitdiffstats
path: root/dom/fetch/tests
diff options
context:
space:
mode:
Diffstat (limited to 'dom/fetch/tests')
-rw-r--r--dom/fetch/tests/.eslintrc.js5
-rw-r--r--dom/fetch/tests/browser.ini2
-rw-r--r--dom/fetch/tests/browser_blobFromFile.js62
-rw-r--r--dom/fetch/tests/crashtests/1577196.html26
-rw-r--r--dom/fetch/tests/crashtests/1664514.html6
-rw-r--r--dom/fetch/tests/crashtests/crashtests.list2
-rw-r--r--dom/fetch/tests/crashtests/url.url5
-rw-r--r--dom/fetch/tests/mochitest.ini2
-rw-r--r--dom/fetch/tests/test_ext_response_constructor.html46
-rw-r--r--dom/fetch/tests/test_invalid_header_exception.html39
10 files changed, 195 insertions, 0 deletions
diff --git a/dom/fetch/tests/.eslintrc.js b/dom/fetch/tests/.eslintrc.js
new file mode 100644
index 0000000000..1779fd7f1c
--- /dev/null
+++ b/dom/fetch/tests/.eslintrc.js
@@ -0,0 +1,5 @@
+"use strict";
+
+module.exports = {
+ extends: ["plugin:mozilla/browser-test"],
+};
diff --git a/dom/fetch/tests/browser.ini b/dom/fetch/tests/browser.ini
new file mode 100644
index 0000000000..8705dea1ab
--- /dev/null
+++ b/dom/fetch/tests/browser.ini
@@ -0,0 +1,2 @@
+[DEFAULT]
+[browser_blobFromFile.js]
diff --git a/dom/fetch/tests/browser_blobFromFile.js b/dom/fetch/tests/browser_blobFromFile.js
new file mode 100644
index 0000000000..155f420477
--- /dev/null
+++ b/dom/fetch/tests/browser_blobFromFile.js
@@ -0,0 +1,62 @@
+add_task(async function test() {
+ await SpecialPowers.pushPrefEnv({
+ set: [["browser.tabs.remote.separateFileUriProcess", true]],
+ });
+
+ let fileData = "";
+ for (var i = 0; i < 100; ++i) {
+ fileData += "hello world!";
+ }
+
+ let file = Cc["@mozilla.org/file/directory_service;1"]
+ .getService(Ci.nsIDirectoryService)
+ .QueryInterface(Ci.nsIProperties)
+ .get("ProfD", Ci.nsIFile);
+ file.append("file.txt");
+ file.createUnique(Ci.nsIFile.NORMAL_FILE_TYPE, 0o600);
+
+ let outStream = Cc[
+ "@mozilla.org/network/file-output-stream;1"
+ ].createInstance(Ci.nsIFileOutputStream);
+ outStream.init(
+ file,
+ 0x02 | 0x08 | 0x20, // write, create, truncate
+ 0666,
+ 0
+ );
+ outStream.write(fileData, fileData.length);
+ outStream.close();
+
+ let fileHandler = Cc["@mozilla.org/network/io-service;1"]
+ .getService(Ci.nsIIOService)
+ .getProtocolHandler("file")
+ .QueryInterface(Ci.nsIFileProtocolHandler);
+
+ let fileURL = fileHandler.getURLSpecFromFile(file);
+
+ info("Opening url: " + fileURL);
+ let tab = BrowserTestUtils.addTab(gBrowser, fileURL);
+
+ let browser = gBrowser.getBrowserForTab(tab);
+ await BrowserTestUtils.browserLoaded(browser);
+
+ let blob = await SpecialPowers.spawn(browser, [file.leafName], function(
+ fileName
+ ) {
+ return new content.window.Promise(resolve => {
+ content.window
+ .fetch(fileName)
+ .then(r => r.blob())
+ .then(blob => resolve(blob));
+ });
+ });
+
+ ok(blob instanceof File, "We have a file");
+
+ is(blob.size, file.fileSize, "The size matches");
+ is(blob.name, file.leafName, "The name is correct");
+
+ file.remove(false);
+
+ gBrowser.removeTab(tab);
+});
diff --git a/dom/fetch/tests/crashtests/1577196.html b/dom/fetch/tests/crashtests/1577196.html
new file mode 100644
index 0000000000..a2cdae06d0
--- /dev/null
+++ b/dom/fetch/tests/crashtests/1577196.html
@@ -0,0 +1,26 @@
+<!DOCTYPE html>
+<html>
+<body>
+<script>
+
+function test() {
+ const xhr = new XMLHttpRequest();
+ const frame = document.createElement("frame");
+ document.documentElement.appendChild(frame);
+ const win = frame.contentWindow;
+ const div = document.createElement("div");
+ div.insertBefore(frame, div.childNodes[0]);
+ SpecialPowers.forceCC();
+ SpecialPowers.gc();
+ xhr.open("P", "", false);
+ xhr.send();
+ win.fetch(null, {}).then(function(arg14) {});
+}
+
+for (let i = 0; i < 10; i++) {
+ test();
+}
+
+</script>
+</body>
+</html>
diff --git a/dom/fetch/tests/crashtests/1664514.html b/dom/fetch/tests/crashtests/1664514.html
new file mode 100644
index 0000000000..dae325d2a7
--- /dev/null
+++ b/dom/fetch/tests/crashtests/1664514.html
@@ -0,0 +1,6 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<h3>Set <code>privacy.file_unique_origin</code> to false when testing this.</h3>
+<script>
+ fetch("./url.url")
+</script>
diff --git a/dom/fetch/tests/crashtests/crashtests.list b/dom/fetch/tests/crashtests/crashtests.list
new file mode 100644
index 0000000000..b3210cd4d8
--- /dev/null
+++ b/dom/fetch/tests/crashtests/crashtests.list
@@ -0,0 +1,2 @@
+load 1577196.html
+pref(privacy.file_unique_origin,false) load 1664514.html
diff --git a/dom/fetch/tests/crashtests/url.url b/dom/fetch/tests/crashtests/url.url
new file mode 100644
index 0000000000..95e9cf8db0
--- /dev/null
+++ b/dom/fetch/tests/crashtests/url.url
@@ -0,0 +1,5 @@
+[{000214A0-0000-0000-C000-000000000046}]
+Prop3=19,11
+[InternetShortcut]
+IDList=
+URL=http://localhost:8000/
diff --git a/dom/fetch/tests/mochitest.ini b/dom/fetch/tests/mochitest.ini
new file mode 100644
index 0000000000..32eb841faf
--- /dev/null
+++ b/dom/fetch/tests/mochitest.ini
@@ -0,0 +1,2 @@
+[test_ext_response_constructor.html]
+[test_invalid_header_exception.html]
diff --git a/dom/fetch/tests/test_ext_response_constructor.html b/dom/fetch/tests/test_ext_response_constructor.html
new file mode 100644
index 0000000000..adff6c78e9
--- /dev/null
+++ b/dom/fetch/tests/test_ext_response_constructor.html
@@ -0,0 +1,46 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+ <meta charset="utf-8">
+ <title>Test `Response` constructor in a WebExtension</title>
+ <script src="/tests/SimpleTest/SimpleTest.js"></script>
+ <script src="/tests/SimpleTest/ExtensionTestUtils.js"></script>
+ <link rel="stylesheet" href="/tests/SimpleTest/test.css"/>
+ <script>
+ add_task(async function testResponseConstructor() {
+ function contentScript() {
+ new Response();
+ browser.test.notifyPass("done");
+ }
+
+ const extension = ExtensionTestUtils.loadExtension({
+ manifest: {
+ content_scripts: [
+ {
+ matches: ["<all_urls>"],
+ js: ["content_script.js"],
+ },
+ ],
+ },
+
+ files: {
+ "content_script.js": contentScript,
+ },
+ });
+
+ await extension.startup();
+
+ const win = window.open("https://example.com");
+ await extension.awaitFinish("done");
+ win.close();
+
+ await extension.unload();
+ });
+ </script>
+</head>
+<body>
+<p id="display"></p>
+<div id="content" style="display: none"></div>
+<pre id="test"></pre>
+</body>
+</html>
diff --git a/dom/fetch/tests/test_invalid_header_exception.html b/dom/fetch/tests/test_invalid_header_exception.html
new file mode 100644
index 0000000000..274e85bb68
--- /dev/null
+++ b/dom/fetch/tests/test_invalid_header_exception.html
@@ -0,0 +1,39 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=1629390
+-->
+<head>
+ <title>Test for Bug 1629390</title>
+ <meta charset="UTF-8">
+ <script type="text/javascript" src="/MochiKit/MochiKit.js"></script>
+ <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+ <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
+</head>
+<body>
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1629390">Mozilla Bug 1629390</a>
+<p id="display"></p>
+<div id="content" style="display: none"></div>
+<pre id="test">
+<script class="testbody" type="text/javascript">
+
+/** Test for Bug 1629390 **/
+let headerNames = [
+ ['a˻b', 'a\uFFFD\uFFFDb'],
+ ['Àaª', '\uFFFDa\uFFFD'],
+ ['˻b', '\uFFFD\uFFFDb'],
+ ['\xEAa', '\uFFFDa'],
+ ['\xC2\x7F', '\uFFFD\x7F'],
+];
+for ([invalid, corrected] of headerNames) {
+ try {
+ new Headers([[invalid, '']]);
+ } catch(e) {
+ is(e.message, `Headers constructor: ${corrected} is an invalid header name.`);
+ }
+}
+
+</script>
+</pre>
+</body>
+</html>