summaryrefslogtreecommitdiffstats
path: root/toolkit/components/passwordmgr/test/unit/test_getPasswordOrigin.js
blob: f2773ec6246a8c38dff8987de0b0df9fa5c19759 (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
/*
 * Test for LoginUtils._getPasswordOrigin
 */

"use strict";

const LMCBackstagePass = Cu.import("resource://gre/modules/LoginManagerContent.jsm");
const TESTCASES = [
  ["javascript:void(0);", null],
  ["javascript:void(0);", "javascript:", true],
  ["chrome://MyAccount", null],
  ["data:text/html,example", null],
  ["http://username:password@example.com:80/foo?bar=baz#fragment", "http://example.com", true],
  ["http://127.0.0.1:80/foo", "http://127.0.0.1"],
  ["http://[::1]:80/foo", "http://[::1]"],
  ["http://example.com:8080/foo", "http://example.com:8080"],
  ["http://127.0.0.1:8080/foo", "http://127.0.0.1:8080", true],
  ["http://[::1]:8080/foo", "http://[::1]:8080"],
  ["https://example.com:443/foo", "https://example.com"],
  ["https://[::1]:443/foo", "https://[::1]"],
  ["https://[::1]:8443/foo", "https://[::1]:8443"],
  ["ftp://username:password@[::1]:2121/foo", "ftp://[::1]:2121"],
];

for (let [input, expected, allowJS] of TESTCASES) {
  let actual = LMCBackstagePass.LoginUtils._getPasswordOrigin(input, allowJS);
  Assert.strictEqual(actual, expected, "Checking: " + input);
}