1
    2
    3
    4
    5
    6
    7
    8
    9
   10
   11
   12
   13
   14
   15
   16
   17
   18
   19
   20
   21
   22
   23
   24
   25
   26
   27
   28
   29
   30
   31
   32
   33
   34
   35
   36
   37
   38
   39
   40
   41
   42
   43
   44
   45
   46
   47
   48
   49
   50

content / test / data / indexeddb / bug_346955148.js [blame]

// Copyright 2024 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// This is a regression test for crbug.com/346955148. It tests what happens when
// a getAll request is in the queue and the IndexedDBConnection is destroyed
// by way of the renderer dropping the mojo connection. Success occurs if the
// browser doesn't crash.

'use strict';

let connection;

function populateObjectStore() {
  connection = event.target.result;
  let store = connection.createObjectStore('store-name', null);
}

function createGetAllRequest() {
  const transaction = connection.transaction('store-name', 'readonly');
  const store = transaction.objectStore('store-name');
  const req = store.getAll();
  req.onerror = () => fail('getAll request should succeed');
  return req;
}

function createAddRequest() {
  const txn =
      connection.transaction('store-name', 'readwrite', {durability: 'strict'});
  txn.objectStore('store-name').add('value-X', '42');
}

function doTest() {
  createGetAllRequest().onsuccess = evt => {
    // Create a lot of slow requests, with one getAll() waiting behind them.
    for (let i = 0; i < 100; i++) {
      createAddRequest();
    }
    createGetAllRequest().onsuccess = evt => {
      assert_array_equals(evt.target.result, ['value-X']);
    };
    connection = null;
    gc();
    done();
  };
}

function test() {
  indexedDBTest(populateObjectStore, doTest);
}