summaryrefslogtreecommitdiffstats
path: root/toolkit/components/passwordmgr/test/browser/browser_http_autofill.js
blob: beb928a34e3bf88082a8d5761d4821b3b52fbb8b (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
const TEST_URL_PATH = "://example.org/browser/toolkit/components/passwordmgr/test/browser/";

add_task(function* setup() {
  let login = LoginTestUtils.testData.formLogin({
    hostname: "http://example.org",
    formSubmitURL: "http://example.org",
    username: "username",
    password: "password",
  });
  Services.logins.addLogin(login);
  login = LoginTestUtils.testData.formLogin({
    hostname: "http://example.org",
    formSubmitURL: "http://another.domain",
    username: "username",
    password: "password",
  });
  Services.logins.addLogin(login);
  yield SpecialPowers.pushPrefEnv({ "set": [["signon.autofillForms.http", false]] });
});

add_task(function* test_http_autofill() {
  for (let scheme of ["http", "https"]) {
    let tab = yield BrowserTestUtils
      .openNewForegroundTab(gBrowser, `${scheme}${TEST_URL_PATH}form_basic.html`);

    let [username, password] = yield ContentTask.spawn(gBrowser.selectedBrowser, null, function* () {
      let doc = content.document;
      let contentUsername = doc.getElementById("form-basic-username").value;
      let contentPassword = doc.getElementById("form-basic-password").value;
      return [contentUsername, contentPassword];
    });

    is(username, scheme == "http" ? "" : "username", "Username filled correctly");
    is(password, scheme == "http" ? "" : "password", "Password filled correctly");

    gBrowser.removeTab(tab);
  }
});

add_task(function* test_iframe_in_http_autofill() {
  for (let scheme of ["http", "https"]) {
    let tab = yield BrowserTestUtils
      .openNewForegroundTab(gBrowser, `${scheme}${TEST_URL_PATH}form_basic_iframe.html`);

    let [username, password] = yield ContentTask.spawn(gBrowser.selectedBrowser, null, function* () {
      let doc = content.document;
      let iframe = doc.getElementById("test-iframe");
      let contentUsername = iframe.contentWindow.document.getElementById("form-basic-username").value;
      let contentPassword = iframe.contentWindow.document.getElementById("form-basic-password").value;
      return [contentUsername, contentPassword];
    });

    is(username, scheme == "http" ? "" : "username", "Username filled correctly");
    is(password, scheme == "http" ? "" : "password", "Password filled correctly");

    gBrowser.removeTab(tab);
  }
});

add_task(function* test_http_action_autofill() {
  for (let type of ["insecure", "secure"]) {
    let tab = yield BrowserTestUtils
      .openNewForegroundTab(gBrowser, `https${TEST_URL_PATH}form_cross_origin_${type}_action.html`);

    let [username, password] = yield ContentTask.spawn(gBrowser.selectedBrowser, null, function* () {
      let doc = content.document;
      let contentUsername = doc.getElementById("form-basic-username").value;
      let contentPassword = doc.getElementById("form-basic-password").value;
      return [contentUsername, contentPassword];
    });

    is(username, type == "insecure" ? "" : "username", "Username filled correctly");
    is(password, type == "insecure" ? "" : "password", "Password filled correctly");

    gBrowser.removeTab(tab);
  }
});