Skip to content
This repository was archived by the owner on Feb 26, 2024. It is now read-only.

Commit 84a251f

Browse files
gionkunzmhevery
authored andcommitted
feat(indexdb): Added property patches and event target methods as well as tests for Indexed DB
Closes #204
1 parent 99940c3 commit 84a251f

File tree

3 files changed

+123
-1
lines changed

3 files changed

+123
-1
lines changed

lib/browser/event-target.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {patchEventTargetMethods} from './utils';
22

33
const WTF_ISSUE_555 = 'Anchor,Area,Audio,BR,Base,BaseFont,Body,Button,Canvas,Content,DList,Directory,Div,Embed,FieldSet,Font,Form,Frame,FrameSet,HR,Head,Heading,Html,IFrame,Image,Input,Keygen,LI,Label,Legend,Link,Map,Marquee,Media,Menu,Meta,Meter,Mod,OList,Object,OptGroup,Option,Output,Paragraph,Pre,Progress,Quote,Script,Select,Source,Span,Style,TableCaption,TableCell,TableCol,Table,TableRow,TableSection,TextArea,Title,Track,UList,Unknown,Video';
4-
const NO_EVENT_TARGET = 'ApplicationCache,EventSource,FileReader,InputMethodContext,MediaController,MessagePort,Node,Performance,SVGElementInstance,SharedWorker,TextTrack,TextTrackCue,TextTrackList,WebKitNamedFlow,Worker,WorkerGlobalScope,XMLHttpRequest,XMLHttpRequestEventTarget,XMLHttpRequestUpload'.split(',');
4+
const NO_EVENT_TARGET = 'ApplicationCache,EventSource,FileReader,InputMethodContext,MediaController,MessagePort,Node,Performance,SVGElementInstance,SharedWorker,TextTrack,TextTrackCue,TextTrackList,WebKitNamedFlow,Worker,WorkerGlobalScope,XMLHttpRequest,XMLHttpRequestEventTarget,XMLHttpRequestUpload,IDBRequest,IDBOpenDBRequest,IDBDatabase,IDBTransaction,IDBCursor,DBIndex'.split(',');
55
const EVENT_TARGET = 'EventTarget';
66

77
export function eventTargetPatch(_global) {

lib/browser/property-descriptor.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,14 @@ export function propertyDescriptorPatch(_global) {
1515
patchOnProperties(HTMLElement.prototype, eventNames);
1616
}
1717
patchOnProperties(XMLHttpRequest.prototype, null);
18+
if (typeof IDBIndex !== 'undefined') {
19+
patchOnProperties(IDBIndex.prototype, null);
20+
patchOnProperties(IDBRequest.prototype, null);
21+
patchOnProperties(IDBOpenDBRequest.prototype, null);
22+
patchOnProperties(IDBDatabase.prototype, null);
23+
patchOnProperties(IDBTransaction.prototype, null);
24+
patchOnProperties(IDBCursor.prototype, null);
25+
}
1826
if (supportsWebSocket) {
1927
patchOnProperties(WebSocket.prototype, null);
2028
}

test/patch/IndexedDB.spec.js

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
'use strict';
2+
3+
describe('IndexedDB', ifEnvSupports('IDBDatabase', function () {
4+
var testZone = zone.fork();
5+
var db;
6+
7+
beforeEach(function (done) {
8+
var openRequest = indexedDB.open('_zone_testdb');
9+
openRequest.onupgradeneeded = function(event) {
10+
db = event.target.result;
11+
var objectStore = db.createObjectStore('test-object-store', {
12+
keyPath: 'key'
13+
});
14+
objectStore.createIndex('key', 'key', { unique: true });
15+
objectStore.createIndex('data', 'data', { unique: false });
16+
17+
objectStore.transaction.oncomplete = function() {
18+
var testStore = db.transaction('test-object-store', 'readwrite').objectStore('test-object-store');
19+
testStore.add({
20+
key: 1,
21+
data: 'Test data'
22+
});
23+
testStore.transaction.oncomplete = function() {
24+
done();
25+
}
26+
};
27+
};
28+
});
29+
30+
afterEach(function(done) {
31+
db.close();
32+
33+
var openRequest = indexedDB.deleteDatabase('_zone_testdb');
34+
openRequest.onsuccess = function(event) {
35+
done();
36+
};
37+
});
38+
39+
describe('IDBRequest', function() {
40+
it('should bind EventTarget.addEventListener', function (done) {
41+
testZone.run(function () {
42+
db.transaction('test-object-store').objectStore('test-object-store').get(1).addEventListener('success', function(event) {
43+
expect(zone).toBeDirectChildOf(testZone);
44+
expect(event.target.result.data).toBe('Test data');
45+
done();
46+
});
47+
});
48+
});
49+
50+
it('should bind onEventType listeners', function (done) {
51+
testZone.run(function () {
52+
db.transaction('test-object-store').objectStore('test-object-store').get(1).onsuccess = function(event) {
53+
expect(zone).toBeDirectChildOf(testZone);
54+
expect(event.target.result.data).toBe('Test data');
55+
done();
56+
};
57+
});
58+
});
59+
});
60+
61+
describe('IDBCursor', function() {
62+
it('should bind EventTarget.addEventListener', function (done) {
63+
testZone.run(function () {
64+
db.transaction('test-object-store').objectStore('test-object-store').openCursor().addEventListener('success', function(event) {
65+
var cursor = event.target.result;
66+
if (cursor) {
67+
expect(zone).toBeDirectChildOf(testZone);
68+
expect(cursor.value.data).toBe('Test data');
69+
done();
70+
} else {
71+
throw 'Error while reading cursor!';
72+
}
73+
});
74+
});
75+
});
76+
77+
it('should bind onEventType listeners', function (done) {
78+
testZone.run(function () {
79+
db.transaction('test-object-store').objectStore('test-object-store').openCursor().onsuccess = function(event) {
80+
var cursor = event.target.result;
81+
if (cursor) {
82+
expect(zone).toBeDirectChildOf(testZone);
83+
expect(cursor.value.data).toBe('Test data');
84+
done();
85+
} else {
86+
throw 'Error while reading cursor!';
87+
}
88+
};
89+
});
90+
});
91+
});
92+
93+
describe('IDBIndex', function() {
94+
it('should bind EventTarget.addEventListener', function (done) {
95+
testZone.run(function () {
96+
db.transaction('test-object-store').objectStore('test-object-store').index('data').get('Test data').addEventListener('success', function(event) {
97+
expect(zone).toBeDirectChildOf(testZone);
98+
expect(event.target.result.key).toBe(1);
99+
done();
100+
});
101+
});
102+
});
103+
104+
it('should bind onEventType listeners', function (done) {
105+
testZone.run(function () {
106+
db.transaction('test-object-store').objectStore('test-object-store').index('data').get('Test data').onsuccess = function(event) {
107+
expect(zone).toBeDirectChildOf(testZone);
108+
expect(event.target.result.key).toBe(1);
109+
done();
110+
};
111+
});
112+
});
113+
});
114+
}));

0 commit comments

Comments
 (0)