tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

test_nosniff.html (2713B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <head>
      4  <title>Bug 471020 - Add X-Content-Type-Options: nosniff support to Firefox</title>
      5  <!-- Including SimpleTest.js so we can use waitForExplicitFinish !-->
      6  <script src="/tests/SimpleTest/SimpleTest.js"></script>
      7  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
      8 
      9  <!-- add the two css tests -->
     10  <link rel="stylesheet" id="cssCorrectType">
     11  <link rel="stylesheet" id="cssWrongType">
     12 </head>
     13 <body>
     14 
     15 <!-- add the two script tests -->
     16 <script id="scriptCorrectType"></script>
     17 <script id="scriptWrongType"></script>
     18 
     19 <script class="testbody" type="text/javascript">
     20 /* Description of the test:
     21 * We load 2 css files, 2 script files and 2 image files, where
     22 * the sever either responds with the right mime type or
     23 * the wrong mime type for each test.
     24 */
     25 
     26 SimpleTest.waitForExplicitFinish();
     27 const NUM_TESTS = 4;
     28 
     29 var testCounter = 0;
     30 function checkFinish() {
     31 testCounter++;
     32 if (testCounter === NUM_TESTS) {
     33 	SimpleTest.finish();
     34 }
     35 }
     36 
     37  // 1) Test CSS with correct mime type
     38  var cssCorrectType = document.getElementById("cssCorrectType");
     39  cssCorrectType.onload = function() {
     40    ok(true, "style nosniff correct type should load");
     41    checkFinish();
     42  }
     43  cssCorrectType.onerror = function() {
     44    ok(false, "style nosniff correct type should load");
     45    checkFinish();
     46  }
     47  cssCorrectType.href = "file_nosniff_testserver.sjs?cssCorrectType";
     48 
     49  // 2) Test CSS with wrong mime type
     50  var cssWrongType = document.getElementById("cssWrongType");
     51  cssWrongType.onload = function() {
     52    ok(false, "style nosniff wrong type should not load");
     53    checkFinish();
     54  }
     55  cssWrongType.onerror = function() {
     56    ok(true, "style nosniff wrong type should not load");
     57    checkFinish();
     58  }
     59  cssWrongType.href = "file_nosniff_testserver.sjs?cssWrongType";
     60 
     61  // 3) Test SCRIPT with correct mime type
     62  var scriptCorrectType = document.getElementById("scriptCorrectType");
     63  scriptCorrectType.onload = function() {
     64    ok(true, "script nosniff correct type should load");
     65    checkFinish();
     66  }
     67  scriptCorrectType.onerror = function() {
     68    ok(false, "script nosniff correct type should load");
     69    checkFinish();
     70  }
     71  scriptCorrectType.src = "file_nosniff_testserver.sjs?scriptCorrectType";
     72 
     73  // 4) Test SCRIPT with wrong mime type
     74  var scriptWrongType = document.getElementById("scriptWrongType");
     75  scriptWrongType.onload = function() {
     76    ok(false, "script nosniff wrong type should not load");
     77    checkFinish();
     78  }
     79  scriptWrongType.onerror = function() {
     80    ok(true, "script nosniff wrong type should not load");
     81    checkFinish();
     82  }
     83  scriptWrongType.src = "file_nosniff_testserver.sjs?scriptWrongType";
     84 
     85 
     86 </script>
     87 </body>
     88 </html>