summaryrefslogtreecommitdiffstats
path: root/testing/mochitest/tests/Harness_sanity/test_createFiles.html
diff options
context:
space:
mode:
authorMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
committerMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
commit5f8de423f190bbb79a62f804151bc24824fa32d8 (patch)
tree10027f336435511475e392454359edea8e25895d /testing/mochitest/tests/Harness_sanity/test_createFiles.html
parent49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff)
downloadUXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip
Add m-esr52 at 52.6.0
Diffstat (limited to 'testing/mochitest/tests/Harness_sanity/test_createFiles.html')
-rw-r--r--testing/mochitest/tests/Harness_sanity/test_createFiles.html91
1 files changed, 91 insertions, 0 deletions
diff --git a/testing/mochitest/tests/Harness_sanity/test_createFiles.html b/testing/mochitest/tests/Harness_sanity/test_createFiles.html
new file mode 100644
index 000000000..502592acc
--- /dev/null
+++ b/testing/mochitest/tests/Harness_sanity/test_createFiles.html
@@ -0,0 +1,91 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+ <title>Test for SpecialPowers.createFiles</title>
+ <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+ <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
+</head>
+<body>
+
+<div id="content" class="testbody">
+ <script type="text/javascript">
+ // Creating one file, followed by failing to create a file.
+ function test1() {
+ const fileType = "some file type";
+ let fdata = "this is same data for a file";
+ SpecialPowers.createFiles([{name: "test1.txt", data:fdata, options:{type:fileType}}],
+ function (files) {
+ is(files.length, 1, "Created 1 file");
+ let f = files[0];
+ is("[object File]", f.toString(), "first thing in array is a file");
+ is(f.size, fdata.length, "test1 size of first file should be length of its data");
+ is("test1.txt", f.name, "test1 test file should have the right name");
+ is(f.type, fileType, "File should have the specified type");
+ test2();
+ },
+ function (msg) { ok(false, "Should be able to create a file without an error"); test2(); }
+ );
+ }
+
+ // Failing to create a file, followed by creating a file.
+ function test2() {
+ function test3Check(passed) {
+ ok(passed, "Should trigger the error handler for a bad file name.");
+ test3();
+ };
+
+ SpecialPowers.createFiles([{name: "/\/\/\/\/\/\/\/\/\/\/\invalidname",}],
+ function () { test3Check(false); },
+ function (msg) { test3Check(true); }
+ );
+ }
+
+ // Creating two files at the same time.
+ function test3() {
+ let f1data = "hello";
+ SpecialPowers.createFiles([{name: "test3_file.txt", data:f1data}, {name: "emptyfile.txt"}],
+ function (files) {
+ is(files.length, 2, "Expected two files to be created");
+ let f1 = files[0];
+ let f2 = files[1];
+ is("[object File]", f1.toString(), "first thing in array is a file");
+ is("[object File]", f2.toString(), "second thing in array is a file");
+ is("test3_file.txt", f1.name, "first test3 test file should have the right name");
+ is("emptyfile.txt", f2.name, "second test3 test file should have the right name");
+ is(f1.size, f1data.length, "size of first file should be length of its data");
+ is(f2.size, 0, "size of second file should be 0");
+ test4();
+ },
+ function (msg) {
+ ok(false, "Failed to create files: " + msg);
+ test4();
+ }
+ );
+ };
+
+ // Creating a file without specifying a name should work.
+ function test4() {
+ let fdata = "this is same data for a file";
+ SpecialPowers.createFiles([{data:fdata}],
+ function (files) {
+ is(files.length, 1, "Created 1 file");
+ let f = files[0];
+ is("[object File]", f.toString(), "first thing in array is a file");
+ is(f.size, fdata.length, "test4 size of first file should be length of its data");
+ ok(f.name, "test4 test file should have a name");
+ SimpleTest.finish();
+ },
+ function (msg) {
+ ok(false, "Should be able to create a file without a name without an error");
+ SimpleTest.finish();
+ }
+ );
+ }
+
+ SimpleTest.waitForExplicitFinish();
+ test1();
+
+ </script>
+</div>
+</body>
+</html>