testing/mochitest/tests/browser/browser_getTestFile.js

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:707b900a7de2
1 function test() {
2 let {Promise} = Components.utils.import("resource://gre/modules/Promise.jsm");
3 Components.utils.import("resource://gre/modules/osfile.jsm");
4 let decoder = new TextDecoder();
5
6 waitForExplicitFinish();
7
8 SimpleTest.doesThrow(function () {
9 getTestFilePath("/browser_getTestFile.js")
10 }, "getTestFilePath rejects absolute paths");
11
12 Promise.all([
13 OS.File.exists(getTestFilePath("browser_getTestFile.js"))
14 .then(function (exists) {
15 ok(exists, "getTestFilePath consider the path as being relative");
16 }),
17
18 OS.File.exists(getTestFilePath("./browser_getTestFile.js"))
19 .then(function (exists) {
20 ok(exists, "getTestFilePath also accepts explicit relative path");
21 }),
22
23 OS.File.exists(getTestFilePath("./browser_getTestFileTypo.xul"))
24 .then(function (exists) {
25 ok(!exists, "getTestFilePath do not throw if the file doesn't exists");
26 }),
27
28 OS.File.read(getTestFilePath("test-dir/test-file"))
29 .then(function (array) {
30 is(decoder.decode(array), "foo\n", "getTestFilePath can reach sub-folder files 1/2");
31 }),
32
33 OS.File.read(getTestFilePath("./test-dir/test-file"))
34 .then(function (array) {
35 is(decoder.decode(array), "foo\n", "getTestFilePath can reach sub-folder files 2/2");
36 })
37
38 ]).then(function () {
39 finish();
40 }, function (error) {
41 ok(false, error);
42 finish();
43 });
44 }

mercurial