tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

test_cache2-31-visit-all.js (2532B)


      1 "use strict";
      2 
      3 function run_test() {
      4  getCacheStorage("disk");
      5  var lcis = [
      6    Services.loadContextInfo.default,
      7    Services.loadContextInfo.custom(false, { userContextId: 1 }),
      8    Services.loadContextInfo.custom(false, { userContextId: 2 }),
      9    Services.loadContextInfo.custom(false, { userContextId: 3 }),
     10  ];
     11 
     12  do_get_profile();
     13 
     14  var mc = new MultipleCallbacks(
     15    8,
     16    function () {
     17      executeSoon(function () {
     18        var expectedConsumption = 8192;
     19        var entries = [
     20          { uri: "http://a/", lci: lcis[0] }, // default
     21          { uri: "http://b/", lci: lcis[0] }, // default
     22          { uri: "http://a/", lci: lcis[1] }, // user Context 1
     23          { uri: "http://b/", lci: lcis[1] }, // user Context 1
     24          { uri: "http://a/", lci: lcis[2] }, // user Context 2
     25          { uri: "http://b/", lci: lcis[2] }, // user Context 2
     26          { uri: "http://a/", lci: lcis[3] }, // user Context 3
     27          { uri: "http://b/", lci: lcis[3] },
     28        ]; // user Context 3
     29 
     30        Services.cache2.asyncVisitAllStorages(
     31          // Test should store 8 entries across 4 originAttributes
     32          new VisitCallback(8, expectedConsumption, entries, function () {
     33            Services.cache2.asyncVisitAllStorages(
     34              // Still 8 entries expected, now don't walk them
     35              new VisitCallback(8, expectedConsumption, null, function () {
     36                finish_cache2_test();
     37              }),
     38              false
     39            );
     40          }),
     41          true
     42        );
     43      });
     44    },
     45    true
     46  );
     47 
     48  // Add two cache entries for each originAttributes.
     49  for (var i = 0; i < lcis.length; i++) {
     50    asyncOpenCacheEntry(
     51      "http://a/",
     52      "disk",
     53      Ci.nsICacheStorage.OPEN_NORMALLY,
     54      lcis[i],
     55      new OpenCallback(NEW, "a1m", "a1d", function () {
     56        asyncOpenCacheEntry(
     57          "http://a/",
     58          "disk",
     59          Ci.nsICacheStorage.OPEN_NORMALLY,
     60          lcis[i],
     61          new OpenCallback(NORMAL, "a1m", "a1d", function () {
     62            mc.fired();
     63          })
     64        );
     65      })
     66    );
     67 
     68    asyncOpenCacheEntry(
     69      "http://b/",
     70      "disk",
     71      Ci.nsICacheStorage.OPEN_NORMALLY,
     72      lcis[i],
     73      new OpenCallback(NEW, "b1m", "b1d", function () {
     74        asyncOpenCacheEntry(
     75          "http://b/",
     76          "disk",
     77          Ci.nsICacheStorage.OPEN_NORMALLY,
     78          lcis[i],
     79          new OpenCallback(NORMAL, "b1m", "b1d", function () {
     80            mc.fired();
     81          })
     82        );
     83      })
     84    );
     85  }
     86 
     87  do_test_pending();
     88 }