Revision control

Copy as Markdown

Other Tools

/* 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
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
const { makeMozIconImageSet, makeMozIconSrcSet } = ChromeUtils.importESModule(
);
function assertSrcSetCandidates(srcset, expectedCandidates) {
const candidates = srcset.split(", ");
Assert.deepEqual(candidates, expectedCandidates, "Should format srcset");
for (const candidate of candidates) {
const [url, scale] = candidate.split(" ");
Assert.ok(
!/[,\s]/.test(url),
`Should not leave srcset separators unescaped in ${url}`
);
Assert.ok(/^\d+x$/.test(scale), `Should have a scale descriptor: ${scale}`);
}
}
add_task(function test_makeMozIconSrcSet_escapes_filename_spaces() {
assertSrcSetCandidates(makeMozIconSrcSet("report final.txt", 16), [
]);
});
add_task(function test_makeMozIconSrcSet_escapes_filename_commas() {
assertSrcSetCandidates(
makeMozIconSrcSet("report, final.txt", 16, {
contentType: "text/plain",
}),
[
]
);
});
add_task(function test_makeMozIconSrcSet_preserves_escaped_file_urls() {
assertSrcSetCandidates(
makeMozIconSrcSet("file:///home/me/report%20final.txt", 32),
[
]
);
});
add_task(function test_makeMozIconSrcSet_appends_to_existing_query() {
assertSrcSetCandidates(
makeMozIconSrcSet("moz-icon://goat?contentType=text/plain", 16),
[
]
);
});
add_task(function test_makeMozIconSrcSet_escapes_query_delimiters() {
assertSrcSetCandidates(
makeMozIconSrcSet("report.txt", 16, {
contentType: "text/plain&scale=9?size=64#fragment",
}),
[
]
);
});
add_task(function test_makeMozIconImageSet_escapes_filename_spaces() {
Assert.equal(
makeMozIconImageSet("report final.txt", 16),
"Should format escaped CSS image-set"
);
});