tor-browser

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

browser_favicon_store.js (1652B)


      1 /* Any copyright is dedicated to the Public Domain.
      2 * https://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 // Test that favicons are stored.
      5 
      6 registerCleanupFunction(async () => {
      7  Services.cache2.clear();
      8  await PlacesTestUtils.clearFavicons();
      9  await PlacesUtils.history.clear();
     10 });
     11 
     12 async function test_icon(pageUrl, iconUrl) {
     13  let iconPromise = waitForFaviconMessage(true, iconUrl);
     14  let storedIconPromise = PlacesTestUtils.waitForNotification(
     15    "favicon-changed",
     16    events => events.some(e => e.url == pageUrl)
     17  );
     18  await BrowserTestUtils.withNewTab(pageUrl, async () => {
     19    let { iconURL } = await iconPromise;
     20    Assert.equal(iconURL, iconUrl, "Should have seen the expected icon.");
     21 
     22    // Ensure the favicon has been stored.
     23    await storedIconPromise;
     24    let favicon = await PlacesUtils.favicons.getFaviconForPage(
     25      Services.io.newURI(pageUrl)
     26    );
     27    Assert.equal(
     28      favicon.uri.spec,
     29      iconUrl,
     30      "Should have stored the expected icon."
     31    );
     32  });
     33 }
     34 
     35 add_task(async function test_icon_stored() {
     36  for (let [pageUrl, iconUrl] of [
     37    [
     38      "https://example.net/browser/browser/base/content/test/favicons/datauri-favicon.html",
     39      "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAATklEQVRYhe3SIQ4AIBADwf7/04elBAtrVlSduGnSTDJ7cuT1PQJwwO+Hl7sAGAA07gjAAfgIBeAAoHFHAA7ARygABwCNOwJwAD5CATRgAYXh+kypw86nAAAAAElFTkSuQmCC",
     40    ],
     41    [
     42      "https://example.net/browser/browser/base/content/test/favicons/file_favicon.html",
     43      "https://example.net/browser/browser/base/content/test/favicons/file_favicon.png",
     44    ],
     45  ]) {
     46    await test_icon(pageUrl, iconUrl);
     47  }
     48 });