tor-browser

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

browser_bug968273.js (2004B)


      1 /* This Source Code Form is subject to the terms of the Mozilla Public
      2 * License, v. 2.0. If a copy of the MPL was not distributed with this
      3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      4 
      5 function OpenCacheEntry(key, flags, lci) {
      6  return new Promise(resolve => {
      7    key = Services.io.newURI(key);
      8    function CacheListener() {}
      9    CacheListener.prototype = {
     10      QueryInterface: ChromeUtils.generateQI(["nsICacheEntryOpenCallback"]),
     11 
     12      onCacheEntryCheck() {
     13        return Ci.nsICacheEntryOpenCallback.ENTRY_WANTED;
     14      },
     15 
     16      onCacheEntryAvailable(entry) {
     17        resolve(entry);
     18      },
     19 
     20      run() {
     21        let storage = Services.cache2.diskCacheStorage(lci);
     22        storage.asyncOpenURI(key, "", flags, this);
     23      },
     24    };
     25 
     26    new CacheListener().run();
     27  });
     28 }
     29 
     30 async function do_test_cache_persistent(https) {
     31  let scheme = https ? "https" : "http";
     32  let url =
     33    scheme + "://example.com/browser/netwerk/test/browser/file_bug968273.html";
     34  let redirectUrl =
     35    scheme +
     36    "://example.com/browser/netwerk/test/browser/bug968273_redirect.html";
     37 
     38  await BrowserTestUtils.openNewForegroundTab(gBrowser, url, true);
     39 
     40  let loadContextInfo = Services.loadContextInfo.custom(false, {
     41    partitionKey: `(${scheme},example.com)`,
     42  });
     43 
     44  let entry = await OpenCacheEntry(
     45    redirectUrl,
     46    Ci.nsICacheStorage.OPEN_NORMALLY,
     47    loadContextInfo
     48  );
     49 
     50  Assert.equal(
     51    entry.persistent,
     52    https,
     53    https
     54      ? "Permanent redirects over HTTPS can be persistent"
     55      : "Permanent redirects over HTTP cannot be persistent"
     56  );
     57 
     58  gBrowser.removeCurrentTab();
     59  Services.cache2.clear();
     60 }
     61 
     62 add_task(async function setupTestingPref() {
     63  await SpecialPowers.pushPrefEnv({
     64    set: [
     65      ["network.cache.persist_permanent_redirects_http", false],
     66      ["dom.security.https_first", false],
     67    ],
     68  });
     69 });
     70 
     71 add_task(async function test_cache_persistent() {
     72  await do_test_cache_persistent(true);
     73  await do_test_cache_persistent(false);
     74 });