Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | <!DOCTYPE HTML> |
michael@0 | 2 | <html> |
michael@0 | 3 | <!-- |
michael@0 | 4 | Tests for Mixed Content Blocker - Allowed Protocols |
michael@0 | 5 | https://bugzilla.mozilla.org/show_bug.cgi?id=803225 |
michael@0 | 6 | --> |
michael@0 | 7 | <head> |
michael@0 | 8 | <meta charset="utf-8"> |
michael@0 | 9 | <title>Tests for Bug 62178</title> |
michael@0 | 10 | <script type="application/javascript" src="/tests/SimpleTest/EventUtils.js"></script> |
michael@0 | 11 | </head> |
michael@0 | 12 | <body> |
michael@0 | 13 | <div id="testContent"></div> |
michael@0 | 14 | |
michael@0 | 15 | <!-- Test additional schemes the Mixed Content Blocker should not block |
michael@0 | 16 | "about" protocol URIs that are URI_SAFE_FOR_UNTRUSTED_CONTENT (moz-safe-about; see nsAboutProtocolHandler::NewURI |
michael@0 | 17 | "data", |
michael@0 | 18 | "javascript", |
michael@0 | 19 | "mailto", |
michael@0 | 20 | "resource", |
michael@0 | 21 | "moz-icon", |
michael@0 | 22 | "wss" |
michael@0 | 23 | --> |
michael@0 | 24 | |
michael@0 | 25 | <script> |
michael@0 | 26 | |
michael@0 | 27 | //For tests that require setTimeout, set the timeout interval |
michael@0 | 28 | var TIMEOUT_INTERVAL = 100; |
michael@0 | 29 | |
michael@0 | 30 | var testContent = document.getElementById("testContent"); |
michael@0 | 31 | |
michael@0 | 32 | // Test 1 & 2: about and javascript protcols within an iframe |
michael@0 | 33 | var data = Array(2,2); |
michael@0 | 34 | var protocols = [ |
michael@0 | 35 | ["about", ""], //When no source is specified, the frame gets a source of about:blank |
michael@0 | 36 | ["javascript", "javascript:document.open();document.write='<h1>SUCCESS</h1>';document.close();"], |
michael@0 | 37 | ]; |
michael@0 | 38 | for(var i=0; i < protocols.length; i++) |
michael@0 | 39 | { |
michael@0 | 40 | var generic_frame = document.createElement("iframe"); |
michael@0 | 41 | generic_frame.src = protocols[i][1]; |
michael@0 | 42 | generic_frame.name="generic_protocol"; |
michael@0 | 43 | |
michael@0 | 44 | generic_frame.onload = function(i) { |
michael@0 | 45 | data = {"test": protocols[i][0], "msg": "resource with " + protocols[i][0] + " protocol loaded"}; |
michael@0 | 46 | parent.postMessage(data, "http://mochi.test:8888"); |
michael@0 | 47 | }.bind(generic_frame, i) |
michael@0 | 48 | |
michael@0 | 49 | generic_frame.onerror = function(i) { |
michael@0 | 50 | data = {"test": protocols[i][0], "msg": "resource with " + protocols[i][0] + " protocol did not load"}; |
michael@0 | 51 | parent.postMessage(data, "http://mochi.test:8888"); |
michael@0 | 52 | }.bind(generic_frame, i); |
michael@0 | 53 | |
michael@0 | 54 | testContent.appendChild(generic_frame, i); |
michael@0 | 55 | } |
michael@0 | 56 | |
michael@0 | 57 | // Test 3: for resource within a script tag |
michael@0 | 58 | // Note: the script we load throws an exception, but the script element's |
michael@0 | 59 | // onload listener is called after we successfully fetch the script, |
michael@0 | 60 | // independently of whether it throws an exception. |
michael@0 | 61 | var resource_script=document.createElement("script"); |
michael@0 | 62 | resource_script.src = "resource://gre/modules/XPCOMUtils.jsm"; |
michael@0 | 63 | resource_script.name = "resource_protocol"; |
michael@0 | 64 | resource_script.onload = function() { |
michael@0 | 65 | parent.postMessage({"test": "resource", "msg": "resource with resource protocol loaded"}, "http://mochi.test:8888"); |
michael@0 | 66 | } |
michael@0 | 67 | resource_script.onerror = function() { |
michael@0 | 68 | parent.postMessage({"test": "resource", "msg": "resource with resource protocol did not load"}, "http://mochi.test:8888"); |
michael@0 | 69 | } |
michael@0 | 70 | |
michael@0 | 71 | testContent.appendChild(resource_script); |
michael@0 | 72 | |
michael@0 | 73 | // Test 4: moz-icon within an img tag |
michael@0 | 74 | var image=document.createElement("img"); |
michael@0 | 75 | image.src = "moz-icon://dummy.exe?size=16"; |
michael@0 | 76 | image.onload = function() { |
michael@0 | 77 | parent.postMessage({"test": "mozicon", "msg": "resource with mozicon protocol loaded"}, "http://mochi.test:8888"); |
michael@0 | 78 | } |
michael@0 | 79 | image.onerror = function() { |
michael@0 | 80 | parent.postMessage({"test": "mozicon", "msg": "resource with mozicon protocol did not load"}, "http://mochi.test:8888"); |
michael@0 | 81 | } |
michael@0 | 82 | // We don't need to append the image to the document. Doing so causes the image test to run twice. |
michael@0 | 83 | |
michael@0 | 84 | // Test 5: about unsafe protocol within an iframe |
michael@0 | 85 | var unsafe_about_frame = document.createElement("iframe"); |
michael@0 | 86 | unsafe_about_frame.src = "about:config"; |
michael@0 | 87 | unsafe_about_frame.name = "unsafe_about_protocol"; |
michael@0 | 88 | unsafe_about_frame.onload = function() { |
michael@0 | 89 | parent.postMessage({"test": "unsafe_about", "msg": "resource with unsafe about protocol loaded"}, "http://mochi.test:8888"); |
michael@0 | 90 | } |
michael@0 | 91 | unsafe_about_frame.onerror = function() { |
michael@0 | 92 | parent.postMessage({"test": "unsafe_about", "msg": "resource with unsafe about protocol did not load"}, "http://mochi.test:8888"); |
michael@0 | 93 | } |
michael@0 | 94 | testContent.appendChild(unsafe_about_frame); |
michael@0 | 95 | |
michael@0 | 96 | // Test 6: data protocol within a script tag |
michael@0 | 97 | var x = 2; |
michael@0 | 98 | var newscript = document.createElement("script"); |
michael@0 | 99 | newscript.src= "data:text/javascript,var x = 4;"; |
michael@0 | 100 | newscript.onload = function() { |
michael@0 | 101 | parent.postMessage({"test": "data_protocol", "msg": "resource with data protocol loaded"}, "http://mochi.test:8888"); |
michael@0 | 102 | } |
michael@0 | 103 | newscript.onerror = function() { |
michael@0 | 104 | parent.postMessage({"test": "data_protocol", "msg": "resource with data protocol did not load"}, "http://mochi.test:8888"); |
michael@0 | 105 | } |
michael@0 | 106 | testContent.appendChild(newscript); |
michael@0 | 107 | |
michael@0 | 108 | // Test 7: mailto protocol |
michael@0 | 109 | var ioService = SpecialPowers.Cc["@mozilla.org/network/io-service;1"]. |
michael@0 | 110 | getService(SpecialPowers.Ci.nsIIOService); |
michael@0 | 111 | |
michael@0 | 112 | var webHandler = SpecialPowers.Cc["@mozilla.org/uriloader/web-handler-app;1"]. |
michael@0 | 113 | createInstance(SpecialPowers.Ci.nsIWebHandlerApp); |
michael@0 | 114 | webHandler.name = "Web Handler"; |
michael@0 | 115 | webHandler.uriTemplate = "http://example.com/tests/content/base/test/bug803225_test_mailto.html?s=%"; |
michael@0 | 116 | |
michael@0 | 117 | var uri = ioService.newURI("mailto:foo@bar.com", null, null); |
michael@0 | 118 | webHandler.launchWithURI(uri); |
michael@0 | 119 | |
michael@0 | 120 | var mailto = false; |
michael@0 | 121 | |
michael@0 | 122 | // listen for a messages from a new window |
michael@0 | 123 | var os = SpecialPowers.Cc["@mozilla.org/observer-service;1"]. |
michael@0 | 124 | getService(SpecialPowers.Components.interfaces.nsIObserverService); |
michael@0 | 125 | var observer = { |
michael@0 | 126 | observe: function(subject, topic, data) { |
michael@0 | 127 | if(topic == "content-document-global-created" && data =="http://example.com") { |
michael@0 | 128 | parent.postMessage({"test": "mailto", "msg": "resource with mailto protocol loaded"}, "http://mochi.test:8888"); |
michael@0 | 129 | os.removeObserver(observer, "content-document-global-created"); |
michael@0 | 130 | mailto = true; |
michael@0 | 131 | } |
michael@0 | 132 | } |
michael@0 | 133 | } |
michael@0 | 134 | os.addObserver(observer, "content-document-global-created", false); |
michael@0 | 135 | |
michael@0 | 136 | function mailtoProtocolStatus() { |
michael@0 | 137 | if(!mailto) { |
michael@0 | 138 | //There is no onerror event associated with the WebHandler, and hence we need a setTimeout to check the status |
michael@0 | 139 | setTimeout(mailtoProtocolStatus, TIMEOUT_INTERVAL); |
michael@0 | 140 | } |
michael@0 | 141 | } |
michael@0 | 142 | |
michael@0 | 143 | mailtoProtocolStatus(); |
michael@0 | 144 | |
michael@0 | 145 | // Test 8: wss protocol |
michael@0 | 146 | var wss; |
michael@0 | 147 | wss = new WebSocket("wss://example.com/tests/content/base/test/file_mixed_content_main_bug803225_websocket"); |
michael@0 | 148 | |
michael@0 | 149 | var status_wss = "started"; |
michael@0 | 150 | wss.onopen = function(e) { |
michael@0 | 151 | status_wss = "opened"; |
michael@0 | 152 | wss.close(); |
michael@0 | 153 | } |
michael@0 | 154 | wss.onclose = function(e) { |
michael@0 | 155 | if(status_wss == "opened") { |
michael@0 | 156 | parent.postMessage({"test": "wss", "msg": "resource with wss protocol loaded"}, "http://mochi.test:8888"); |
michael@0 | 157 | } else { |
michael@0 | 158 | parent.postMessage({"test": "wss", "msg": "resource with wss protocol did not load"}, "http://mochi.test:8888"); |
michael@0 | 159 | } |
michael@0 | 160 | } |
michael@0 | 161 | |
michael@0 | 162 | </script> |
michael@0 | 163 | </body> |
michael@0 | 164 | </html> |