Quellcodebibliothek Statistik Leitseite products/Sources/formale Sprachen/C/Firefox/dom/indexedDB/test/   (Browser von der Mozilla Stiftung Version 136.0.1©)  Datei vom 10.2.2025 mit Größe 3 kB image not shown  

Quelle  test_blob_worker_xhr_read_slice.html   Sprache: HTML

 
 products/Sources/formale Sprachen/C/Firefox/dom/indexedDB/test/test_blob_worker_xhr_read_slice.html


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

<html>
<head>
  <title>Indexed Database Blob Read From Worker</title>

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

  <script type="text/javascript">
  /**
   * Create an IndexedDB-backed Blob, send it to the worker, try and read the
   * *SLICED* contents of the Blob from the worker using an XHR.  This is
   * (as of the time of writing this) basically the same as
   * test_blob_worker_xhr_read.html but with slicing added.
   */
  function* testSteps()
  {
    const BLOB_DATA = ["Green"];
    const BLOB_TYPE = "text/plain";
    const BLOB_SIZE = BLOB_DATA.join("").length;

    info("Setting up");

    let request = indexedDB.open(window.location.pathname, 1);
    request.onerror = errorHandler;
    request.onupgradeneeded = grabEventAndContinueHandler;
    request.onsuccess = unexpectedSuccessHandler;
    let event = yield undefined;

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

    ok(db, "Created database");

    info("Creating objectStore");

    let objectStore = db.createObjectStore("foo", { autoIncrement: true });

    request.onupgradeneeded = unexpectedSuccessHandler;
    request.onsuccess = grabEventAndContinueHandler;
    event = yield undefined;

    ok(true, "Opened database");

    let blob = new Blob(BLOB_DATA, { type: BLOB_TYPE });

    info("Adding blob to database");

    objectStore = db.transaction("foo""readwrite").objectStore("foo");
    objectStore.add(blob).onsuccess = grabEventAndContinueHandler;
    event = yield undefined;

    let blobKey = event.target.result;
    ok(blobKey, "Got a key for the blob");

    info("Getting blob from the database");

    objectStore = db.transaction("foo").objectStore("foo");
    objectStore.get(blobKey).onsuccess = grabEventAndContinueHandler;
    event = yield undefined;

    blob = event.target.result;

    ok(blob instanceof Blob, "Got a blob");
    is(blob.size, BLOB_SIZE, "Correct size");
    is(blob.type, BLOB_TYPE, "Correct type");

    info("Sending blob to a worker");

    function workerScript() {
      /* eslint-env worker */
      onmessage = function(event) {
        var blob = event.data;
        var slicedBlob = blob.slice(0, 3, "text/plain");
        var blobUrl = URL.createObjectURL(slicedBlob);
        var xhr = new XMLHttpRequest();
        xhr.open("GET", blobUrl, true);
        xhr.responseType = "text";
        xhr.onload = function() {
          postMessage({ data: xhr.response });
          URL.revokeObjectURL(blobUrl);
        };
        xhr.onerror = function() {
          postMessage({ data: null });
          URL.revokeObjectURL(blobUrl);
        };
        xhr.send();
      };
    }

    let workerScriptUrl =
      URL.createObjectURL(new Blob(["(", workerScript.toString(), ")()"]));

    let xhrWorker = new Worker(workerScriptUrl);
    xhrWorker.postMessage(blob);
    xhrWorker.onmessage = grabEventAndContinueHandler;
    event = yield undefined;

    is(event.data.data, "Gre""XHR returned expected sliced payload.");
    xhrWorker.terminate();

    URL.revokeObjectURL(workerScriptUrl);

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

</head>

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

</html>

Messung V0.5
C=93 H=94 G=93

¤ Dauer der Verarbeitung: 0.3 Sekunden  ¤

*© 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.