/* Any copyright is dedicated to the Public Domain.
 * http://creativecommons.org/publicdomain/zero/1.0/ */

/*
 * Test Yahoo search plugin URLs
 */

"use strict";

const BROWSER_SEARCH_PREF = "browser.search.";

function test() {
  let engine = Services.search.getEngineByName("Yahoo");
  ok(engine, "Yahoo");

  let base = "https://search.yahoo.com/yhs/search?p=foo&ei=UTF-8&hspart=mozilla";
  let url;

  // Test search URLs (including purposes).
  url = engine.getSubmission("foo").uri.spec;
  is(url, base, "Check search URL for 'foo'");

  // Check search suggestion URL.
  url = engine.getSubmission("foo", "application/x-suggestions+json").uri.spec;
  is(url, "https://search.yahoo.com/sugg/ff?output=fxjson&appid=ffd&command=foo", "Check search suggestion URL for 'foo'");

  // Check all other engine properties.
  const EXPECTED_ENGINE = {
    name: "Yahoo",
    alias: null,
    description: "Yahoo Search",
    searchForm: "https://search.yahoo.com/yhs/search?p=&ei=UTF-8&hspart=mozilla",
    type: Ci.nsISearchEngine.TYPE_MOZSEARCH,
    hidden: false,
    wrappedJSObject: {
      queryCharset: "UTF-8",
      "_iconURL": "data:image/x-icon;base64,[encoded data, 8540 characters]",
      _urls : [
        {
          type: "application/x-suggestions+json",
          method: "GET",
          template: "https://search.yahoo.com/sugg/ff",
          params: [
            {
              name: "output",
              value: "fxjson",
              purpose: undefined,
            },
            {
              name: "appid",
              value: "ffd",
              purpose: undefined,
            },
            {
              name: "command",
              value: "{searchTerms}",
              purpose: undefined,
            },
          ],
        },
        {
          type: "text/html",
          method: "GET",
          template: "https://search.yahoo.com/yhs/search",
          params: [
            {
              name: "p",
              value: "{searchTerms}",
              purpose: undefined,
            },
            {
              name: "ei",
              value: "UTF-8",
              purpose: undefined,
            },
            {
              name: "hspart",
              value: "mozilla",
              purpose: undefined,
            },
            {
              name: "hsimp",
              value: "yhs-001",
              purpose: "searchbar",
            },
            {
              name: "hsimp",
              value: "yhs-002",
              purpose: "keyword",
            },
            {
              name: "hsimp",
              value: "yhs-003",
              purpose: "homepage",
            },
            {
              name: "hsimp",
              value: "yhs-004",
              purpose: "newtab",
            },
            {
              name: "hsimp",
              value: "yhs-005",
              purpose: "contextmenu",
            },
          ],
          mozparams: {},
        },
      ],
    },
  };

  isSubObjectOf(EXPECTED_ENGINE, engine, "Yahoo");
}
