]> git.proxmox.com Git - extjs.git/blame - extjs/packages/core/test/specs/dom/GarbageCollector.js
add extjs 6.0.1 sources
[extjs.git] / extjs / packages / core / test / specs / dom / GarbageCollector.js
CommitLineData
6527f429
DM
1describe("Ext.dom.GarbageCollector", function() {\r
2 var skipGarbageCollection;\r
3\r
4 beforeEach(function() {\r
5 skipGarbageCollection = Ext.dom.Element.prototype.skipGarbageCollection;\r
6 Ext.dom.Element.prototype.skipGarbageCollection = false;\r
7 });\r
8\r
9 afterEach(function() {\r
10 Ext.dom.Element.prototype.skipGarbageCollection = skipGarbageCollection;\r
11 });\r
12\r
13 it("should collect an orphan element", function() {\r
14 var el = Ext.get(document.createElement('div')),\r
15 id = el.id;\r
16\r
17 expect(id in Ext.cache).toBe(true);\r
18\r
19 spyOn(el, 'clearListeners').andCallThrough();\r
20\r
21 Ext.dom.GarbageCollector.collect();\r
22\r
23 expect(el.clearListeners).toHaveBeenCalled();\r
24 expect(id in Ext.cache).toBe(false);\r
25 \r
26 // Element is already destroyed warning is expected\r
27 spyOn(Ext.Logger, 'warn');\r
28 \r
29 el.destroy();\r
30 });\r
31\r
32 it("should not collect an element that is in the body", function() {\r
33 var el = Ext.get(document.createElement('div')),\r
34 id = el.id;\r
35\r
36 Ext.getBody().appendChild(el);\r
37\r
38 spyOn(el, 'clearListeners').andCallThrough();\r
39\r
40 Ext.dom.GarbageCollector.collect();\r
41\r
42 expect(el.clearListeners).not.toHaveBeenCalled();\r
43 expect(id in Ext.cache).toBe(true);\r
44\r
45 el.destroy();\r
46 });\r
47\r
48 (Ext.getDetachedBody ? it : xit)("should not collect an element that is in the detached body", function() {\r
49 var el = Ext.get(document.createElement('div')),\r
50 id = el.id;\r
51\r
52 Ext.getDetachedBody().appendChild(el);\r
53\r
54 spyOn(el, 'clearListeners').andCallThrough();\r
55\r
56 Ext.dom.GarbageCollector.collect();\r
57\r
58 expect(el.clearListeners).not.toHaveBeenCalled();\r
59 expect(id in Ext.cache).toBe(true);\r
60\r
61 el.destroy();\r
62 });\r
63\r
64 it("should return the ids of collected elements", function() {\r
65 var ids, el2;\r
66\r
67 Ext.Element.create({ id: 'one' });\r
68 el2 = Ext.getBody().createChild({ id: 'two' });\r
69 Ext.Element.create({ tag: 'a', id: 'three' });\r
70\r
71 ids = Ext.dom.GarbageCollector.collect();\r
72\r
73 expect(ids instanceof Array).toBe(true);\r
74 expect(Ext.Array.contains(ids, 'DIV#one')).toBe(true);\r
75 expect(Ext.Array.contains(ids, 'DIV#two')).toBe(false);\r
76 expect(Ext.Array.contains(ids, 'A#three')).toBe(true);\r
77\r
78 el2.destroy();\r
79 });\r
80});\r