summaryrefslogtreecommitdiffstats
path: root/toolkit/components/places/tests/browser/browser_favicon.js
blob: 9b4a1b97fea759b42ea6badcbf042c6f05e5246c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/* Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

const lazy = {};
ChromeUtils.defineESModuleGetters(lazy, {
  PlacesTestUtils: "resource://testing-common/PlacesTestUtils.sys.mjs",
});

const { MockRegistrar } = ChromeUtils.importESModule(
  "resource://testing-common/MockRegistrar.sys.mjs"
);

add_task(async function test_userpass() {
  // Setup the prompt to avoid showing it.
  let mockPromptService = {
    firstTimeCalled: false,
    confirmExBC() {
      if (!this.firstTimeCalled) {
        this.firstTimeCalled = true;
        return 0;
      }

      return 1;
    },
    QueryInterface: ChromeUtils.generateQI(["nsIPromptService"]),
  };
  let mockPromptServiceCID = MockRegistrar.register(
    "@mozilla.org/prompter;1",
    mockPromptService
  );
  registerCleanupFunction(() => {
    MockRegistrar.unregister(mockPromptServiceCID);
  });

  const pageUrl =
    "https://user:pass@example.org/tests/toolkit/components/places/tests/browser/favicon.html";
  const faviconUrl =
    "https://user:pass@example.org/tests/toolkit/components/places/tests/browser/favicon-normal32.png";
  const exposableFaviconUrl =
    "https://example.org/tests/toolkit/components/places/tests/browser/favicon-normal32.png";

  let faviconPromise = lazy.PlacesTestUtils.waitForNotification(
    "favicon-changed",
    async () => {
      let faviconForExposable = await lazy.PlacesTestUtils.getDatabaseValue(
        "moz_icons",
        "icon_url",
        {
          icon_url: exposableFaviconUrl,
        }
      );
      Assert.ok(faviconForExposable, "Found the icon for exposable URL");

      let faviconForOriginal = await lazy.PlacesTestUtils.getDatabaseValue(
        "moz_icons",
        "icon_url",
        {
          icon_url: faviconUrl,
        }
      );
      Assert.ok(!faviconForOriginal, "Not found the icon for the original URL");
      return true;
    }
  );

  await BrowserTestUtils.openNewForegroundTab(gBrowser, pageUrl);
  await faviconPromise;

  // Clean up.
  await PlacesUtils.history.clear();
  gBrowser.removeCurrentTab();
});