dom/filehandle/test/test_location.html
author Jan Varga <jan.varga@gmail.com>
Wed, 07 May 2014 16:32:12 +0200
changeset 201268 03fdda1af1f4fc0bdf7bd71c765b89216a5a2737
parent 150375 dom/file/test/test_location.html@c6ecfbeb6553f84a823f2d1f23b126df18bce952
child 209075 00d924bed2d1be6252ba8aa4c0c66a4d7baf2a71
permissions -rw-r--r--
Bug 975696 - Split ArchiveReader and FileHandle implementation into separate dirs. r=bent f=baku

<!--
  Any copyright is dedicated to the Public Domain.
  http://creativecommons.org/publicdomain/zero/1.0/
-->
<html>
<head>
  <title>File Handle Test</title>

  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>

  <script type="text/javascript;version=1.7">
  function testSteps()
  {
    for each (let fileStorage in fileStorages) {
      let request = getFileHandle(fileStorage.key, "test.txt");
      request.onerror = errorHandler;
      request.onsuccess = grabEventAndContinueHandler;
      let event = yield undefined;

      let fileHandle = event.target.result;
      fileHandle.onerror = errorHandler;

      let lockedFile = fileHandle.open("readwrite");
      is(lockedFile.location, 0, "Correct location");

      lockedFile.location = 100000;
      is(lockedFile.location, 100000, "Correct location");

      lockedFile.location = null;
      ok(lockedFile.location === null, "Correct location");

      try {
        lockedFile.readAsArrayBuffer(1);
        ok(false, "Should have thrown!");
      }
      catch (e) {
        ok(e instanceof DOMException, "Got exception.");
        is(e.name, "InvalidStateError", "Good error.");
        is(e.code, DOMException.INVALID_STATE_ERR, "Good error code.");
      }

      try {
        lockedFile.readAsText(1);
        ok(false, "Should have thrown!");
      }
      catch (e) {
        ok(e instanceof DOMException, "Got exception.");
        is(e.name, "InvalidStateError", "Good error.");
        is(e.code, DOMException.INVALID_STATE_ERR, "Good error code.");
      }

      try {
        lockedFile.write({});
        ok(false, "Should have thrown!");
      }
      catch (e) {
        ok(e instanceof DOMException, "Got exception.");
        is(e.name, "InvalidStateError", "Good error.");
        is(e.code, DOMException.INVALID_STATE_ERR, "Good error code.");
      }

      request = lockedFile.append("foo");
      request.onsuccess = grabEventAndContinueHandler;
      event = yield undefined;

      ok(lockedFile.location === null, "Correct location");

      try {
        lockedFile.truncate();
        ok(false, "Should have thrown!");
      }
      catch (e) {
        ok(e instanceof DOMException, "Got exception.");
        is(e.name, "InvalidStateError", "Good error.");
        is(e.code, DOMException.INVALID_STATE_ERR, "Good error code.");
      }

      request = lockedFile.truncate(0);
      request.onsuccess = grabEventAndContinueHandler;
      event = yield undefined;

      is(lockedFile.location, 0, "Correct location");
    }

    finishTest();
    yield undefined;
  }
  </script>
  <script type="text/javascript;version=1.7" src="helpers.js"></script>

</head>

<body onload="runTest();"></body>

</html>