1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/caps/tests/mochitest/test_bug995943.xul Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,111 @@ 1.4 +<?xml version="1.0"?> 1.5 +<?xml-stylesheet type="text/css" href="chrome://global/skin"?> 1.6 +<?xml-stylesheet type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"?> 1.7 +<!-- 1.8 +https://bugzilla.mozilla.org/show_bug.cgi?id=995943 1.9 +--> 1.10 +<window title="Mozilla Bug 995943" 1.11 + xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> 1.12 + <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/> 1.13 + 1.14 + <!-- test results are displayed in the html:body --> 1.15 + <body xmlns="http://www.w3.org/1999/xhtml"> 1.16 + <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=995943" 1.17 + target="_blank">Mozilla Bug 995943</a> 1.18 + </body> 1.19 + 1.20 + <!-- test code goes here --> 1.21 + <script type="application/javascript"> 1.22 + <![CDATA[ 1.23 + const Cu = Components.utils; 1.24 + const Cc = Components.classes; 1.25 + const Ci = Components.interfaces; 1.26 + Cu.import("resource://gre/modules/Services.jsm"); 1.27 + function debug(msg) { info(msg); } 1.28 + 1.29 + /** Test for CAPS file:// URI prefs. **/ 1.30 + SimpleTest.waitForExplicitFinish(); 1.31 + SimpleTest.requestCompleteLog(); 1.32 + if (Services.appinfo.OS == "Darwin") // See bug 1067022 1.33 + SimpleTest.expectAssertions(0, 1); 1.34 + 1.35 + var rootdir = Services.appinfo.OS == "WINNT" ? "file:///C:" : "file:///"; 1.36 + 1.37 + function checkLoadFileURI(domain, shouldLoad) { 1.38 + debug("Invoking checkLoadFileURI with domain: " + domain + ", shouldLoad: " + shouldLoad); 1.39 + return new Promise(function(resolve, reject) { 1.40 + $('ifr').addEventListener('load', function l1() { 1.41 + debug("Invoked l1 for " + domain); 1.42 + $('ifr').removeEventListener('load', l1); 1.43 + function l2() { 1.44 + debug("Invoked l2 for " + domain); 1.45 + $('ifr').removeEventListener('load', l2); 1.46 + ok(shouldLoad, "Successfully loaded file:// URI for domain: " + domain); 1.47 + resolve(); 1.48 + } 1.49 + $('ifr').addEventListener('load', l2); 1.50 + try { 1.51 + window[0].wrappedJSObject.location = rootdir; 1.52 + debug("Successfully navigated for " + domain); 1.53 + } catch (e) { 1.54 + ok(!shouldLoad && /denied|insecure/.test(e), 1.55 + "Prevented loading of file:// URI for domain: " + domain + " - " + e); 1.56 + $('ifr').removeEventListener('load', l2); 1.57 + resolve(); 1.58 + } 1.59 + }); 1.60 + let targetURI = domain + '/tests/js/xpconnect/tests/mochitest/file_empty.html'; 1.61 + debug("Navigating iframe to " + targetURI); 1.62 + $('ifr').contentWindow.location = targetURI; 1.63 + }); 1.64 + } 1.65 + 1.66 + function pushPrefs(prefs) { 1.67 + return new Promise(function(resolve) { SpecialPowers.pushPrefEnv({ set: prefs }, resolve); }); 1.68 + } 1.69 + 1.70 + function popPrefs() { 1.71 + return new Promise(function(resolve) { SpecialPowers.popPrefEnv(resolve); }); 1.72 + } 1.73 + 1.74 + var gGoCount = 0; 1.75 + function go() { 1.76 + debug("Invoking go for window with id: " + window.getInterface(Ci.nsIDOMWindowUtils).currentInnerWindowID); 1.77 + is(++gGoCount, 1, "Should only call go once!"); 1.78 + checkLoadFileURI('http://example.com', false).then( 1.79 + pushPrefs.bind(null, [['capability.policy.policynames', ' somepolicy '], 1.80 + ['capability.policy.somepolicy.checkloaduri.enabled', 'AlLAcCeSs'], 1.81 + ['capability.policy.somepolicy.sites', 'http://example.com']])) 1.82 + .then(checkLoadFileURI.bind(null, 'http://example.com', true)) 1.83 + .then(popPrefs) 1.84 + .then(checkLoadFileURI.bind(null, 'http://example.com', false)) 1.85 + .then( 1.86 + pushPrefs.bind(null, [['capability.policy.policynames', ',somepolicy, someotherpolicy, '], 1.87 + ['capability.policy.somepolicy.checkloaduri.enabled', 'allaccess'], 1.88 + ['capability.policy.someotherpolicy.checkloaduri.enabled', 'nope'], 1.89 + ['capability.policy.somepolicy.sites', ' http://example.org test1.example.com https://test2.example.com '], 1.90 + ['capability.policy.someotherpolicy.sites', 'http://example.net ']])) 1.91 + .then(checkLoadFileURI.bind(null, 'http://example.org', true)) 1.92 + .then(checkLoadFileURI.bind(null, 'http://test2.example.com', false)) 1.93 + .then(checkLoadFileURI.bind(null, 'https://test2.example.com', true)) 1.94 + .then(checkLoadFileURI.bind(null, 'http://sub1.test2.example.com', false)) 1.95 + .then(checkLoadFileURI.bind(null, 'https://sub1.test2.example.com', true)) 1.96 + .then(checkLoadFileURI.bind(null, 'http://example.net', false)) 1.97 + .then(checkLoadFileURI.bind(null, 'http://test1.example.com', true)) 1.98 + .then(checkLoadFileURI.bind(null, 'https://test1.example.com', true)) 1.99 + .then(checkLoadFileURI.bind(null, 'http://sub1.test1.example.com', true)) 1.100 + .then(checkLoadFileURI.bind(null, 'https://sub1.test1.example.com', true)) 1.101 + .then(pushPrefs.bind(null, [['capability.policy.someotherpolicy.checkloaduri.enabled', 'allAccess']])) 1.102 + .then(checkLoadFileURI.bind(null, 'http://example.net', true)) 1.103 + .then(popPrefs) 1.104 + .then(popPrefs) 1.105 + .then(checkLoadFileURI.bind(null, 'http://example.net', false)) 1.106 + .then(SimpleTest.finish.bind(SimpleTest)); 1.107 + 1.108 + } 1.109 + addLoadEvent(go); 1.110 + 1.111 + ]]> 1.112 + </script> 1.113 + <iframe id="ifr" type="content" /> 1.114 +</window>