Bug 579388 - nsIMIMEService should run in chrome. r?josh
MozReview-Commit-ID: Hu2sdcOWuZX
--- a/uriloader/exthandler/tests/mochitest/mochitest.ini
+++ b/uriloader/exthandler/tests/mochitest/mochitest.ini
@@ -1,12 +1,11 @@
[DEFAULT]
skip-if = buildapp == 'b2g'
support-files =
handlerApp.xhtml
handlerApps.js
unsafeBidi_chromeScript.js
unsafeBidiFileName.sjs
-[test_badMimeType.html]
[test_handlerApps.xhtml]
skip-if = (toolkit == 'android' || os == 'mac') || e10s # OS X: bug 786938
[test_unsafeBidiChars.xhtml]
deleted file mode 100644
--- a/uriloader/exthandler/tests/mochitest/test_badMimeType.html
+++ /dev/null
@@ -1,27 +0,0 @@
-<!DOCTYPE HTML>
-<html>
-<head>
- <title>Crashtest for bad MIME type</title>
- <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
- <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
-</head>
-<body>
-<pre id="test">
-<script class="testbody" type="text/javascript">
- const Cc = SpecialPowers.Cc;
- const Ci = SpecialPowers.Ci;
- const mimeService = Cc["@mozilla.org/mime;1"].
- getService(Ci.nsIMIMEService);
- // "text/plain" has an 0xFF character appended to it. This means it's an
- // invalid string, which is tricky to enter using a text editor (I used
- // emacs' hexl-mode). It also means an ordinary text editor might drop it
- // or convert it to something that *is* valid (in UTF8). So we measure
- // its length to make sure this hasn't happened.
- var badMimeType = "text/plainÿ";
- ok(badMimeType.length == 11, "badMimeType has changed, making this test invalid");
- mimeService.getFromTypeAndExtension(badMimeType, "txt");
- ok(true, "The test shouldn't trigger a crash");
-</script>
-</pre>
-</body>
-</html>
new file mode 100644
--- /dev/null
+++ b/uriloader/exthandler/tests/unit/test_badMIMEType.js
@@ -0,0 +1,26 @@
+/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*-
+ * 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/. */
+
+function run_test() {
+ // "text/plain" has an 0xFF character appended to it. This means it's an
+ // invalid string, which is tricky to enter using a text editor (I used
+ // emacs' hexl-mode). It also means an ordinary text editor might drop it
+ // or convert it to something that *is* valid (in UTF8). So we measure
+ // its length to make sure this hasn't happened.
+ var badMimeType = "text/plainÿ";
+ do_check_eq(badMimeType.length, 11);
+
+ try {
+ var type = Cc["@mozilla.org/mime;1"].
+ getService(Ci.nsIMIMEService).
+ getFromTypeAndExtension(badMimeType, "txt");
+ } catch (e if (e instanceof Ci.nsIException &&
+ e.result == Cr.NS_ERROR_NOT_AVAILABLE)) {
+ // This is an expected exception, thrown if the type can't be determined
+ } finally {
+ }
+ // Not crashing is good enough
+ do_check_eq(true, true);
+}
--- a/uriloader/exthandler/tests/unit/xpcshell.ini
+++ b/uriloader/exthandler/tests/unit/xpcshell.ini
@@ -1,15 +1,16 @@
[DEFAULT]
head = head_handlerService.js
tail = tail_handlerService.js
skip-if = toolkit == 'gonk'
run-sequentially = Bug 912235 - Intermittent failures
[test_getTypeFromExtension_ext_to_type_mapping.js]
[test_getTypeFromExtension_with_empty_Content_Type.js]
+[test_badMIMEType.js]
[test_handlerService.js]
support-files = mailcap
# Bug 676997: test consistently fails on Android
fail-if = os == "android"
[test_punycodeURIs.js]
# Bug 676997: test consistently fails on Android
fail-if = os == "android"