testing/mochitest/tests/browser/browser_getTestFile.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/testing/mochitest/tests/browser/browser_getTestFile.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,44 @@
     1.4 +function test() {
     1.5 +  let {Promise} = Components.utils.import("resource://gre/modules/Promise.jsm");
     1.6 +  Components.utils.import("resource://gre/modules/osfile.jsm");
     1.7 +  let decoder = new TextDecoder();
     1.8 +
     1.9 +  waitForExplicitFinish();
    1.10 +
    1.11 +  SimpleTest.doesThrow(function () {
    1.12 +    getTestFilePath("/browser_getTestFile.js")
    1.13 +  }, "getTestFilePath rejects absolute paths");
    1.14 +
    1.15 +  Promise.all([
    1.16 +    OS.File.exists(getTestFilePath("browser_getTestFile.js"))
    1.17 +      .then(function (exists) {
    1.18 +        ok(exists, "getTestFilePath consider the path as being relative");
    1.19 +      }),
    1.20 +
    1.21 +    OS.File.exists(getTestFilePath("./browser_getTestFile.js"))
    1.22 +      .then(function (exists) {
    1.23 +        ok(exists, "getTestFilePath also accepts explicit relative path");
    1.24 +      }),
    1.25 +
    1.26 +    OS.File.exists(getTestFilePath("./browser_getTestFileTypo.xul"))
    1.27 +      .then(function (exists) {
    1.28 +        ok(!exists, "getTestFilePath do not throw if the file doesn't exists");
    1.29 +      }),
    1.30 +
    1.31 +    OS.File.read(getTestFilePath("test-dir/test-file"))
    1.32 +      .then(function (array) {
    1.33 +        is(decoder.decode(array), "foo\n", "getTestFilePath can reach sub-folder files 1/2");
    1.34 +      }),
    1.35 +
    1.36 +    OS.File.read(getTestFilePath("./test-dir/test-file"))
    1.37 +      .then(function (array) {
    1.38 +        is(decoder.decode(array), "foo\n", "getTestFilePath can reach sub-folder files 2/2");
    1.39 +      })
    1.40 +
    1.41 +  ]).then(function () {
    1.42 +    finish();
    1.43 +  }, function (error) {
    1.44 +    ok(false, error);
    1.45 +    finish();
    1.46 +  });
    1.47 +}

mercurial