summaryrefslogtreecommitdiffstats
path: root/toolkit/components/search/tests/xpcshell/test_opensearch_icons_invalid.js
blob: 4f81b0e9d3211dacf4669cd9b3bbec775ca5c26f (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
/* Any copyright is dedicated to the Public Domain.
 * http://creativecommons.org/publicdomain/zero/1.0/ */

/* Test that an installed engine can't use a resource URL for an icon */

"use strict";

add_task(async function setup() {
  let server = useHttpServer("");
  server.registerContentType("sjs", "sjs");
  await AddonTestUtils.promiseStartupManager();
});

add_task(async function test_installedresourceicon() {
  let engine1 = await SearchTestUtils.promiseNewSearchEngine({
    url: `${gDataUrl}opensearch/resourceicon.xml`,
  });
  let engine2 = await SearchTestUtils.promiseNewSearchEngine({
    url: `${gDataUrl}opensearch/chromeicon.xml`,
  });

  Assert.equal(null, engine1.iconURI);
  Assert.equal(null, engine2.iconURI);
});

add_task(async function test_installedhttpplace() {
  let observed = TestUtils.consoleMessageObserved(msg => {
    return msg.wrappedJSObject.arguments[0].includes(
      "Content type does not match expected"
    );
  });

  // The easiest way to test adding the icon is via a generated xml, otherwise
  // we have to somehow insert the address of the server into it.
  let engine = await SearchTestUtils.promiseNewSearchEngine({
    url:
      `${gDataUrl}data/engineMaker.sjs?` +
      JSON.stringify({
        baseURL: gDataUrl,
        image: "opensearch/resourceicon.xml",
        name: "invalidicon",
        method: "GET",
      }),
  });

  await observed;

  Assert.equal(null, engine.iconURI, "Should not have set an iconURI");
});