toolkit/content/tests/unit/test_contentAreaUtils.js

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

michael@0 1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
michael@0 2 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6 const Ci = Components.interfaces;
michael@0 7 const Cc = Components.classes;
michael@0 8 const Cr = Components.results;
michael@0 9
michael@0 10 function loadUtilsScript() {
michael@0 11 var loader = Cc["@mozilla.org/moz/jssubscript-loader;1"].
michael@0 12 getService(Ci.mozIJSSubScriptLoader);
michael@0 13 loader.loadSubScript("chrome://global/content/contentAreaUtils.js");
michael@0 14 }
michael@0 15
michael@0 16 function test_urlSecurityCheck() {
michael@0 17 var nullPrincipal = Cc["@mozilla.org/nullprincipal;1"].
michael@0 18 createInstance(Ci.nsIPrincipal);
michael@0 19
michael@0 20 const HTTP_URI = "http://www.mozilla.org/";
michael@0 21 const CHROME_URI = "chrome://browser/content/browser.xul";
michael@0 22 const DISALLOW_INHERIT_PRINCIPAL =
michael@0 23 Ci.nsIScriptSecurityManager.DISALLOW_INHERIT_PRINCIPAL;
michael@0 24
michael@0 25 try {
michael@0 26 urlSecurityCheck(makeURI(HTTP_URI), nullPrincipal,
michael@0 27 DISALLOW_INHERIT_PRINCIPAL);
michael@0 28 }
michael@0 29 catch(ex) {
michael@0 30 do_throw("urlSecurityCheck should not throw when linking to a http uri with a null principal");
michael@0 31 }
michael@0 32
michael@0 33 // urlSecurityCheck also supports passing the url as a string
michael@0 34 try {
michael@0 35 urlSecurityCheck(HTTP_URI, nullPrincipal,
michael@0 36 DISALLOW_INHERIT_PRINCIPAL);
michael@0 37 }
michael@0 38 catch(ex) {
michael@0 39 do_throw("urlSecurityCheck failed to handle the http URI as a string (uri spec)");
michael@0 40 }
michael@0 41
michael@0 42 let shouldThrow = true;
michael@0 43 try {
michael@0 44 urlSecurityCheck(CHROME_URI, nullPrincipal,
michael@0 45 DISALLOW_INHERIT_PRINCIPAL);
michael@0 46 }
michael@0 47 catch(ex) {
michael@0 48 shouldThrow = false;
michael@0 49 }
michael@0 50 if (shouldThrow)
michael@0 51 do_throw("urlSecurityCheck should throw when linking to a chrome uri with a null principal");
michael@0 52 }
michael@0 53
michael@0 54 function test_stringBundle() {
michael@0 55 // This test verifies that the elements that can be used as file picker title
michael@0 56 // keys in the save* functions are actually present in the string bundle.
michael@0 57 // These keys are part of the contentAreaUtils.js public API.
michael@0 58 var validFilePickerTitleKeys = [
michael@0 59 "SaveImageTitle",
michael@0 60 "SaveVideoTitle",
michael@0 61 "SaveAudioTitle",
michael@0 62 "SaveLinkTitle",
michael@0 63 ];
michael@0 64
michael@0 65 for (let [, filePickerTitleKey] in Iterator(validFilePickerTitleKeys)) {
michael@0 66 // Just check that the string exists
michael@0 67 try {
michael@0 68 ContentAreaUtils.stringBundle.GetStringFromName(filePickerTitleKey);
michael@0 69 } catch (e) {
michael@0 70 do_throw("Error accessing file picker title key: " + filePickerTitleKey);
michael@0 71 }
michael@0 72 }
michael@0 73 }
michael@0 74
michael@0 75 function run_test()
michael@0 76 {
michael@0 77 loadUtilsScript();
michael@0 78 test_urlSecurityCheck();
michael@0 79 test_stringBundle();
michael@0 80 }

mercurial