Bug 579388 - nsIMIMEService should run in chrome. r=jaas+18821

MozReview-Commit-ID: Hu2sdcOWuZX

--HG--
extra : rebase_source : a6950d5971343c63e60d0acddd77e130fc2f45cb
This commit is contained in:
Gian-Carlo Pascutto 2016-06-15 12:29:30 +01:00
parent 8a525ec4ae
commit 0706b698f4
4 changed files with 27 additions and 28 deletions

View File

@ -6,7 +6,6 @@ support-files =
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]

View File

@ -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>

View File

@ -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);
}

View File

@ -6,6 +6,7 @@ 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