4
<title>Tests for request data</title>
6
<link rel="stylesheet" type="text/css" href="/content/tests/SimpleTest/test.css" />
8
<script type="text/javascript" src="/content/MochiKit/MochiKit.js"></script>
9
<script type="text/javascript" src="/content/tests/SimpleTest/SimpleTest.js"></script>
11
<script type="application/x-javascript;version=1.7" src="../httpd.js"></script>
12
<script type="application/x-javascript;version=1.7" src="common.js"></script>
16
<div id="content" style="display: none">
17
<iframe id="frame"></iframe>
20
<script type="application/x-javascript;version=1.7">
21
let abp = Components.classes["@mozilla.org/adblockplus;1"].createInstance().wrappedJSObject;
24
["test1", "", sameAddressNodes1],
25
["test2", "", sameAddressNodes2],
26
["test3", "", sameAddressNodes3],
27
["test4", "", sameAddressNodes4],
28
["test1", "'+i+'", differentAddressNodes1],
29
["test2", "'+i+'", differentAddressNodes2],
30
["test3", "'+i+'", differentAddressNodes3],
31
["test4", "'+i+'", differentAddressNodes4],
34
let urlModifier = null;
38
window.addEventListener("unload", stop, false);
41
abp.prefs.enabled = true;
43
server.registerPathHandler("/test1", function(metadata, response)
45
response.setStatusLine("1.1", "200", "OK");
46
response.setHeader("Content-Type", "text/html");
48
let body = "<script>for (var i = 0; i < 40; i++) new Image().src='test" + urlModifier + ".png';<" + "/script>";
49
response.bodyOutputStream.write(body, body.length);
52
server.registerPathHandler("/test2", function(metadata, response)
54
response.setStatusLine("1.1", "200", "OK");
55
response.setHeader("Content-Type", "text/html");
57
let body = "<body onload='document.body.innerHTML=null;'><script>for (var i = 0; i < 40; i++) document.write('<iframe src=dummy" + urlModifier + "></iframe>')<" + "/script></body>";
58
response.bodyOutputStream.write(body, body.length);
61
server.registerPathHandler("/test3", function(metadata, response)
63
response.setStatusLine("1.1", "200", "OK");
64
response.setHeader("Content-Type", "text/html");
66
let body = "<body><script>for (var i = 0; i < 40; i++) document.write('<iframe src=dummy" + urlModifier + "></iframe>')<" + "/script></body>";
67
response.bodyOutputStream.write(body, body.length);
70
server.registerPathHandler("/test4", function(metadata, response)
72
response.setStatusLine("1.1", "200", "OK");
73
response.setHeader("Content-Type", "text/html");
75
let body = "<script>function addImage() { new Image().src='test" + urlModifier + ".png'; }for (var i = 0; i < 40; i++) addImage();<" + "/script>";
76
response.bodyOutputStream.write(body, body.length);
82
function runNextTest()
85
if (currentTest >= tests.length)
87
$("frame").onload = null;
92
urlModifier = tests[currentTest][1];
94
$("frame").onload = function() setTimeout(testPageLoaded, 0);
95
$("frame").src = "http://127.0.0.1:1234/" + tests[currentTest][0];
98
function testPageLoaded()
100
tests[currentTest][2]();
104
function sameAddressNodes1()
106
let frameData = abp.RequestList.getDataForWindow(abp.wrapNode(window.frames[0]), true);
107
ok(frameData, "Frame has data associated with it");
109
let entries = frameData.getAllLocations();
110
is(entries.length, 1, "Number of entries in the frame data");
112
let entry = entries[0];
113
is(entry.nodes.length, 40, "Number of associated nodes before garbage collection");
115
top.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIDOMWindowUtils).garbageCollect();
116
is(entry.nodes.length, 0, "Number of associated nodes after garbage collection");
119
function sameAddressNodes2()
121
let frameData = abp.RequestList.getDataForWindow(abp.wrapNode(window.frames[0]), true);
122
ok(frameData, "Frame has data associated with it");
124
let entries = frameData.getAllLocations();
125
is(entries.length, 1, "Number of entries in the frame data");
127
let entry = entries[0];
128
is(entry.nodes.length, 40, "Number of associated nodes before garbage collection");
130
top.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIDOMWindowUtils).garbageCollect();
131
is(entry.nodes.length, 0, "Number of associated nodes after garbage collection");
134
function sameAddressNodes3()
136
let frameData = abp.RequestList.getDataForWindow(abp.wrapNode(window.frames[0]), true);
137
ok(frameData, "Frame has data associated with it");
139
let entries = frameData.getAllLocations();
140
is(entries.length, 1, "Number of entries in the frame data");
142
let entry = entries[0];
143
is(entry.nodes.length, 40, "Number of associated nodes before garbage collection");
145
top.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIDOMWindowUtils).garbageCollect();
146
is(entry.nodes.length, 40, "Number of associated nodes after garbage collection");
149
function sameAddressNodes4(event)
151
let frameData = abp.RequestList.getDataForWindow(abp.wrapNode(window.frames[0]), true);
152
ok(frameData, "Frame has data associated with it");
154
let entries = frameData.getAllLocations();
155
is(entries.length, 1, "Number of entries in the frame data");
157
let entry = entries[0];
158
is(entry._nodes.length, 40, "Number of associated nodes before garbage collection");
160
top.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIDOMWindowUtils).garbageCollect();
162
// Trigger list compression by adding a node while the counter has a high value
163
entry._compactCounter = 100;
164
window.frames[0].addImage();
165
is(entry._nodes.length, 1, "Number of associated nodes after garbage collection");
168
function differentAddressNodes1()
170
let frameData = abp.RequestList.getDataForWindow(abp.wrapNode(window.frames[0]), true);
171
ok(frameData, "Frame has data associated with it");
173
let entries = frameData.getAllLocations();
174
is(entries.length, 40, "Number of entries in the frame data before garbage collection");
176
top.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIDOMWindowUtils).garbageCollect();
177
for each (let entry in entries)
178
entry.lastUpdate = 0;
180
entries = frameData.getAllLocations();
181
is(entries.length, 0, "Number of entries in the frame data after garbage collection");
184
function differentAddressNodes2()
186
let frameData = abp.RequestList.getDataForWindow(abp.wrapNode(window.frames[0]), true);
187
ok(frameData, "Frame has data associated with it");
189
let entries = frameData.getAllLocations();
190
is(entries.length, 40, "Number of entries in the frame data before garbage collection");
192
top.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIDOMWindowUtils).garbageCollect();
193
for each (let entry in entries)
194
entry.lastUpdate = 0;
196
entries = frameData.getAllLocations();
197
is(entries.length, 0, "Number of entries in the frame data after garbage collection");
200
function differentAddressNodes3()
202
let frameData = abp.RequestList.getDataForWindow(abp.wrapNode(window.frames[0]), true);
203
ok(frameData, "Frame has data associated with it");
205
let entries = frameData.getAllLocations();
206
is(entries.length, 40, "Number of entries in the frame data before garbage collection");
208
top.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIDOMWindowUtils).garbageCollect();
209
for each (let entry in entries)
210
entry.lastUpdate = 0;
212
entries = frameData.getAllLocations();
213
is(entries.length, 40, "Number of entries in the frame data after garbage collection");
216
function differentAddressNodes4()
218
let frameData = abp.RequestList.getDataForWindow(abp.wrapNode(window.frames[0]), true);
219
ok(frameData, "Frame has data associated with it");
221
let entries = frameData.getAllLocations();
222
is(entries.length, 40, "Number of entries in the frame data before garbage collection");
224
top.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIDOMWindowUtils).garbageCollect();
225
for each (let entry in entries)
226
entry.lastUpdate = 0;
228
// Trigger list compression by adding a node while the counter has a high value
229
frameData._compactCounter = 100;
230
window.frames[0].addImage();
232
entries = frameData.getAllLocations();
233
is(entries.length, 1, "Number of entries in the frame data after garbage collection");
240
abp.prefs.enabled = oldEnabled;
243
let server = new nsHttpServer();
244
let oldEnabled = abp.prefs.enabled;
245
SimpleTest.waitForExplicitFinish();