Source code
Revision control
Copy as Markdown
Other Tools
Test Info: Warnings
- This test runs only with pattern: os != 'android'
- Manifest: browser/components/urlbar/tests/unit/xpcshell.toml
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
// Tests for UrlbarUtils.isOriginUrl().
"use strict";
add_task(function test_basic_origins() {
const ORIGIN_URLS = [
// Group them as origins because they carry no information.
];
for (let url of ORIGIN_URLS) {
Assert.ok(
UrlbarUtils.isOriginUrl(url),
`${url} should be recognized as an origin URL`
);
}
});
add_task(function test_urls_with_paths() {
const DEEP_URLS = [
];
for (let url of DEEP_URLS) {
Assert.ok(
!UrlbarUtils.isOriginUrl(url),
`${url} should NOT be recognized as an origin URL`
);
}
});
add_task(function test_urls_with_query_strings() {
const QUERY_URLS = [
];
for (let url of QUERY_URLS) {
Assert.ok(
!UrlbarUtils.isOriginUrl(url),
`${url} should NOT be an origin (has query string)`
);
}
});
add_task(function test_urls_with_fragments() {
const FRAGMENT_URLS = [
];
for (let url of FRAGMENT_URLS) {
Assert.ok(
!UrlbarUtils.isOriginUrl(url),
`${url} should NOT be an origin (has fragment)`
);
}
});
add_task(function test_urls_with_query_and_fragment() {
const COMBINED_URLS = [
];
for (let url of COMBINED_URLS) {
Assert.ok(
!UrlbarUtils.isOriginUrl(url),
`${url} should NOT be an origin (has both query and fragment)`
);
}
});
add_task(function test_deep_urls_with_query_and_fragment() {
const DEEP_COMBINED_URLS = [
];
for (let url of DEEP_COMBINED_URLS) {
Assert.ok(!UrlbarUtils.isOriginUrl(url), `${url} should NOT be an origin`);
}
});
add_task(function test_invalid_input() {
const INVALID_INPUTS = [
"",
"not a url",
"example.com",
"example",
"://missing-scheme",
"http://",
" ",
"foo:bar:baz",
];
for (let input of INVALID_INPUTS) {
Assert.ok(
!UrlbarUtils.isOriginUrl(input),
`"${input}" should return false (unparseable)`
);
}
});
add_task(function test_special_schemes() {
Assert.ok(
!UrlbarUtils.isOriginUrl("about:blank"),
"about: URLs should not be treated as origins"
);
Assert.ok(
!UrlbarUtils.isOriginUrl("data:text/html,hello"),
"data: URLs should not be treated as origins"
);
Assert.ok(
!UrlbarUtils.isOriginUrl("javascript:void(0)"),
"javascript: URLs should not be treated as origins"
);
});
add_task(function test_edge_cases() {
// Standard port should be normalized away by URL parser.
Assert.ok(
"https with standard port 443 should be origin-only"
);
Assert.ok(
"http with standard port 80 should be origin-only"
);
// Non-standard port.
Assert.ok(
"Non-standard port should still be origin-only"
);
// Double slash path is NOT origin-only.
Assert.ok(
"Double trailing slash means pathname is '//' not '/'"
);
});