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

async function testVal(win, url) {
  info(`Testing ${url}`);
  win.gURLBar.setURI(makeURI(url));

  let urlbar = win.gURLBar;
  urlbar.blur();

  for (let width of [1000, 800]) {
    win.resizeTo(width, 500);
    await win.promiseDocumentFlushed(() => {});
    Assert.greater(
      urlbar.inputField.scrollWidth,
      urlbar.inputField.clientWidth,
      "Check The input field overflows"
    );
    // Resize is handled on a timer, so we must wait for it.
    await TestUtils.waitForCondition(
      () => urlbar.inputField.scrollLeft == urlbar.inputField.scrollLeftMax,
      "The urlbar input field is completely scrolled to the end"
    );
    await TestUtils.waitForCondition(
      () => urlbar.getAttribute("textoverflow") == "left",
      "Wait for the textoverflow attribute"
    );
  }
}

add_task(async function () {
  // We use a new tab for the test to be sure all the tab switching and loading
  // is complete before starting, otherwise onLocationChange for this tab could
  // override the value we set with an empty value.
  let win = await BrowserTestUtils.openNewBrowserWindow();
  registerCleanupFunction(() => BrowserTestUtils.closeWindow(win));

  let lotsOfSpaces = "%20".repeat(200);

  // اسماء.شبكة
  let rtlDomain =
    "\u0627\u0633\u0645\u0627\u0621\u002e\u0634\u0628\u0643\u0629";

  // Mix the direction of the tests to cover more cases, and to ensure the
  // textoverflow attribute changes every time, because tewtVal waits for that.
  await testVal(win, `https://${rtlDomain}/${lotsOfSpaces}/test/`);

  info("Test with formatting and trimurl disabled");
  await SpecialPowers.pushPrefEnv({
    set: [
      ["browser.urlbar.formatting.enabled", false],
      ["browser.urlbar.trimURLs", false],
    ],
  });

  await testVal(win, `https://${rtlDomain}/${lotsOfSpaces}/test/`);
  await testVal(win, `http://${rtlDomain}/${lotsOfSpaces}/test/`);
});