~ubuntu-branches/ubuntu/natty/adblock-plus/natty

« back to all changes in this revision

Viewing changes to chrome/content/mochitest/tests/test_requestList_memory.html

  • Committer: Bazaar Package Importer
  • Author(s): Benjamin Drung
  • Date: 2010-11-05 18:42:36 UTC
  • mto: (25.1.1 sid)
  • mto: This revision was merged to the branch mainline in revision 27.
  • Revision ID: james.westby@ubuntu.com-20101105184236-h7dnu8mbfjaoya62
Tags: upstream-1.3.1
ImportĀ upstreamĀ versionĀ 1.3.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
<!DOCTYPE HTML>
2
 
<html>
3
 
<head>
4
 
  <title>Tests for request data</title>
5
 
 
6
 
  <link rel="stylesheet" type="text/css" href="/content/tests/SimpleTest/test.css" />
7
 
 
8
 
  <script type="text/javascript" src="/content/MochiKit/MochiKit.js"></script>
9
 
  <script type="text/javascript" src="/content/tests/SimpleTest/SimpleTest.js"></script>
10
 
 
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>
13
 
</head>
14
 
<body>
15
 
  <p id="display"></p>
16
 
  <div id="content" style="display: none">
17
 
    <iframe id="frame"></iframe>
18
 
  </div>
19
 
  <pre id="test">
20
 
  <script type="application/x-javascript;version=1.7">
21
 
    let abp = Components.classes["@mozilla.org/adblockplus;1"].createInstance().wrappedJSObject;
22
 
 
23
 
    let tests = [
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],
32
 
    ];
33
 
    let currentTest = -1;
34
 
    let urlModifier = null;
35
 
 
36
 
    function start()
37
 
    {
38
 
      window.addEventListener("unload", stop, false);
39
 
      server.start(1234);
40
 
 
41
 
      abp.prefs.enabled = true;
42
 
 
43
 
      server.registerPathHandler("/test1", function(metadata, response)
44
 
      {
45
 
        response.setStatusLine("1.1", "200", "OK");
46
 
        response.setHeader("Content-Type", "text/html");
47
 
 
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);
50
 
      });
51
 
 
52
 
      server.registerPathHandler("/test2", function(metadata, response)
53
 
      {
54
 
        response.setStatusLine("1.1", "200", "OK");
55
 
        response.setHeader("Content-Type", "text/html");
56
 
 
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);
59
 
      });
60
 
 
61
 
      server.registerPathHandler("/test3", function(metadata, response)
62
 
      {
63
 
        response.setStatusLine("1.1", "200", "OK");
64
 
        response.setHeader("Content-Type", "text/html");
65
 
 
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);
68
 
      });
69
 
 
70
 
      server.registerPathHandler("/test4", function(metadata, response)
71
 
      {
72
 
        response.setStatusLine("1.1", "200", "OK");
73
 
        response.setHeader("Content-Type", "text/html");
74
 
 
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);
77
 
      });
78
 
 
79
 
      runNextTest();
80
 
    }
81
 
 
82
 
    function runNextTest()
83
 
    {
84
 
      ++currentTest;
85
 
      if (currentTest >= tests.length)
86
 
      {
87
 
        $("frame").onload = null;
88
 
        SimpleTest.finish();
89
 
        return;
90
 
      }
91
 
 
92
 
      urlModifier = tests[currentTest][1];
93
 
 
94
 
      $("frame").onload = function() setTimeout(testPageLoaded, 0);
95
 
      $("frame").src = "http://127.0.0.1:1234/" + tests[currentTest][0];
96
 
    }
97
 
 
98
 
    function testPageLoaded()
99
 
    {
100
 
      tests[currentTest][2]();
101
 
      runNextTest();
102
 
    }
103
 
 
104
 
    function sameAddressNodes1()
105
 
    {
106
 
      let frameData = abp.RequestList.getDataForWindow(abp.wrapNode(window.frames[0]), true);
107
 
      ok(frameData, "Frame has data associated with it");
108
 
 
109
 
      let entries = frameData.getAllLocations();
110
 
      is(entries.length, 1, "Number of entries in the frame data");
111
 
 
112
 
      let entry = entries[0];
113
 
      is(entry.nodes.length, 40, "Number of associated nodes before garbage collection");
114
 
 
115
 
      top.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIDOMWindowUtils).garbageCollect();
116
 
      is(entry.nodes.length, 0, "Number of associated nodes after garbage collection");
117
 
    }
118
 
 
119
 
    function sameAddressNodes2()
120
 
    {
121
 
      let frameData = abp.RequestList.getDataForWindow(abp.wrapNode(window.frames[0]), true);
122
 
      ok(frameData, "Frame has data associated with it");
123
 
 
124
 
      let entries = frameData.getAllLocations();
125
 
      is(entries.length, 1, "Number of entries in the frame data");
126
 
 
127
 
      let entry = entries[0];
128
 
      is(entry.nodes.length, 40, "Number of associated nodes before garbage collection");
129
 
 
130
 
      top.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIDOMWindowUtils).garbageCollect();
131
 
      is(entry.nodes.length, 0, "Number of associated nodes after garbage collection");
132
 
    }
133
 
 
134
 
    function sameAddressNodes3()
135
 
    {
136
 
      let frameData = abp.RequestList.getDataForWindow(abp.wrapNode(window.frames[0]), true);
137
 
      ok(frameData, "Frame has data associated with it");
138
 
 
139
 
      let entries = frameData.getAllLocations();
140
 
      is(entries.length, 1, "Number of entries in the frame data");
141
 
 
142
 
      let entry = entries[0];
143
 
      is(entry.nodes.length, 40, "Number of associated nodes before garbage collection");
144
 
 
145
 
      top.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIDOMWindowUtils).garbageCollect();
146
 
      is(entry.nodes.length, 40, "Number of associated nodes after garbage collection");
147
 
    }
148
 
 
149
 
    function sameAddressNodes4(event)
150
 
    {
151
 
      let frameData = abp.RequestList.getDataForWindow(abp.wrapNode(window.frames[0]), true);
152
 
      ok(frameData, "Frame has data associated with it");
153
 
 
154
 
      let entries = frameData.getAllLocations();
155
 
      is(entries.length, 1, "Number of entries in the frame data");
156
 
 
157
 
      let entry = entries[0];
158
 
      is(entry._nodes.length, 40, "Number of associated nodes before garbage collection");
159
 
 
160
 
      top.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIDOMWindowUtils).garbageCollect();
161
 
 
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");
166
 
    }
167
 
 
168
 
    function differentAddressNodes1()
169
 
    {
170
 
      let frameData = abp.RequestList.getDataForWindow(abp.wrapNode(window.frames[0]), true);
171
 
      ok(frameData, "Frame has data associated with it");
172
 
 
173
 
      let entries = frameData.getAllLocations();
174
 
      is(entries.length, 40, "Number of entries in the frame data before garbage collection");
175
 
 
176
 
      top.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIDOMWindowUtils).garbageCollect();
177
 
      for each (let entry in entries)
178
 
        entry.lastUpdate = 0;
179
 
 
180
 
      entries = frameData.getAllLocations();
181
 
      is(entries.length, 0, "Number of entries in the frame data after garbage collection");
182
 
    }
183
 
 
184
 
    function differentAddressNodes2()
185
 
    {
186
 
      let frameData = abp.RequestList.getDataForWindow(abp.wrapNode(window.frames[0]), true);
187
 
      ok(frameData, "Frame has data associated with it");
188
 
 
189
 
      let entries = frameData.getAllLocations();
190
 
      is(entries.length, 40, "Number of entries in the frame data before garbage collection");
191
 
 
192
 
      top.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIDOMWindowUtils).garbageCollect();
193
 
      for each (let entry in entries)
194
 
        entry.lastUpdate = 0;
195
 
 
196
 
      entries = frameData.getAllLocations();
197
 
      is(entries.length, 0, "Number of entries in the frame data after garbage collection");
198
 
    }
199
 
 
200
 
    function differentAddressNodes3()
201
 
    {
202
 
      let frameData = abp.RequestList.getDataForWindow(abp.wrapNode(window.frames[0]), true);
203
 
      ok(frameData, "Frame has data associated with it");
204
 
 
205
 
      let entries = frameData.getAllLocations();
206
 
      is(entries.length, 40, "Number of entries in the frame data before garbage collection");
207
 
 
208
 
      top.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIDOMWindowUtils).garbageCollect();
209
 
      for each (let entry in entries)
210
 
        entry.lastUpdate = 0;
211
 
 
212
 
      entries = frameData.getAllLocations();
213
 
      is(entries.length, 40, "Number of entries in the frame data after garbage collection");
214
 
    }
215
 
 
216
 
    function differentAddressNodes4()
217
 
    {
218
 
      let frameData = abp.RequestList.getDataForWindow(abp.wrapNode(window.frames[0]), true);
219
 
      ok(frameData, "Frame has data associated with it");
220
 
 
221
 
      let entries = frameData.getAllLocations();
222
 
      is(entries.length, 40, "Number of entries in the frame data before garbage collection");
223
 
 
224
 
      top.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIDOMWindowUtils).garbageCollect();
225
 
      for each (let entry in entries)
226
 
        entry.lastUpdate = 0;
227
 
 
228
 
      // Trigger list compression by adding a node while the counter has a high value
229
 
      frameData._compactCounter = 100;
230
 
      window.frames[0].addImage();
231
 
 
232
 
      entries = frameData.getAllLocations();
233
 
      is(entries.length, 1, "Number of entries in the frame data after garbage collection");
234
 
    }
235
 
 
236
 
    function stop()
237
 
    {
238
 
      server.stop();
239
 
 
240
 
      abp.prefs.enabled = oldEnabled;
241
 
    }
242
 
 
243
 
    let server = new nsHttpServer();
244
 
    let oldEnabled = abp.prefs.enabled;
245
 
    SimpleTest.waitForExplicitFinish();
246
 
    addLoadEvent(start);
247
 
  </script>
248
 
  </pre>
249
 
</body>
250
 
</html>