Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(22)

Unified Diff: LayoutTests/storage/indexeddb/key-type-binary.html

Issue 1087923003: Indexed DB: Adopt BufferSource model for binary keys (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: LayoutTests/storage/indexeddb/key-type-binary.html
diff --git a/LayoutTests/storage/indexeddb/key-type-binary.html b/LayoutTests/storage/indexeddb/key-type-binary.html
index 588a415d45fb87a10be376d10e3f28cfb8378643..1790a05bffa72c38856a37cebacab21e0012f24c 100644
--- a/LayoutTests/storage/indexeddb/key-type-binary.html
+++ b/LayoutTests/storage/indexeddb/key-type-binary.html
@@ -1,4 +1,99 @@
<!DOCTYPE html>
-<script src="../../resources/js-test.js"></script>
-<script src="resources/shared.js"></script>
-<script src="resources/key-type-binary.js"></script>
+<title>IndexedDB: Verify transaction activation behavior around microtasks</title>
+<script src="../../resources/testharness.js"></script>
+<script src="../../resources/testharnessreport.js"></script>
+<script src="resources/testharness-helpers.js"></script>
+<script>
+var sample = [0x44, 0x33, 0x22, 0x11, 0xFF, 0xEE, 0xDD, 0xCC];
+var buffer = new Uint8Array(sample).buffer;
+
+function assert_key_valid(a, message) {
+ assert_equals(indexedDB.cmp(a, a), 0, message);
cmumford 2015/04/27 17:14:23 expected is first.
jsbell 2015/04/27 22:39:47 Not per testharness.js docs: * https://github.com
cmumford 2015/04/27 22:44:23 Yep - you're totally correct. I naively trusted th
+}
+
+function assert_buffer_equals(a, b, message) {
+ assert_array_equals(
+ [].slice.call(new Uint8Array(a)),
+ [].slice.call(new Uint8Array(b)),
+ message);
+}
+
+function check_key(t, db, key) {
+ var tx = db.transaction('store', 'readwrite');
+ var store = tx.objectStore('store');
+
+ // Verify put with key
+ var req = store.put('value', key);
+ req.onerror = t.unreached_func('put should succeed');
+
+ // Verify get with key
+ req = store.get(key);
+ req.onerror = t.unreached_func('get should succeed');
+ req.onsuccess = t.step_func(function() {
+ assert_equals(req.result, 'value', 'get with key should succeed');
+
+ // Verify iteration returning key
+ req = store.openCursor();
+ req.onerror = t.unreached_func('openCursor should succeed');
+ req.onsuccess = t.step_func(function() {
+ assert_not_equals(req.result, null, 'cursor should be present');
cmumford 2015/04/27 17:14:23 param order.
+ var found_key = req.result.key;
+ assert_true(found_key instanceof ArrayBuffer,
+ 'Key should be an ArrayBuffer');
+ assert_key_equals(found_key, key,
cmumford 2015/04/27 17:14:23 Nit: Do you want to swap the expected/actual order
+ 'Key should be equal to put key');
+ assert_buffer_equals(
+ found_key, buffer, 'Buffers should be equal to put buffer');
+
+ t.done();
+ });
+ });
+}
+
+function type_test(type) {
+ idb_test(
+ 'Binary key: ' + type,
+ function(t, db) {
+ db.createObjectStore('store');
+ },
+ function(t, db) {
+ var key = new self[type](buffer);
+ assert_key_valid(key, type + ' should be a valid key');
+ assert_key_equals(key, buffer,
+ 'Keys should be equal regardless of type');
+ check_key(t, db, key);
+ }
+ );
+}
+
+[
+ 'Uint8Array',
+ 'Uint8ClampedArray',
+ 'Int8Array',
+ 'Uint16Array',
+ 'Int16Array',
+ 'Uint32Array',
+ 'Int32Array',
+ 'Float32Array',
+ 'Float64Array'
+].forEach(function(type) { type_test(type); });
+
+function value_test(type, value) {
+ idb_test(
+ 'Value test: ' + type,
+ function(t, db) {
+ db.createObjectStore('store');
+ },
+ function(t, db) {
+ assert_key_valid(value, type + ' should be a valid key');
+ check_key(t, db, value);
+ t.done();
+ }
+ );
+}
+
+value_test('ArrayBuffer', buffer);
+value_test('DataView', new DataView(buffer));
+value_test('Offset DataView', new DataView(buffer), 3, 3);
+value_test('Offset Uint8Array', new Uint8Array(buffer), 3, 3);
+</script>

Powered by Google App Engine
This is Rietveld 408576698