summaryrefslogtreecommitdiffstats
path: root/toolkit/components/osfile/tests/xpcshell/test_unique.js
diff options
context:
space:
mode:
authorwolfbeast <mcwerewolf@wolfbeast.com>2020-04-14 21:49:04 +0200
committerwolfbeast <mcwerewolf@wolfbeast.com>2020-04-14 21:49:04 +0200
commit39dac57259cff8b61db0b22cb2ad0a8adb02692e (patch)
tree52a026cc8c22793eb17fd0f5e22adce1ae08a1dd /toolkit/components/osfile/tests/xpcshell/test_unique.js
parenta1cce3b2b00bbd9f4983013ddd8934a7bccb9e99 (diff)
parentc2d9ab62f3d097c9e0e00184cab1f546554f5eaa (diff)
downloadUXP-39dac57259cff8b61db0b22cb2ad0a8adb02692e.tar
UXP-39dac57259cff8b61db0b22cb2ad0a8adb02692e.tar.gz
UXP-39dac57259cff8b61db0b22cb2ad0a8adb02692e.tar.lz
UXP-39dac57259cff8b61db0b22cb2ad0a8adb02692e.tar.xz
UXP-39dac57259cff8b61db0b22cb2ad0a8adb02692e.zip
Merge branch 'redwood' into 28.9-platform
Diffstat (limited to 'toolkit/components/osfile/tests/xpcshell/test_unique.js')
-rw-r--r--toolkit/components/osfile/tests/xpcshell/test_unique.js88
1 files changed, 0 insertions, 88 deletions
diff --git a/toolkit/components/osfile/tests/xpcshell/test_unique.js b/toolkit/components/osfile/tests/xpcshell/test_unique.js
deleted file mode 100644
index 8aa81b803..000000000
--- a/toolkit/components/osfile/tests/xpcshell/test_unique.js
+++ /dev/null
@@ -1,88 +0,0 @@
-"use strict";
-
-Components.utils.import("resource://gre/modules/osfile.jsm");
-Components.utils.import("resource://gre/modules/Task.jsm");
-
-function run_test() {
- do_get_profile();
- run_next_test();
-}
-
-function testFiles(filename) {
- return Task.spawn(function() {
- const MAX_TRIES = 10;
- let profileDir = OS.Constants.Path.profileDir;
- let path = OS.Path.join(profileDir, filename);
-
- // Ensure that openUnique() uses the file name if there is no file with that name already.
- let openedFile = yield OS.File.openUnique(path);
- do_print("\nCreate new file: " + openedFile.path);
- yield openedFile.file.close();
- let exists = yield OS.File.exists(openedFile.path);
- do_check_true(exists);
- do_check_eq(path, openedFile.path);
- let fileInfo = yield OS.File.stat(openedFile.path);
- do_check_true(fileInfo.size == 0);
-
- // Ensure that openUnique() creates a new file name using a HEX number, as the original name is already taken.
- openedFile = yield OS.File.openUnique(path);
- do_print("\nCreate unique HEX file: " + openedFile.path);
- yield openedFile.file.close();
- exists = yield OS.File.exists(openedFile.path);
- do_check_true(exists);
- fileInfo = yield OS.File.stat(openedFile.path);
- do_check_true(fileInfo.size == 0);
-
- // Ensure that openUnique() generates different file names each time, using the HEX number algorithm
- let filenames = new Set();
- for (let i=0; i < MAX_TRIES; i++) {
- openedFile = yield OS.File.openUnique(path);
- yield openedFile.file.close();
- filenames.add(openedFile.path);
- }
-
- do_check_eq(filenames.size, MAX_TRIES);
-
- // Ensure that openUnique() creates a new human readable file name using, as the original name is already taken.
- openedFile = yield OS.File.openUnique(path, {humanReadable : true});
- do_print("\nCreate unique Human Readable file: " + openedFile.path);
- yield openedFile.file.close();
- exists = yield OS.File.exists(openedFile.path);
- do_check_true(exists);
- fileInfo = yield OS.File.stat(openedFile.path);
- do_check_true(fileInfo.size == 0);
-
- // Ensure that openUnique() generates different human readable file names each time
- filenames = new Set();
- for (let i=0; i < MAX_TRIES; i++) {
- openedFile = yield OS.File.openUnique(path, {humanReadable : true});
- yield openedFile.file.close();
- filenames.add(openedFile.path);
- }
-
- do_check_eq(filenames.size, MAX_TRIES);
-
- let exn;
- try {
- for (let i=0; i < 100; i++) {
- openedFile = yield OS.File.openUnique(path, {humanReadable : true});
- yield openedFile.file.close();
- }
- } catch (ex) {
- exn = ex;
- }
-
- do_print("Ensure that this raises the correct error");
- do_check_true(!!exn);
- do_check_true(exn instanceof OS.File.Error);
- do_check_true(exn.becauseExists);
- });
-}
-
-add_task(function test_unique() {
- OS.Shared.DEBUG = true;
- // Tests files with extension
- yield testFiles("dummy_unique_file.txt");
- // Tests files with no extension
- yield testFiles("dummy_unique_file_no_ext");
-});