summaryrefslogtreecommitdiffstats
path: root/docshell/test/unit/test_bug442584.js
blob: c109557f50a3012c12aaa1e28ad643bb29d4b94e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
var prefetch = Cc["@mozilla.org/prefetch-service;1"].getService(
  Ci.nsIPrefetchService
);

var ReferrerInfo = Components.Constructor(
  "@mozilla.org/referrer-info;1",
  "nsIReferrerInfo",
  "init"
);

function run_test() {
  // Fill up the queue
  Services.prefs.setBoolPref("network.prefetch-next", true);
  for (var i = 0; i < 5; i++) {
    var uri = Services.io.newURI("http://localhost/" + i);
    var referrerInfo = new ReferrerInfo(Ci.nsIReferrerInfo.EMPTY, true, uri);
    prefetch.prefetchURI(uri, referrerInfo, null, true);
  }

  // Make sure the queue has items in it...
  Assert.ok(prefetch.hasMoreElements());

  // Now disable the pref to force the queue to empty...
  Services.prefs.setBoolPref("network.prefetch-next", false);
  Assert.ok(!prefetch.hasMoreElements());

  // Now reenable the pref, and add more items to the queue.
  Services.prefs.setBoolPref("network.prefetch-next", true);
  for (var k = 0; k < 5; k++) {
    var uri2 = Services.io.newURI("http://localhost/" + k);
    var referrerInfo2 = new ReferrerInfo(Ci.nsIReferrerInfo.EMPTY, true, uri2);
    prefetch.prefetchURI(uri2, referrerInfo2, null, true);
  }
  Assert.ok(prefetch.hasMoreElements());
}