summaryrefslogtreecommitdiffstats
path: root/toolkit/components/passwordmgr/test/unit/test_doLoginsMatch.js
blob: fb38f08cf7c6967380244d278e050419359108c6 (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
/**
 * Test LoginHelper.doLoginsMatch
 */

add_task(function test_formActionOrigin_ignoreSchemes() {
  let httpActionLogin = TestData.formLogin();
  let httpsActionLogin = TestData.formLogin({
    formActionOrigin: "https://www.example.com",
  });
  let jsActionLogin = TestData.formLogin({
    formActionOrigin: "javascript:",
  });
  let emptyActionLogin = TestData.formLogin({
    formActionOrigin: "",
  });

  Assert.notEqual(
    httpActionLogin.formActionOrigin,
    httpsActionLogin.formActionOrigin,
    "Ensure actions differ"
  );

  const TEST_CASES = [
    [httpActionLogin, httpActionLogin, true],
    [httpsActionLogin, httpsActionLogin, true],
    [jsActionLogin, jsActionLogin, true],
    [emptyActionLogin, emptyActionLogin, true],
    // only differing by scheme:
    [httpsActionLogin, httpActionLogin, true],
    [httpActionLogin, httpsActionLogin, true],

    // empty matches everything
    [httpsActionLogin, emptyActionLogin, true],
    [emptyActionLogin, httpsActionLogin, true],
    [jsActionLogin, emptyActionLogin, true],
    [emptyActionLogin, jsActionLogin, true],

    // Begin false cases:
    [httpsActionLogin, jsActionLogin, false],
    [jsActionLogin, httpsActionLogin, false],
    [httpActionLogin, jsActionLogin, false],
    [jsActionLogin, httpActionLogin, false],
  ];

  for (let [login1, login2, expected] of TEST_CASES) {
    Assert.strictEqual(
      LoginHelper.doLoginsMatch(login1, login2, {
        ignorePassword: false,
        ignoreSchemes: true,
      }),
      expected,
      `LoginHelper.doLoginsMatch:
\t${JSON.stringify(login1)}
\t${JSON.stringify(login2)}`
    );
  }
});