Quellcodebibliothek Statistik Leitseite products/sources/formale Sprachen/C/Firefox/services/sync/tests/tps/   (Browser von der Mozilla Stiftung Version 136.0.1©)  Datei vom 10.2.2025 mit Größe 1 kB image not shown  

Quelle  test_ioutils_remove.html   Sprache: HTML

 
 products/Sources/formale Sprachen/C/Firefox/dom/system/tests/ioutils/test_ioutils_remove.html


<!-- Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ -->

<!DOCTYPE HTML>
<html>

<head>
  <meta charset="utf-8">
  <title>Test the IOUtils file I/O API</title>
  <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
  <link rel="stylesheet" href="chrome://mochikit/content/tests/SimpleTest/test.css" />
  <script src="file_ioutils_test_fixtures.js"></script>
  <script>
    "use strict";

    const { Assert } = ChromeUtils.importESModule(
      "resource://testing-common/Assert.sys.mjs"
    );

    add_task(async function test_create_and_remove_file() {
      info("Test creating and removing a single file");
      const tmpFileName = PathUtils.join(PathUtils.tempDir, "test_ioutils_create_and_remove.tmp");
      await IOUtils.write(tmpFileName, new Uint8Array(0));
      ok(await fileExists(tmpFileName), `Expected file ${tmpFileName} to exist`);

      await IOUtils.remove(tmpFileName);
      ok(!await fileExists(tmpFileName), "IOUtils::remove can remove files");

      info("Test creating and removing an empty directory");
      const tempDirName = PathUtils.join(PathUtils.tempDir, "test_ioutils_create_and_remove.tmp.d");
      await IOUtils.makeDirectory(tempDirName);
      ok(await dirExists(tempDirName), `Expected directory ${tempDirName} to exist`);

      await IOUtils.remove(tempDirName);
      ok(!await dirExists(tempDirName), "IOUtils::remove can remove empty directories");
    });

    add_task(async function test_remove_non_existing() {
      const tmpFileName = PathUtils.join(PathUtils.tempDir, "test_ioutil_remove_non_existing.tmp");
      ok(!await fileExists(tmpFileName), `Expected file ${tmpFileName} not to exist`);

      await IOUtils.remove(tmpFileName, { ignoreAbsent: true });
      ok(!await fileExists(tmpFileName), "IOUtils::remove can ignore missing files without error");

      await Assert.rejects(
        IOUtils.remove(tmpFileName, { ignoreAbsent: false }),
        /NotFoundError: Could not remove `.*': file does not exist/,
        "IOUtils::remove can throw an error when target file is missing"
      );
      ok(!await fileExists(tmpFileName), `Expected file ${tmpFileName} not to exist`);
    });

    add_task(async function test_remove_recursive() {
      const tmpParentDir = PathUtils.join(PathUtils.tempDir, "test_ioutils_remove.tmp.d");
      const tmpChildDir = PathUtils.join(tmpParentDir, "child.tmp.d");
      const tmpTopLevelFileName = PathUtils.join(tmpParentDir, "top.tmp");
      const tmpNestedFileName = PathUtils.join(tmpChildDir, "nested.tmp");
      await createDir(tmpChildDir);
      await createFile(tmpTopLevelFileName, "");
      await createFile(tmpNestedFileName, "");

      ok(
        await fileExists(tmpTopLevelFileName),
        `Expected file ${tmpTopLevelFileName} to exist`
      );
      ok(
        await fileExists(tmpNestedFileName),
        `Expected file  ${tmpNestedFileName} to exist`
      );

      await Assert.rejects(
        IOUtils.remove(tmpParentDir, { recursive: false }),
        /OperationError: Could not remove `.*': the directory is not empty/,
        "IOUtils::remove fails if non-recursively removing directory with contents"
      );

      await IOUtils.remove(tmpParentDir, { recursive: true });
      ok(
        !await dirExists(tmpParentDir),
        "IOUtils::remove can recursively remove a directory"
      );
    });

    if (Services.appinfo.OS === "WINNT") {
      add_task(async function test_remove_retry_readonly() {

        const tmpDir = PathUtils.join(PathUtils.tempDir, "test_ioutils_remove_retry_readonly.tmp.d");
        const path = PathUtils.join(tmpDir, "file.txt");

        await createDir(tmpDir);
        await createFile(path, "");

        await IOUtils.setWindowsAttributes(path, { readOnly: true });

        await Assert.rejects(
          IOUtils.remove(path),
          /NotAllowedError/,
          "Cannot remove a readonly file by default"
        );

        Assert.ok(await fileExists(path), "File should still exist");

        await IOUtils.remove(path, { retryReadonly: true });

        Assert.ok(!await fileExists(path), "File should not exist");

        await IOUtils.remove(tmpDir);
      });
    }
  </script>
</head>

<body>
  <p id="display"></p>
  <div id="content" style="display: none"></div>
  <pre id="test"></pre>
</body>

</html>

Messung V0.5
C=97 H=76 G=86

¤ Dauer der Verarbeitung: 0.14 Sekunden  (vorverarbeitet)  ¤

*© Formatika GbR, Deutschland






Wurzel

Suchen

Beweissystem der NASA

Beweissystem Isabelle

NIST Cobol Testsuite

Cephes Mathematical Library

Wiener Entwicklungsmethode

Haftungshinweis

Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.

Bemerkung:

Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.