summaryrefslogtreecommitdiffstats
path: root/netwerk/test/unit/test_cache2-05-visit.js
blob: 7ed9b9effd5d90be79928fb246cd3b8eb1f09a91 (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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
"use strict";

function run_test() {
  do_get_profile();

  var storage = getCacheStorage("disk");
  var mc = new MultipleCallbacks(4, function () {
    // Method asyncVisitStorage() gets the data from index on Cache I/O thread
    // with INDEX priority, so it is ensured that index contains information
    // about all pending writes. However, OpenCallback emulates network latency
    // by postponing the writes using do_execute_soon. We must do the same here
    // to make sure that all writes are posted to Cache I/O thread before we
    // visit the storage.
    executeSoon(function () {
      syncWithCacheIOThread(function () {
        var expectedConsumption = 4096;

        storage.asyncVisitStorage(
          // Test should store 4 entries
          new VisitCallback(
            4,
            expectedConsumption,
            ["http://a/", "http://b/", "http://c/", "http://d/"],
            function () {
              storage.asyncVisitStorage(
                // Still 4 entries expected, now don't walk them
                new VisitCallback(4, expectedConsumption, null, function () {
                  finish_cache2_test();
                }),
                false
              );
            }
          ),
          true
        );
      });
    });
  });

  asyncOpenCacheEntry(
    "http://a/",
    "disk",
    Ci.nsICacheStorage.OPEN_NORMALLY,
    null,
    new OpenCallback(NEW, "a1m", "a1d", function (entry) {
      asyncOpenCacheEntry(
        "http://a/",
        "disk",
        Ci.nsICacheStorage.OPEN_NORMALLY,
        null,
        new OpenCallback(NORMAL, "a1m", "a1d", function (entry) {
          mc.fired();
        })
      );
    })
  );

  asyncOpenCacheEntry(
    "http://b/",
    "disk",
    Ci.nsICacheStorage.OPEN_NORMALLY,
    null,
    new OpenCallback(NEW, "b1m", "b1d", function (entry) {
      asyncOpenCacheEntry(
        "http://b/",
        "disk",
        Ci.nsICacheStorage.OPEN_NORMALLY,
        null,
        new OpenCallback(NORMAL, "b1m", "b1d", function (entry) {
          mc.fired();
        })
      );
    })
  );

  asyncOpenCacheEntry(
    "http://c/",
    "disk",
    Ci.nsICacheStorage.OPEN_NORMALLY,
    null,
    new OpenCallback(NEW, "c1m", "c1d", function (entry) {
      asyncOpenCacheEntry(
        "http://c/",
        "disk",
        Ci.nsICacheStorage.OPEN_NORMALLY,
        null,
        new OpenCallback(NORMAL, "c1m", "c1d", function (entry) {
          mc.fired();
        })
      );
    })
  );

  asyncOpenCacheEntry(
    "http://d/",
    "disk",
    Ci.nsICacheStorage.OPEN_NORMALLY,
    null,
    new OpenCallback(NEW, "d1m", "d1d", function (entry) {
      asyncOpenCacheEntry(
        "http://d/",
        "disk",
        Ci.nsICacheStorage.OPEN_NORMALLY,
        null,
        new OpenCallback(NORMAL, "d1m", "d1d", function (entry) {
          mc.fired();
        })
      );
    })
  );

  do_test_pending();
}