testing/mochitest/chrome/test_chromeGetTestFile.xul

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/testing/mochitest/chrome/test_chromeGetTestFile.xul	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,55 @@
     1.4 +<?xml version="1.0"?>
     1.5 +<!-- This Source Code Form is subject to the terms of the Mozilla Public
     1.6 +   - License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 +   - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
     1.8 +<?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css"
     1.9 +                 type="text/css"?>
    1.10 +<window title="Test chrome harness functions"
    1.11 +        xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
    1.12 +  <script type="application/javascript"
    1.13 +          src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
    1.14 +  <script type="application/javascript" src="chrome://mochikit/content/chrome-harness.js"></script>
    1.15 +  <script type="application/javascript">
    1.16 +  <![CDATA[
    1.17 +    let {Promise} = Components.utils.import("resource://gre/modules/Promise.jsm");
    1.18 +    Components.utils.import("resource://gre/modules/osfile.jsm");
    1.19 +    let decoder = new TextDecoder();
    1.20 +
    1.21 +    SimpleTest.waitForExplicitFinish();
    1.22 +
    1.23 +    SimpleTest.doesThrow(function () {
    1.24 +      getTestFilePath("/test_chromeGetTestFile.xul")
    1.25 +    }, "getTestFilePath rejects absolute paths");
    1.26 +
    1.27 +    Promise.all([
    1.28 +      OS.File.exists(getTestFilePath("test_chromeGetTestFile.xul"))
    1.29 +        .then(function (exists) {
    1.30 +          ok(exists, "getTestFilePath consider the path as being relative");
    1.31 +        }),
    1.32 +
    1.33 +      OS.File.exists(getTestFilePath("./test_chromeGetTestFile.xul"))
    1.34 +        .then(function (exists) {
    1.35 +          ok(exists, "getTestFilePath also accepts explicit relative path");
    1.36 +        }),
    1.37 +
    1.38 +      OS.File.exists(getTestFilePath("./test_chromeGetTestFileTypo.xul"))
    1.39 +        .then(function (exists) {
    1.40 +          ok(!exists, "getTestFilePath do not throw if the file doesn't exists");
    1.41 +        }),
    1.42 +
    1.43 +      OS.File.read(getTestFilePath("test-dir/test-file"))
    1.44 +        .then(function (array) {
    1.45 +          is(decoder.decode(array), "foo\n", "getTestFilePath can reach sub-folder files 1/2");
    1.46 +        }),
    1.47 +
    1.48 +      OS.File.read(getTestFilePath("./test-dir/test-file"))
    1.49 +        .then(function (array) {
    1.50 +          is(decoder.decode(array), "foo\n", "getTestFilePath can reach sub-folder files 2/2");
    1.51 +        })
    1.52 +
    1.53 +    ]).then(function () {
    1.54 +      SimpleTest.finish();
    1.55 +    }, console.error);
    1.56 +  ]]>
    1.57 +  </script>
    1.58 +</window>

mercurial