summaryrefslogtreecommitdiffstats
path: root/browser/components/urlbar/tests/browser/browser_textruns.js
blob: 6d6a9a3c2585af1e4f260f20fd66b5fb9f54b293 (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
/* Any copyright is dedicated to the Public Domain.
 * http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

/**
 * This test ensures that we limit textruns in case of very long urls or titles.
 */

add_task(async function() {
  await SpecialPowers.pushPrefEnv({
    set: [["browser.urlbar.suggest.searches", true]],
  });
  await SearchTestUtils.installSearchExtension(
    { name: "Test" },
    { setAsDefault: true }
  );

  let lotsOfSpaces = "%20".repeat(300);
  await PlacesTestUtils.addVisits({
    uri: `https://textruns.mozilla.org/${lotsOfSpaces}/test/`,
    title: `A long ${lotsOfSpaces} title`,
  });
  await UrlbarTestUtils.formHistory.add([
    { value: `A long ${lotsOfSpaces} textruns suggestion` },
  ]);

  registerCleanupFunction(async function() {
    await PlacesUtils.history.clear();
    await UrlbarTestUtils.formHistory.clear();
  });

  await UrlbarTestUtils.promiseAutocompleteResultPopup({
    window,
    value: "textruns",
  });
  let result = await UrlbarTestUtils.getDetailsOfResultAt(window, 1);
  Assert.equal(result.searchParams.engine, "Test", "Sanity check engine");
  Assert.equal(
    result.displayed.title.length,
    UrlbarUtils.MAX_TEXT_LENGTH,
    "Result title should be limited"
  );
  result = await UrlbarTestUtils.getDetailsOfResultAt(window, 2);
  Assert.equal(
    result.displayed.title.length,
    UrlbarUtils.MAX_TEXT_LENGTH,
    "Result title should be limited"
  );
  Assert.equal(
    result.displayed.url.length,
    UrlbarUtils.MAX_TEXT_LENGTH,
    "Result url should be limited"
  );
});