File: idbobjectstore_putall.tentative.any.js

package info (click to toggle)
firefox-esr 91.13.0esr-1~deb11u1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 3,375,652 kB
  • sloc: cpp: 5,762,054; javascript: 5,481,714; ansic: 3,121,191; python: 851,492; asm: 331,172; xml: 178,949; java: 155,554; sh: 63,704; makefile: 20,127; perl: 12,825; yacc: 4,583; cs: 3,846; objc: 3,026; lex: 1,720; exp: 762; pascal: 635; php: 436; lisp: 260; awk: 231; ruby: 103; sed: 53; sql: 46; csh: 45
file content (180 lines) | stat: -rw-r--r-- 7,286 bytes parent folder | download | duplicates (4)
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
// META: script=support-promises.js

promise_test(async testCase => {
  const db = await createDatabase(testCase, db => {
    const store = createBooksStore(testCase, db);
  });
  const txn = db.transaction(['books'], 'readwrite');
  const objectStore = txn.objectStore('books');
  const values = [
    {isbn: 'one', title: 'title1'},
    {isbn: 'two', title: 'title2'},
    {isbn: 'three', title: 'title3'}
  ];
  const putAllRequest = objectStore.putAllValues(values);
  // TODO(nums): Check that correct keys are returned.
  await promiseForRequest(testCase, putAllRequest);
  await promiseForTransaction(testCase, txn);

  const txn2 = db.transaction(['books'], 'readonly');
  const objectStore2 = txn2.objectStore('books');
  const getRequest1 = objectStore2.get('one');
  const getRequest2 = objectStore2.get('two');
  const getRequest3 = objectStore2.get('three');
  await promiseForTransaction(testCase, txn2);
  assert_array_equals(
      [getRequest1.result.title,
          getRequest2.result.title,
          getRequest3.result.title],
      ['title1', 'title2', 'title3'],
      'All three retrieved titles should match those that were put.');
  db.close();
}, 'Data can be successfully inserted into an object store using putAll.');

promise_test(async testCase => {
  const db = await createDatabase(testCase, db => {
    const store = createBooksStore(testCase, db);
  });
  const txn = db.transaction(['books'], 'readwrite');
  const objectStore = txn.objectStore('books');
  const values = [
    {isbn: ['one', 'two', 'three'], title: 'title1'},
    {isbn: ['four', 'five', 'six'], title: 'title2'},
    {isbn: ['seven', 'eight', 'nine'], title: 'title3'}
  ];
  const putAllRequest = objectStore.putAllValues(values);
  // TODO(nums): Check that correct keys are returned.
  await promiseForRequest(testCase, putAllRequest);
  await promiseForTransaction(testCase, txn);

  const txn2 = db.transaction(['books'], 'readonly');
  const objectStore2 = txn2.objectStore('books');
  const getRequest1 = objectStore2.get(['one', 'two', 'three']);
  const getRequest2 = objectStore2.get(['four', 'five', 'six']);
  const getRequest3 = objectStore2.get(['seven', 'eight', 'nine']);
  await promiseForTransaction(testCase, txn2);
  assert_array_equals(
      [getRequest1.result.title,
          getRequest2.result.title,
          getRequest3.result.title],
      ['title1', 'title2', 'title3'],
      'All three retrieved titles should match those that were put.');
  db.close();
}, 'Values with array keys can be successfully inserted into an object'
    + ' store using putAll.');

promise_test(async testCase => {
  const db = await createDatabase(testCase, db => {
    const store = createBooksStore(testCase, db);
  });
  const txn = db.transaction(['books'], 'readwrite');
  const objectStore = txn.objectStore('books');
  const putAllRequest = objectStore.putAllValues([]);
  await promiseForRequest(testCase, putAllRequest);
  await promiseForTransaction(testCase, txn);
  // TODO(nums): Check that an empty key array is returned.
  db.close();
}, 'Inserting an empty list using putAll.');

promise_test(async testCase => {
  const db = await createDatabase(testCase, db => {
    const store = createBooksStore(testCase, db);
  });
  const txn = db.transaction(['books'], 'readwrite');
  const objectStore = txn.objectStore('books');
  const putAllRequest = objectStore.putAllValues([{}, {}, {}]);
  // TODO(nums): Check that correct keys are returned.
  await promiseForRequest(testCase, putAllRequest);
  await promiseForTransaction(testCase, txn);

  const txn2 = db.transaction(['books'], 'readonly');
  const objectStore2 = txn2.objectStore('books');
  const getRequest1 = objectStore2.get(1);
  const getRequest2 = objectStore2.get(2);
  const getRequest3 = objectStore2.get(3);
  await Promise.all([
    promiseForRequest(testCase, getRequest1),
    promiseForRequest(testCase, getRequest2),
    promiseForRequest(testCase, getRequest3),
  ]);
  db.close();
}, 'Empty values can be inserted into an objectstore'
    + ' with a key generator using putAll.');

promise_test(async testCase => {
  const db = await createDatabase(testCase, db => {
    const store = createBooksStore(testCase, db);
  });
  const txn = db.transaction(['books'], 'readonly');
  const objectStore = txn.objectStore('books');
  assert_throws_dom('ReadOnlyError',
    () => { objectStore.putAllValues([{}]); },
    'The transaction is readonly');
  db.close();
}, 'Attempting to insert with a read only transaction using putAll throws a '
    + 'ReadOnlyError.');

promise_test(async testCase => {
  const db = await createDatabase(testCase, db => {
    const store = createBooksStore(testCase, db);
  });
  const txn = db.transaction(['books'], 'readwrite');
  const objectStore = txn.objectStore('books');
  const putRequest = await objectStore.put({isbn: 1, title: "duplicate"});
  await promiseForRequest(testCase, putRequest);
  const putAllRequest = objectStore.putAllValues([
    {isbn: 2, title: "duplicate"},
    {isbn: 3, title: "duplicate"}
  ]);
  const errorEvent = await requestWatcher(testCase,
                                        putAllRequest).wait_for('error');
  assert_equals(errorEvent.target.error.name, "ConstraintError");
  errorEvent.preventDefault();
  // The transaction still receives the error event even though it
  // isn't aborted.
  await transactionWatcher(testCase, txn).wait_for(['error', 'complete']);

  const txn2 = db.transaction(['books'], 'readonly');
  const objectStore2 = txn2.objectStore('books');
  const getRequest1 = objectStore2.get(1);
  const getRequest2 = objectStore2.get(2);
  const getRequest3 = objectStore2.get(3);
  await promiseForTransaction(testCase, txn2);
  assert_array_equals(
      [getRequest1.result.title, getRequest2.result, getRequest3.result],
      ["duplicate", undefined, undefined],
      'None of the values should have been inserted.');
  db.close();
}, 'Inserting duplicate unique keys into a store that already has the key'
    + 'using putAll throws a ConstraintError.');

promise_test(async testCase => {
  const db = await createDatabase(testCase, db => {
    const store = createBooksStoreWithoutAutoIncrement(testCase, db);
  });
  const txn = db.transaction(['books'], 'readwrite');
  const objectStore = txn.objectStore('books');
  const values = [
    {title: "title1", isbn: 1},
    {title: "title2"}
  ];
  assert_throws_dom('DataError',
    () => { const putAllRequest = objectStore.putAllValues(values); },
    "Evaluating the object store's key path did not yield a value");

  const txn2 = db.transaction(['books'], 'readonly');
  const objectStore2 = txn2.objectStore('books');
  const getRequest1 = objectStore2.get(1);
  const getRequest2 = objectStore2.get(2);
  await promiseForTransaction(testCase, txn2);
  assert_array_equals(
      [getRequest1.result, getRequest2.result],
      [undefined, undefined],
      'No data should have been inserted');
  db.close();
}, 'Inserting values without the key into an object store that'
    + ' does not have generated keys throws an exception.');

// TODO(nums): Add test for insertion into multi entry indexes
// TODO(nums): Add test for inserting unique keys into a store
// that doesn't already have the key https://crbug.com/1115649