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

"use strict";

const TEST_URL =
  getRootDirectory(gTestPath).replace(
    "chrome://mochitests/content",
    "https://example.com"
  ) + "mixed_active.html";

/**
 * Tests a given url.
 * The de-emphasized parts must be wrapped in "<" and ">" chars.
 *
 * @param {string} urlFormatString The URL to test.
 * @param {string} [clobberedURLString] Normally the URL is de-emphasized
 *        in-place, thus it's enough to pass aExpected. Though, in some cases
 *        the formatter may decide to replace the URL with a fixed one, because
 *        it can't properly guess a host. In that case clobberedURLString is
 *        the expected de-emphasized value.
 */
async function testVal(urlFormatString, clobberedURLString = null) {
  let str = urlFormatString.replace(/[<>]/g, "");

  info("Setting the value property directly");
  gURLBar.value = str;
  gBrowser.selectedBrowser.focus();
  UrlbarTestUtils.checkFormatting(window, urlFormatString, {
    clobberedURLString,
    selectionType: Ci.nsISelectionController.SELECTION_URLSTRIKEOUT,
  });
}

add_task(async function test_strikeout_on_no_https_trimming() {
  await SpecialPowers.pushPrefEnv({
    set: [
      ["browser.urlbar.trimHttps", false],
      ["security.mixed_content.block_active_content", false],
    ],
  });
  await BrowserTestUtils.withNewTab(TEST_URL, function () {
    testVal("<https>://example.com/mixed_active.html");
  });
  await SpecialPowers.popPrefEnv();
});

add_task(async function test_no_strikeout_on_https_trimming() {
  await SpecialPowers.pushPrefEnv({
    set: [
      ["browser.urlbar.trimHttps", true],
      ["security.mixed_content.block_active_content", false],
    ],
  });
  await BrowserTestUtils.withNewTab(TEST_URL, function () {
    testVal(
      "https://example.com/mixed_active.html",
      "example.com/mixed_active.html"
    );
  });
  await SpecialPowers.popPrefEnv();
});