tor-browser

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

test_padding_error_handle.js (2213B)


      1 /**
      2 *  This test is mainly to verify cache actions work as usual even there exists
      3 *  an unexpected padding file.
      4 */
      5 
      6 function getTempPaddingFilePath() {
      7  let cacheDir = getCacheDir();
      8  let temporaryPaddingFile = cacheDir.clone();
      9  temporaryPaddingFile.append(".padding-tmp");
     10  return temporaryPaddingFile;
     11 }
     12 
     13 function createTempPaddingFile() {
     14  let temporaryPaddingFile = getTempPaddingFilePath();
     15  temporaryPaddingFile.create(Ci.nsIFile.NORMAL_FILE_TYPE, parseInt("0644", 8));
     16 
     17  ok(
     18    temporaryPaddingFile.exists(),
     19    "Temporary padding file does be created by test"
     20  );
     21 }
     22 
     23 add_task(async function testSteps() {
     24  create_test_profile("schema_25_profile.zip");
     25  let cache = await caches.open("test");
     26 
     27  // Step 1: Verify cache.match won't fail when there is a temporary padding
     28  // file
     29  createTempPaddingFile();
     30 
     31  let response = await cache.match("https://www.mozilla.org");
     32  ok(!!response, "Upgrade from 25 to 26 do succeed");
     33 
     34  // Note: Only cache write actions(e.g. cache.put/add/addAll/delete) will
     35  // remove unexpected temporary padding file when writting an opaque response
     36  // into the file-system. Cache read actions(e.g. cache.keys/match) won't.
     37  let temporaryPaddingFile = getTempPaddingFilePath();
     38  ok(
     39    temporaryPaddingFile.exists(),
     40    "Temporary padding file doesn't be removed by cache.match"
     41  );
     42 
     43  // Step 2: Verify cache.put won't fail when there is a temporary padding
     44  // file
     45  await cache.put("https://foo.com", response);
     46  ok(
     47    !temporaryPaddingFile.exists(),
     48    "Temporary padding file does be removed by cache.put"
     49  );
     50 
     51  // Step 3: Verify cache.keys won't fail when there is a temporary padding
     52  // file
     53  createTempPaddingFile();
     54 
     55  let cacheEntries = await cache.keys("https://foo.com");
     56  Assert.strictEqual(cacheEntries.length, 1, "Cache.put does succeed");
     57 
     58  ok(
     59    temporaryPaddingFile.exists(),
     60    "Temporary padding file doesn't be removed by cache.keys"
     61  );
     62 
     63  // Step 4: Verify cache.delete won't fail when there is a temporary padding
     64  // file
     65  await cache.delete("https://foo.com");
     66  ok(
     67    !temporaryPaddingFile.exists(),
     68    "Temporary padding file does be removed by cache.delete"
     69  );
     70 
     71  await caches.delete("test");
     72 });