tor-browser

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

test_cache2-05-visit.js (2870B)


      1 "use strict";
      2 
      3 function run_test() {
      4  do_get_profile();
      5 
      6  var storage = getCacheStorage("disk");
      7  var mc = new MultipleCallbacks(4, function () {
      8    // Method asyncVisitStorage() gets the data from index on Cache I/O thread
      9    // with INDEX priority, so it is ensured that index contains information
     10    // about all pending writes. However, OpenCallback emulates network latency
     11    // by postponing the writes using do_execute_soon. We must do the same here
     12    // to make sure that all writes are posted to Cache I/O thread before we
     13    // visit the storage.
     14    executeSoon(function () {
     15      syncWithCacheIOThread(function () {
     16        var expectedConsumption = 4096;
     17 
     18        storage.asyncVisitStorage(
     19          // Test should store 4 entries
     20          new VisitCallback(
     21            4,
     22            expectedConsumption,
     23            ["http://a/", "http://b/", "http://c/", "http://d/"],
     24            function () {
     25              storage.asyncVisitStorage(
     26                // Still 4 entries expected, now don't walk them
     27                new VisitCallback(4, expectedConsumption, null, function () {
     28                  finish_cache2_test();
     29                }),
     30                false
     31              );
     32            }
     33          ),
     34          true
     35        );
     36      });
     37    });
     38  });
     39 
     40  asyncOpenCacheEntry(
     41    "http://a/",
     42    "disk",
     43    Ci.nsICacheStorage.OPEN_NORMALLY,
     44    null,
     45    new OpenCallback(NEW, "a1m", "a1d", function () {
     46      asyncOpenCacheEntry(
     47        "http://a/",
     48        "disk",
     49        Ci.nsICacheStorage.OPEN_NORMALLY,
     50        null,
     51        new OpenCallback(NORMAL, "a1m", "a1d", function () {
     52          mc.fired();
     53        })
     54      );
     55    })
     56  );
     57 
     58  asyncOpenCacheEntry(
     59    "http://b/",
     60    "disk",
     61    Ci.nsICacheStorage.OPEN_NORMALLY,
     62    null,
     63    new OpenCallback(NEW, "b1m", "b1d", function () {
     64      asyncOpenCacheEntry(
     65        "http://b/",
     66        "disk",
     67        Ci.nsICacheStorage.OPEN_NORMALLY,
     68        null,
     69        new OpenCallback(NORMAL, "b1m", "b1d", function () {
     70          mc.fired();
     71        })
     72      );
     73    })
     74  );
     75 
     76  asyncOpenCacheEntry(
     77    "http://c/",
     78    "disk",
     79    Ci.nsICacheStorage.OPEN_NORMALLY,
     80    null,
     81    new OpenCallback(NEW, "c1m", "c1d", function () {
     82      asyncOpenCacheEntry(
     83        "http://c/",
     84        "disk",
     85        Ci.nsICacheStorage.OPEN_NORMALLY,
     86        null,
     87        new OpenCallback(NORMAL, "c1m", "c1d", function () {
     88          mc.fired();
     89        })
     90      );
     91    })
     92  );
     93 
     94  asyncOpenCacheEntry(
     95    "http://d/",
     96    "disk",
     97    Ci.nsICacheStorage.OPEN_NORMALLY,
     98    null,
     99    new OpenCallback(NEW, "d1m", "d1d", function () {
    100      asyncOpenCacheEntry(
    101        "http://d/",
    102        "disk",
    103        Ci.nsICacheStorage.OPEN_NORMALLY,
    104        null,
    105        new OpenCallback(NORMAL, "d1m", "d1d", function () {
    106          mc.fired();
    107        })
    108      );
    109    })
    110  );
    111 
    112  do_test_pending();
    113 }