testing/mochitest/tests/browser/browser_getTestFile.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     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();
     6   waitForExplicitFinish();
     8   SimpleTest.doesThrow(function () {
     9     getTestFilePath("/browser_getTestFile.js")
    10   }, "getTestFilePath rejects absolute paths");
    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       }),
    18     OS.File.exists(getTestFilePath("./browser_getTestFile.js"))
    19       .then(function (exists) {
    20         ok(exists, "getTestFilePath also accepts explicit relative path");
    21       }),
    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       }),
    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       }),
    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       })
    38   ]).then(function () {
    39     finish();
    40   }, function (error) {
    41     ok(false, error);
    42     finish();
    43   });
    44 }

mercurial