Source code

Revision control

Copy as Markdown

Other Tools

Test Info:

/* 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 http://mozilla.org/MPL/2.0/. */
"use strict";
const { validateProfilerWebChannelUrl } = ChromeUtils.importESModule(
"resource:///modules/DevToolsStartup.sys.mjs"
);
add_task(function test() {
info(
"Since the WebChannel can communicate with a content page, test that only " +
"trusted URLs can be used with this mechanism."
);
const { checkUrlIsValid, checkUrlIsInvalid } = setup();
info("Check all of the valid URLs");
checkUrlIsValid("https://profiler.firefox.com");
checkUrlIsValid("http://example.com");
checkUrlIsValid("http://localhost:4242");
checkUrlIsValid("http://localhost:32343434");
checkUrlIsValid("http://localhost:4242/");
info("Check all of the invalid URLs");
checkUrlIsInvalid("http://mozilla.com");
});
function setup() {
function checkUrlIsValid(url) {
info(`Check that ${url} is valid`);
equal(
validateProfilerWebChannelUrl(url),
url,
`"${url}" is a valid WebChannel URL.`
);
}
function checkUrlIsInvalid(url) {
info(`Check that ${url} is invalid`);
equal(
validateProfilerWebChannelUrl(url),
`"${url}" was not valid, and was reset to the base URL.`
);
}
return {
checkUrlIsValid,
checkUrlIsInvalid,
};
}