content/base/test/file_mixed_content_main_bug803225.html

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

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

mercurial