summaryrefslogtreecommitdiffstats
path: root/uriloader/exthandler/tests
diff options
context:
space:
mode:
Diffstat (limited to 'uriloader/exthandler/tests')
-rw-r--r--uriloader/exthandler/tests/mochitest/browser_download_idn_blocklist.js5
-rw-r--r--uriloader/exthandler/tests/unit/test_getFromTypeAndExtension.js122
-rw-r--r--uriloader/exthandler/tests/unit/xpcshell.toml1
3 files changed, 124 insertions, 4 deletions
diff --git a/uriloader/exthandler/tests/mochitest/browser_download_idn_blocklist.js b/uriloader/exthandler/tests/mochitest/browser_download_idn_blocklist.js
index a5de2870af..0d49a898a0 100644
--- a/uriloader/exthandler/tests/mochitest/browser_download_idn_blocklist.js
+++ b/uriloader/exthandler/tests/mochitest/browser_download_idn_blocklist.js
@@ -24,10 +24,7 @@ server.registerFile(`/${encodeURIComponent(TEST_FILE)}`, file);
*/
add_task(async function test_idn_blocklisted_char_not_escaped() {
await SpecialPowers.pushPrefEnv({
- set: [
- ["browser.download.always_ask_before_handling_new_types", false],
- ["dom.block_download_insecure", false],
- ],
+ set: [["browser.download.always_ask_before_handling_new_types", false]],
});
info("Testing with " + TEST_URL);
diff --git a/uriloader/exthandler/tests/unit/test_getFromTypeAndExtension.js b/uriloader/exthandler/tests/unit/test_getFromTypeAndExtension.js
index 6f4fe52a49..87a013812b 100644
--- a/uriloader/exthandler/tests/unit/test_getFromTypeAndExtension.js
+++ b/uriloader/exthandler/tests/unit/test_getFromTypeAndExtension.js
@@ -15,3 +15,125 @@ add_task(async function test_utf8_extension() {
Assert.equal(someMIME.primaryExtension, ".ั‚ะตัั‚");
}
});
+
+function getLocalHandlers(mimeInfo) {
+ try {
+ const appList = mimeInfo?.possibleLocalHandlers || [];
+ return appList;
+ } catch (err) {
+ // if the mime info on this platform doesn't support getting local handlers,
+ // we don't need to test
+ if (err.result == Cr.NS_ERROR_NOT_IMPLEMENTED) {
+ return [];
+ }
+
+ // otherwise, throw the err because the test is broken
+ throw err;
+ }
+}
+
+add_task(async function test_default_executable() {
+ if (AppConstants.platform == "linux") {
+ return;
+ }
+
+ const mimeService = Cc["@mozilla.org/mime;1"].getService(Ci.nsIMIMEService);
+ let mimeInfo = mimeService.getFromTypeAndExtension("text/html", "html");
+ if (mimeInfo !== undefined) {
+ if (mimeInfo.hasDefaultHandler) {
+ let defaultExecutableFile = mimeInfo.defaultExecutable;
+ if (defaultExecutableFile) {
+ if (AppConstants.platform == "win") {
+ Assert.ok(
+ defaultExecutableFile.leafName.endsWith(".exe"),
+ "Default browser on Windows should end with .exe"
+ );
+ }
+ }
+
+ let foundDefaultInList = false;
+
+ let appList = getLocalHandlers(mimeInfo);
+ if (!appList.length) {
+ return;
+ }
+
+ for (let index = 0; index < appList.length; index++) {
+ let app = appList.queryElementAt(index, Ci.nsILocalHandlerApp);
+ let executablePath = app.executable.path;
+
+ if (executablePath == defaultExecutableFile.path) {
+ foundDefaultInList = true;
+ break;
+ }
+ }
+
+ Assert.ok(
+ foundDefaultInList,
+ "The default browser must be returned in the list of executables from the mime info"
+ );
+ } else {
+ Assert.throws(
+ () => mimeInfo.defaultExecutable,
+ /NS_ERROR_FAILURE/,
+ "Fetching the defaultExecutable should generate an exception; this line should never be reached"
+ );
+ }
+ }
+});
+
+add_task(async function test_pretty_name_for_edge() {
+ if (AppConstants.platform == "win" && !AppConstants.IS_ESR) {
+ const mimeService = Cc["@mozilla.org/mime;1"].getService(Ci.nsIMIMEService);
+
+ let mimeInfo = mimeService.getFromTypeAndExtension("text/html", "html");
+ let appList = getLocalHandlers(mimeInfo);
+ for (let index = 0; index < appList.length; index++) {
+ let app = appList.queryElementAt(index, Ci.nsILocalHandlerApp);
+ if (app) {
+ let executableName = app.executable?.displayName;
+ if (executableName) {
+ let prettyName = await app.prettyNameAsync();
+
+ // Hardcode Edge, as an extra test, when it's installed
+ if (executableName == "msedge.exe") {
+ Assert.equal(
+ prettyName,
+ "Microsoft Edge",
+ "The generated pretty name for MS Edge should match the expectation."
+ );
+ }
+
+ // The pretty name should always be something nicer than the executable name.
+ // This isn't testing that's nice, but should be good enough to validate that
+ // something other than the executable is found.
+ Assert.notEqual(executableName, prettyName);
+ }
+ }
+ }
+ }
+});
+
+add_task(async function test_pretty_names_match_names_on_non_windows() {
+ if (AppConstants.platform != "win") {
+ const mimeService = Cc["@mozilla.org/mime;1"].getService(Ci.nsIMIMEService);
+
+ let mimeInfo = mimeService.getFromTypeAndExtension("text/html", "html");
+ let appList = getLocalHandlers(mimeInfo);
+ for (let index = 0; index < appList.length; index++) {
+ let app = appList.queryElementAt(index, Ci.nsILocalHandlerApp);
+ if (app) {
+ if (app.executable) {
+ let name = app.executable.name;
+ let prettyName = await app.prettyNameAsync();
+
+ Assert.equal(
+ prettyName,
+ name,
+ "On platforms other than windows, the prettyName and the name of file handlers should be the same."
+ );
+ }
+ }
+ }
+ }
+});
diff --git a/uriloader/exthandler/tests/unit/xpcshell.toml b/uriloader/exthandler/tests/unit/xpcshell.toml
index 216ad49555..91e1f65e48 100644
--- a/uriloader/exthandler/tests/unit/xpcshell.toml
+++ b/uriloader/exthandler/tests/unit/xpcshell.toml
@@ -18,6 +18,7 @@ skip-if = [
skip-if = ["os == 'mac'"] # Bug 1817727
["test_getFromTypeAndExtension.js"]
+skip-if = ["os == 'android'"]
["test_getMIMEInfo_pdf.js"]