summaryrefslogtreecommitdiffstats
path: root/browser/components/urlbar/tests/browser/browser_customizeMode.js
blob: 0ed26644cc2fba9201de766d4a7e88769bbce3e1 (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
63
64
65
66
67
68
69
70
71
72
73
/* Any copyright is dedicated to the Public Domain.
 * http://creativecommons.org/publicdomain/zero/1.0/ */

// This test checks that the left/right arrow keys and home/end keys work in
// the urlbar after customize mode starts and ends.

"use strict";

add_task(async function test() {
  let win = await BrowserTestUtils.openNewBrowserWindow();
  await startCustomizing(win);
  await endCustomizing(win);

  let urlbar = win.gURLBar;

  let value = "example";
  urlbar.value = value;
  urlbar.focus();
  urlbar.selectionEnd = value.length;
  urlbar.selectionStart = value.length;

  // left
  EventUtils.synthesizeKey("KEY_ArrowLeft", {}, win);
  Assert.equal(urlbar.selectionStart, value.length - 1);
  Assert.equal(urlbar.selectionEnd, value.length - 1);

  // home
  if (AppConstants.platform == "macosx") {
    EventUtils.synthesizeKey("KEY_ArrowLeft", { metaKey: true }, win);
  } else {
    EventUtils.synthesizeKey("KEY_Home", {}, win);
  }
  Assert.equal(urlbar.selectionStart, 0);
  Assert.equal(urlbar.selectionEnd, 0);

  // right
  EventUtils.synthesizeKey("KEY_ArrowRight", {}, win);
  Assert.equal(urlbar.selectionStart, 1);
  Assert.equal(urlbar.selectionEnd, 1);

  // end
  if (AppConstants.platform == "macosx") {
    EventUtils.synthesizeKey("KEY_ArrowRight", { metaKey: true }, win);
  } else {
    EventUtils.synthesizeKey("KEY_End", {}, win);
  }
  Assert.equal(urlbar.selectionStart, value.length);
  Assert.equal(urlbar.selectionEnd, value.length);

  await BrowserTestUtils.closeWindow(win);
});

async function startCustomizing(win = window) {
  if (win.document.documentElement.getAttribute("customizing") != "true") {
    let eventPromise = BrowserTestUtils.waitForEvent(
      win.gNavToolbox,
      "customizationready"
    );
    win.gCustomizeMode.enter();
    await eventPromise;
  }
}

async function endCustomizing(win = window) {
  if (win.document.documentElement.getAttribute("customizing") == "true") {
    let eventPromise = BrowserTestUtils.waitForEvent(
      win.gNavToolbox,
      "aftercustomization"
    );
    win.gCustomizeMode.exit();
    await eventPromise;
  }
}