1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/content/base/test/file_mixed_content_main_bug803225.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,164 @@ 1.4 +<!DOCTYPE HTML> 1.5 +<html> 1.6 +<!-- 1.7 +Tests for Mixed Content Blocker - Allowed Protocols 1.8 +https://bugzilla.mozilla.org/show_bug.cgi?id=803225 1.9 +--> 1.10 +<head> 1.11 + <meta charset="utf-8"> 1.12 + <title>Tests for Bug 62178</title> 1.13 + <script type="application/javascript" src="/tests/SimpleTest/EventUtils.js"></script> 1.14 +</head> 1.15 +<body> 1.16 +<div id="testContent"></div> 1.17 + 1.18 +<!-- Test additional schemes the Mixed Content Blocker should not block 1.19 + "about" protocol URIs that are URI_SAFE_FOR_UNTRUSTED_CONTENT (moz-safe-about; see nsAboutProtocolHandler::NewURI 1.20 + "data", 1.21 + "javascript", 1.22 + "mailto", 1.23 + "resource", 1.24 + "moz-icon", 1.25 + "wss" 1.26 +--> 1.27 + 1.28 +<script> 1.29 + 1.30 + //For tests that require setTimeout, set the timeout interval 1.31 + var TIMEOUT_INTERVAL = 100; 1.32 + 1.33 + var testContent = document.getElementById("testContent"); 1.34 + 1.35 + // Test 1 & 2: about and javascript protcols within an iframe 1.36 + var data = Array(2,2); 1.37 + var protocols = [ 1.38 + ["about", ""], //When no source is specified, the frame gets a source of about:blank 1.39 + ["javascript", "javascript:document.open();document.write='<h1>SUCCESS</h1>';document.close();"], 1.40 + ]; 1.41 + for(var i=0; i < protocols.length; i++) 1.42 + { 1.43 + var generic_frame = document.createElement("iframe"); 1.44 + generic_frame.src = protocols[i][1]; 1.45 + generic_frame.name="generic_protocol"; 1.46 + 1.47 + generic_frame.onload = function(i) { 1.48 + data = {"test": protocols[i][0], "msg": "resource with " + protocols[i][0] + " protocol loaded"}; 1.49 + parent.postMessage(data, "http://mochi.test:8888"); 1.50 + }.bind(generic_frame, i) 1.51 + 1.52 + generic_frame.onerror = function(i) { 1.53 + data = {"test": protocols[i][0], "msg": "resource with " + protocols[i][0] + " protocol did not load"}; 1.54 + parent.postMessage(data, "http://mochi.test:8888"); 1.55 + }.bind(generic_frame, i); 1.56 + 1.57 + testContent.appendChild(generic_frame, i); 1.58 + } 1.59 + 1.60 + // Test 3: for resource within a script tag 1.61 + // Note: the script we load throws an exception, but the script element's 1.62 + // onload listener is called after we successfully fetch the script, 1.63 + // independently of whether it throws an exception. 1.64 + var resource_script=document.createElement("script"); 1.65 + resource_script.src = "resource://gre/modules/XPCOMUtils.jsm"; 1.66 + resource_script.name = "resource_protocol"; 1.67 + resource_script.onload = function() { 1.68 + parent.postMessage({"test": "resource", "msg": "resource with resource protocol loaded"}, "http://mochi.test:8888"); 1.69 + } 1.70 + resource_script.onerror = function() { 1.71 + parent.postMessage({"test": "resource", "msg": "resource with resource protocol did not load"}, "http://mochi.test:8888"); 1.72 + } 1.73 + 1.74 + testContent.appendChild(resource_script); 1.75 + 1.76 + // Test 4: moz-icon within an img tag 1.77 + var image=document.createElement("img"); 1.78 + image.src = "moz-icon://dummy.exe?size=16"; 1.79 + image.onload = function() { 1.80 + parent.postMessage({"test": "mozicon", "msg": "resource with mozicon protocol loaded"}, "http://mochi.test:8888"); 1.81 + } 1.82 + image.onerror = function() { 1.83 + parent.postMessage({"test": "mozicon", "msg": "resource with mozicon protocol did not load"}, "http://mochi.test:8888"); 1.84 + } 1.85 + // We don't need to append the image to the document. Doing so causes the image test to run twice. 1.86 + 1.87 + // Test 5: about unsafe protocol within an iframe 1.88 + var unsafe_about_frame = document.createElement("iframe"); 1.89 + unsafe_about_frame.src = "about:config"; 1.90 + unsafe_about_frame.name = "unsafe_about_protocol"; 1.91 + unsafe_about_frame.onload = function() { 1.92 + parent.postMessage({"test": "unsafe_about", "msg": "resource with unsafe about protocol loaded"}, "http://mochi.test:8888"); 1.93 + } 1.94 + unsafe_about_frame.onerror = function() { 1.95 + parent.postMessage({"test": "unsafe_about", "msg": "resource with unsafe about protocol did not load"}, "http://mochi.test:8888"); 1.96 + } 1.97 + testContent.appendChild(unsafe_about_frame); 1.98 + 1.99 + // Test 6: data protocol within a script tag 1.100 + var x = 2; 1.101 + var newscript = document.createElement("script"); 1.102 + newscript.src= "data:text/javascript,var x = 4;"; 1.103 + newscript.onload = function() { 1.104 + parent.postMessage({"test": "data_protocol", "msg": "resource with data protocol loaded"}, "http://mochi.test:8888"); 1.105 + } 1.106 + newscript.onerror = function() { 1.107 + parent.postMessage({"test": "data_protocol", "msg": "resource with data protocol did not load"}, "http://mochi.test:8888"); 1.108 + } 1.109 + testContent.appendChild(newscript); 1.110 + 1.111 + // Test 7: mailto protocol 1.112 + var ioService = SpecialPowers.Cc["@mozilla.org/network/io-service;1"]. 1.113 + getService(SpecialPowers.Ci.nsIIOService); 1.114 + 1.115 + var webHandler = SpecialPowers.Cc["@mozilla.org/uriloader/web-handler-app;1"]. 1.116 + createInstance(SpecialPowers.Ci.nsIWebHandlerApp); 1.117 + webHandler.name = "Web Handler"; 1.118 + webHandler.uriTemplate = "http://example.com/tests/content/base/test/bug803225_test_mailto.html?s=%"; 1.119 + 1.120 + var uri = ioService.newURI("mailto:foo@bar.com", null, null); 1.121 + webHandler.launchWithURI(uri); 1.122 + 1.123 + var mailto = false; 1.124 + 1.125 + // listen for a messages from a new window 1.126 + var os = SpecialPowers.Cc["@mozilla.org/observer-service;1"]. 1.127 + getService(SpecialPowers.Components.interfaces.nsIObserverService); 1.128 + var observer = { 1.129 + observe: function(subject, topic, data) { 1.130 + if(topic == "content-document-global-created" && data =="http://example.com") { 1.131 + parent.postMessage({"test": "mailto", "msg": "resource with mailto protocol loaded"}, "http://mochi.test:8888"); 1.132 + os.removeObserver(observer, "content-document-global-created"); 1.133 + mailto = true; 1.134 + } 1.135 + } 1.136 + } 1.137 + os.addObserver(observer, "content-document-global-created", false); 1.138 + 1.139 + function mailtoProtocolStatus() { 1.140 + if(!mailto) { 1.141 + //There is no onerror event associated with the WebHandler, and hence we need a setTimeout to check the status 1.142 + setTimeout(mailtoProtocolStatus, TIMEOUT_INTERVAL); 1.143 + } 1.144 + } 1.145 + 1.146 + mailtoProtocolStatus(); 1.147 + 1.148 + // Test 8: wss protocol 1.149 + var wss; 1.150 + wss = new WebSocket("wss://example.com/tests/content/base/test/file_mixed_content_main_bug803225_websocket"); 1.151 + 1.152 + var status_wss = "started"; 1.153 + wss.onopen = function(e) { 1.154 + status_wss = "opened"; 1.155 + wss.close(); 1.156 + } 1.157 + wss.onclose = function(e) { 1.158 + if(status_wss == "opened") { 1.159 + parent.postMessage({"test": "wss", "msg": "resource with wss protocol loaded"}, "http://mochi.test:8888"); 1.160 + } else { 1.161 + parent.postMessage({"test": "wss", "msg": "resource with wss protocol did not load"}, "http://mochi.test:8888"); 1.162 + } 1.163 + } 1.164 + 1.165 +</script> 1.166 +</body> 1.167 +</html>