summaryrefslogtreecommitdiffstats
path: root/toolkit/components/passwordmgr/test/browser/browser_formless_submit_chrome.js
blob: bb7e973db620efbeb6d7931878262147715b7cbc (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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
/*
 * Test that browser chrome UI interactions don't trigger a capture doorhanger.
 */

"use strict";

async function fillTestPage(
  aBrowser,
  username = "my_username",
  password = "my_password"
) {
  let notif = getCaptureDoorhanger("any", undefined, aBrowser);
  Assert.ok(!notif, "No doorhangers should be present before filling the form");

  await changeContentFormValues(aBrowser, {
    "#form-basic-username": username,
    "#form-basic-password": password,
  });
  if (LoginHelper.passwordEditCaptureEnabled) {
    // Filling the password will generate a dismissed doorhanger.
    // Check and remove that before running the rest of the task
    notif = await waitForDoorhanger(aBrowser, "any");
    Assert.ok(notif.dismissed, "Only a dismissed doorhanger should be present");
    await cleanupDoorhanger(notif);
  }
}

function withTestPage(aTaskFn) {
  return BrowserTestUtils.withNewTab(
    {
      gBrowser,
      url: "https://example.com" + DIRECTORY_PATH + "formless_basic.html",
    },
    async function (aBrowser) {
      info("tab opened");
      await fillTestPage(aBrowser);
      await aTaskFn(aBrowser);

      // Give a chance for the doorhanger to appear
      await new Promise(resolve => SimpleTest.executeSoon(resolve));
      let notif = getCaptureDoorhanger("any");
      Assert.ok(!notif, "No doorhanger should be present");
      await cleanupDoorhanger(notif);
    }
  );
}

add_setup(async function () {
  await SimpleTest.promiseFocus(window);
});

add_task(async function test_urlbar_new_URL() {
  await withTestPage(async function (aBrowser) {
    gURLBar.value = "";
    let focusPromise = BrowserTestUtils.waitForEvent(gURLBar, "focus");
    gURLBar.focus();
    await focusPromise;
    info("focused");
    EventUtils.sendString("http://mochi.test:8888/");
    EventUtils.synthesizeKey("KEY_Enter");
    await BrowserTestUtils.browserLoaded(
      aBrowser,
      false,
      "http://mochi.test:8888/"
    );
  });
});

add_task(async function test_urlbar_fragment_enter() {
  await withTestPage(function (aBrowser) {
    gURLBar.focus();
    gURLBar.select();
    EventUtils.synthesizeKey("KEY_ArrowRight");
    EventUtils.sendString("#fragment");
    EventUtils.synthesizeKey("KEY_Enter");
  });
});

add_task(async function test_backButton_forwardButton() {
  await withTestPage(async function (aBrowser) {
    info("Loading formless_basic.html?second");
    // Load a new page in the tab so we can test going back
    BrowserTestUtils.startLoadingURIString(
      aBrowser,
      "https://example.com" + DIRECTORY_PATH + "formless_basic.html?second"
    );
    await BrowserTestUtils.browserLoaded(
      aBrowser,
      false,
      "https://example.com" + DIRECTORY_PATH + "formless_basic.html?second"
    );
    info("Loaded formless_basic.html?second");
    await fillTestPage(aBrowser, "my_username", "password_2");

    info("formless_basic.html?second form is filled, clicking back");
    let backPromise = BrowserTestUtils.browserStopped(aBrowser);
    EventUtils.synthesizeMouseAtCenter(
      document.getElementById("back-button"),
      {}
    );
    await backPromise;

    // Give a chance for the doorhanger to appear
    await new Promise(resolve => SimpleTest.executeSoon(resolve));
    Assert.ok(!getCaptureDoorhanger("any"), "No doorhanger should be present");

    // Now go forward again after filling
    await fillTestPage(aBrowser, "my_username", "password_3");

    let forwardButton = document.getElementById("forward-button");
    await BrowserTestUtils.waitForCondition(() => {
      return !forwardButton.disabled;
    });
    let forwardPromise = BrowserTestUtils.browserStopped(aBrowser);
    info("click the forward button");
    EventUtils.synthesizeMouseAtCenter(forwardButton, {});
    await forwardPromise;
    info("done");
  });
});

add_task(async function test_reloadButton() {
  await withTestPage(async function (aBrowser) {
    let reloadButton = document.getElementById("reload-button");
    let loadPromise = BrowserTestUtils.browserLoaded(
      aBrowser,
      false,
      "https://example.com" + DIRECTORY_PATH + "formless_basic.html"
    );

    await BrowserTestUtils.waitForCondition(() => {
      return !reloadButton.disabled;
    });
    EventUtils.synthesizeMouseAtCenter(reloadButton, {});
    await loadPromise;
  });
});

add_task(async function test_back_keyboard_shortcut() {
  await withTestPage(async function (aBrowser) {
    // Load a new page in the tab so we can test going back
    BrowserTestUtils.startLoadingURIString(
      aBrowser,
      "https://example.com" + DIRECTORY_PATH + "formless_basic.html?second"
    );
    await BrowserTestUtils.browserLoaded(
      aBrowser,
      false,
      "https://example.com" + DIRECTORY_PATH + "formless_basic.html?second"
    );
    await fillTestPage(aBrowser);

    let backPromise = BrowserTestUtils.browserStopped(aBrowser);

    const goBackKeyModifier =
      AppConstants.platform == "macosx" ? { metaKey: true } : { altKey: true };
    EventUtils.synthesizeKey("KEY_ArrowLeft", goBackKeyModifier);

    await backPromise;
  });
});