Anforderungen  |   Konzepte  |   Entwurf  |   Entwicklung  |   Qualitätssicherung  |   Lebenszyklus  |   Steuerung
 
 
 
 


Quelle  name-scopes.html   Sprache: HTML

 
 products/sources/formale Sprachen/C/Firefox/testing/web-platform/tests/IndexedDB/name-scopes.html


<!doctype html>
<meta charset="utf-8">
<title>
  IndexedDB: scoping for database / object store / index names, and index keys
</title>
<link rel="help" href="https://w3c.github.io/IndexedDB/#constructs">
<link rel="author" href="pwnall@chromium.org" title="Victor Costan">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="resources/support-promises.js"></script>
<script>
'use strict';

// Creates the structure inside a test database.
//
// The structure includes two stores with identical indexes and nearly-similar
// records. The records differ in the "path" attribute values, which are used to
// verify that IndexedDB returns the correct records when queried.
//
// databaseName appears redundant, but we don't want to rely on database.name.
const buildStores = (database, databaseName, useUniqueKeys) => {
  for (let storeName of ['x''y']) {
    const store = database.createObjectStore(
        storeName, { keyPath: 'pKey', autoIncrement: true });
    for (let indexName of ['x''y']) {
      store.createIndex(
          indexName, `${indexName}Key`, { unique: useUniqueKeys });
    }

    for (let xKeyRoot of ['x''y']) {
      for (let yKeyRoot of ['x''y']) {
        let xKey, yKey;
        if (useUniqueKeys) {
          xKey = `${xKeyRoot}${yKeyRoot}`;
          yKey = `${yKeyRoot}${xKeyRoot}`;
        } else {
          xKey = xKeyRoot;
          yKey = yKeyRoot;
        }
        const path = `${databaseName}-${storeName}-${xKeyRoot}-${yKeyRoot}`;
        store.put({ xKey: xKey, yKey: yKey, path: path });
      }
    }
  }
};

// Creates two databases with identical structures.
const buildDatabases = (testCase, useUniqueKeys) => {
  return createNamedDatabase(
      testCase, 'x', database => buildStores(database, 'x', useUniqueKeys))
      .then(database => database.close())
      .then(() => createNamedDatabase(
          testCase, 'y', database => buildStores(database, 'y', useUniqueKeys)))
      .then(database => database.close());
};

// Reads all the store's values using an index.
//
// Returns a Promise that resolves with an array of values.
const readIndex = (testCase, index) => {
  return new Promise((resolve, reject) => {
    const results = [];
    const request = index.openCursor(IDBKeyRange.bound('a''z'), 'next');
    request.onsuccess = () => {
      const cursor = request.result;
      if (cursor) {
        results.push(cursor.value);
        cursor.continue();
      } else {
        resolve(results);
      }
    }
  });
}

// Verifies that a database contains the expected records.
const checkDatabaseContent =
    (testCase, database, databaseName, usedUniqueKeys) => {
  const promises = [];
  const transaction = database.transaction(['x''y'], 'readonly');
  for (let storeName of ['x''y']) {
    const store = transaction.objectStore(storeName);
    for (let indexName of ['x''y']) {
      const index = store.index(indexName);

      const promise = readIndex(testCase, index).then((results) => {
        assert_array_equals(
            results.map(result => `${result.path}:${result.pKey}`).sort(),
            [`${databaseName}-${storeName}-x-x:1`,
             `${databaseName}-${storeName}-x-y:2`,
             `${databaseName}-${storeName}-y-x:3`,
             `${databaseName}-${storeName}-y-y:4`],
            'The results should include all records put into the store');

        let expectedKeys = (usedUniqueKeys) ?
            ['xx:xx''xy:yx''yx:xy''yy:yy'] : ['x:x''x:y''y:x''y:y'];
        assert_array_equals(
            results.map(result => `${result.xKey}:${result.yKey}`).sort(),
            expectedKeys,
            'The results should include all the index keys put in the store');

        assert_array_equals(
            results.map(result => result[`${indexName}Key`]),
            results.map(result => result[`${indexName}Key`]).sort(),
            'The results should be sorted by the index key');
      });
      promises.push(promise);
    }
  }

  return Promise.all(promises).then(() => database);
}

promise_test(testCase => {
  return buildDatabases(testCase, false)
      .then(() => openNamedDatabase(testCase, 'x', 1))
      .then(database => checkDatabaseContent(testCase, database, 'x', false))
      .then(database => database.close())
      .then(() => openNamedDatabase(testCase, 'y', 1))
      .then(database => checkDatabaseContent(testCase, database, 'y', false))
      .then(database => database.close());
}, 'Non-unique index keys');

promise_test(testCase => {
  return buildDatabases(testCase, true)
      .then(() => openNamedDatabase(testCase, 'x', 1))
      .then(database => checkDatabaseContent(testCase, database, 'x', true))
      .then(database => database.close())
      .then(() => openNamedDatabase(testCase, 'y', 1))
      .then(database => checkDatabaseContent(testCase, database, 'y', true))
      .then(database => database.close());
}, 'Unique index keys');

</script>

Messung V0.5
C=93 H=100 G=96

¤ Dauer der Verarbeitung: 0.1 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.






                                                                                                                                                                                                                                                                                                                                                                                                     


Neuigkeiten

     Aktuelles
     Motto des Tages

Software

     Produkte
     Quellcodebibliothek

Aktivitäten

     Artikel über Sicherheit
     Anleitung zur Aktivierung von SSL

Muße

     Gedichte
     Musik
     Bilder

Jenseits des Üblichen ....
    

Besucherstatistik

Besucherstatistik

Monitoring

Montastic status badge