michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: const Ci = Components.interfaces; michael@0: const Cc = Components.classes; michael@0: const Cr = Components.results; michael@0: michael@0: function loadUtilsScript() { michael@0: var loader = Cc["@mozilla.org/moz/jssubscript-loader;1"]. michael@0: getService(Ci.mozIJSSubScriptLoader); michael@0: loader.loadSubScript("chrome://global/content/contentAreaUtils.js"); michael@0: } michael@0: michael@0: function test_urlSecurityCheck() { michael@0: var nullPrincipal = Cc["@mozilla.org/nullprincipal;1"]. michael@0: createInstance(Ci.nsIPrincipal); michael@0: michael@0: const HTTP_URI = "http://www.mozilla.org/"; michael@0: const CHROME_URI = "chrome://browser/content/browser.xul"; michael@0: const DISALLOW_INHERIT_PRINCIPAL = michael@0: Ci.nsIScriptSecurityManager.DISALLOW_INHERIT_PRINCIPAL; michael@0: michael@0: try { michael@0: urlSecurityCheck(makeURI(HTTP_URI), nullPrincipal, michael@0: DISALLOW_INHERIT_PRINCIPAL); michael@0: } michael@0: catch(ex) { michael@0: do_throw("urlSecurityCheck should not throw when linking to a http uri with a null principal"); michael@0: } michael@0: michael@0: // urlSecurityCheck also supports passing the url as a string michael@0: try { michael@0: urlSecurityCheck(HTTP_URI, nullPrincipal, michael@0: DISALLOW_INHERIT_PRINCIPAL); michael@0: } michael@0: catch(ex) { michael@0: do_throw("urlSecurityCheck failed to handle the http URI as a string (uri spec)"); michael@0: } michael@0: michael@0: let shouldThrow = true; michael@0: try { michael@0: urlSecurityCheck(CHROME_URI, nullPrincipal, michael@0: DISALLOW_INHERIT_PRINCIPAL); michael@0: } michael@0: catch(ex) { michael@0: shouldThrow = false; michael@0: } michael@0: if (shouldThrow) michael@0: do_throw("urlSecurityCheck should throw when linking to a chrome uri with a null principal"); michael@0: } michael@0: michael@0: function test_stringBundle() { michael@0: // This test verifies that the elements that can be used as file picker title michael@0: // keys in the save* functions are actually present in the string bundle. michael@0: // These keys are part of the contentAreaUtils.js public API. michael@0: var validFilePickerTitleKeys = [ michael@0: "SaveImageTitle", michael@0: "SaveVideoTitle", michael@0: "SaveAudioTitle", michael@0: "SaveLinkTitle", michael@0: ]; michael@0: michael@0: for (let [, filePickerTitleKey] in Iterator(validFilePickerTitleKeys)) { michael@0: // Just check that the string exists michael@0: try { michael@0: ContentAreaUtils.stringBundle.GetStringFromName(filePickerTitleKey); michael@0: } catch (e) { michael@0: do_throw("Error accessing file picker title key: " + filePickerTitleKey); michael@0: } michael@0: } michael@0: } michael@0: michael@0: function run_test() michael@0: { michael@0: loadUtilsScript(); michael@0: test_urlSecurityCheck(); michael@0: test_stringBundle(); michael@0: }