tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

idbcursor-source.any.js (1852B)


      1 // META: global=window,worker
      2 // META: title=IDBCursor.source
      3 // META: script=resources/support.js
      4 
      5 'use strict';
      6 
      7 function cursor_source_test(
      8    test_name, name, stringified_object, cursor_rq_func) {
      9  indexeddb_test(
     10      function(t, db, tx) {
     11        const objStore = db.createObjectStore('my_objectstore');
     12        objStore.createIndex('my_index', '');
     13 
     14        objStore.add('data', 1);
     15        objStore.add('data2', 2);
     16      },
     17      function(t, db) {
     18        const cursor_rq = cursor_rq_func(db);
     19 
     20        cursor_rq.onsuccess = t.step_func((e) => {
     21          if (!e.target.result) {
     22            return;
     23          }
     24          const cursor = e.target.result;
     25          assert_readonly(cursor, 'source');
     26 
     27          // Direct try
     28          assert_true(cursor.source instanceof Object, 'source isobject');
     29          assert_equals(cursor.source + '', stringified_object, 'source');
     30          assert_equals(cursor.source.name, name, 'name');
     31 
     32          cursor.continue();
     33        });
     34 
     35        cursor_rq.transaction.oncomplete = t.step_func((e) => {
     36          t.done();
     37        });
     38 
     39        cursor_rq.transaction.onerror = t.step_func((e) => {
     40          assert_unreached(
     41              'Transaction got error. ' +
     42              (e.target.error ? e.target.error.name : 'unknown'));
     43        });
     44      },
     45      test_name);
     46 }
     47 
     48 cursor_source_test(
     49    'IDBCursor.source - IDBObjectStore', 'my_objectstore',
     50    '[object IDBObjectStore]', function(db) {
     51      return db.transaction('my_objectstore', 'readonly')
     52          .objectStore('my_objectstore')
     53          .openCursor();
     54    });
     55 
     56 cursor_source_test(
     57    'IDBCursor.source - IDBIndex', 'my_index', '[object IDBIndex]',
     58    function(db) {
     59      return db.transaction('my_objectstore', 'readonly')
     60          .objectStore('my_objectstore')
     61          .index('my_index')
     62          .openCursor();
     63    });