tor-browser

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

browser_storage_cache_navigation.js (2609B)


      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 "use strict";
      6 
      7 add_task(async function () {
      8  const URL1 = buildURLWithContent(
      9    "example.com",
     10    `<h1>example.com</h1>` +
     11      `<script>
     12        caches.open("lorem").then(cache => {
     13          cache.add("${URL_ROOT_COM_SSL}storage-blank.html");
     14        });
     15        function clear() {
     16          caches.delete("lorem");
     17        }
     18      </script>`
     19  );
     20  const URL2 = buildURLWithContent(
     21    "example.net",
     22    `<h1>example.net</h1>` +
     23      `<script>
     24        caches.open("foo").then(cache => {
     25          cache.add("${URL_ROOT_NET_SSL}storage-blank.html");
     26        });
     27        function clear() {
     28          caches.delete("foo");
     29        }
     30      </script>`
     31  );
     32 
     33  // open tab
     34  await openTabAndSetupStorage(URL1);
     35  const doc = gPanelWindow.document;
     36 
     37  // Check first domain
     38  // check that host appears in the storage tree
     39  checkTree(doc, ["Cache", "https://example.com", "lorem"]);
     40  // check the table for values
     41  await selectTreeItem(["Cache", "https://example.com", "lorem"]);
     42  checkCacheData(URL_ROOT_COM_SSL + "storage-blank.html", "OK");
     43 
     44  // clear up the cache before navigating
     45  info("Cleaning up cache…");
     46  await SpecialPowers.spawn(gBrowser.selectedBrowser, [], async function () {
     47    const win = content.wrappedJSObject;
     48    await win.clear();
     49  });
     50 
     51  // Check second domain
     52  await navigateTo(URL2);
     53 
     54  info("Waiting until Cache > example.net is available in the UI");
     55  await waitUntil(() => gUI.tree.exists(["Cache", "https://example.net"]));
     56 
     57  info("Select the Cache view in order to force updating it");
     58  await selectTreeItem(["Cache", "https://example.net"]);
     59 
     60  // wait for storage tree refresh, and check host
     61  info("Waiting for storage tree to update…");
     62  await waitUntil(() => isInTree(doc, ["Cache", "https://example.net", "foo"]));
     63 
     64  ok(
     65    !isInTree(doc, ["Cache", "https://example.com"]),
     66    "example.com item is not in the tree anymore"
     67  );
     68 
     69  // check the table for values
     70  await selectTreeItem(["Cache", "https://example.net", "foo"]);
     71  checkCacheData(URL_ROOT_NET_SSL + "storage-blank.html", "OK");
     72 
     73  info("Check that the Cache node still has the expected label");
     74  is(
     75    getTreeNodeLabel(doc, ["Cache"]),
     76    "Cache Storage",
     77    "Cache item is properly displayed"
     78  );
     79 });
     80 
     81 function checkCacheData(url, status) {
     82  is(
     83    gUI.table.items.get(url)?.status,
     84    status,
     85    `Table row has an entry for: ${url} with status: ${status}`
     86  );
     87 }