Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | <!DOCTYPE HTML> |
michael@0 | 2 | <html> |
michael@0 | 3 | <head> |
michael@0 | 4 | <meta charset="utf-8"> |
michael@0 | 5 | <title>Bug 941404 - Data documents should not set CSP</title> |
michael@0 | 6 | <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> |
michael@0 | 7 | <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> |
michael@0 | 8 | </head> |
michael@0 | 9 | <body> |
michael@0 | 10 | <p id="display"></p> |
michael@0 | 11 | <div id="content" style="display: none"> |
michael@0 | 12 | |
michael@0 | 13 | |
michael@0 | 14 | </div> |
michael@0 | 15 | |
michael@0 | 16 | <iframe style="width:200px;height:200px;" id='cspframe'></iframe> |
michael@0 | 17 | <script class="testbody" type="text/javascript"> |
michael@0 | 18 | |
michael@0 | 19 | |
michael@0 | 20 | var path = "/tests/content/base/test/csp/"; |
michael@0 | 21 | |
michael@0 | 22 | // These are test results: -1 means it hasn't run, |
michael@0 | 23 | // true/false is the pass/fail result. |
michael@0 | 24 | window.tests = { |
michael@0 | 25 | img_good: -1, |
michael@0 | 26 | img2_good: -1, |
michael@0 | 27 | }; |
michael@0 | 28 | |
michael@0 | 29 | |
michael@0 | 30 | //csp related |
michael@0 | 31 | |
michael@0 | 32 | // This is used to watch the blocked data bounce off CSP and allowed data |
michael@0 | 33 | // get sent out to the wire. |
michael@0 | 34 | function examiner() { |
michael@0 | 35 | SpecialPowers.addObserver(this, "csp-on-violate-policy", false); |
michael@0 | 36 | SpecialPowers.addObserver(this, "specialpowers-http-notify-request", false); |
michael@0 | 37 | } |
michael@0 | 38 | |
michael@0 | 39 | examiner.prototype = { |
michael@0 | 40 | observe: function(subject, topic, data) { |
michael@0 | 41 | var testpat = new RegExp("testid=([a-z0-9_]+)"); |
michael@0 | 42 | |
michael@0 | 43 | //_good things better be allowed! |
michael@0 | 44 | //_bad things better be stopped! |
michael@0 | 45 | |
michael@0 | 46 | if (topic === "specialpowers-http-notify-request") { |
michael@0 | 47 | //these things were allowed by CSP |
michael@0 | 48 | var uri = data; |
michael@0 | 49 | if (!testpat.test(uri)) return; |
michael@0 | 50 | var testid = testpat.exec(uri)[1]; |
michael@0 | 51 | |
michael@0 | 52 | window.testResult(testid, |
michael@0 | 53 | /_good/.test(testid), |
michael@0 | 54 | uri + " allowed by csp"); |
michael@0 | 55 | } |
michael@0 | 56 | |
michael@0 | 57 | if(topic === "csp-on-violate-policy") { |
michael@0 | 58 | //these were blocked... record that they were blocked |
michael@0 | 59 | var asciiSpec = SpecialPowers.getPrivilegedProps(SpecialPowers.do_QueryInterface(subject, "nsIURI"), "asciiSpec"); |
michael@0 | 60 | if (!testpat.test(asciiSpec)) return; |
michael@0 | 61 | var testid = testpat.exec(asciiSpec)[1]; |
michael@0 | 62 | window.testResult(testid, |
michael@0 | 63 | /_bad/.test(testid), |
michael@0 | 64 | asciiSpec + " blocked by \"" + data + "\""); |
michael@0 | 65 | } |
michael@0 | 66 | }, |
michael@0 | 67 | |
michael@0 | 68 | // must eventually call this to remove the listener, |
michael@0 | 69 | // or mochitests might get borked. |
michael@0 | 70 | remove: function() { |
michael@0 | 71 | SpecialPowers.removeObserver(this, "csp-on-violate-policy"); |
michael@0 | 72 | SpecialPowers.removeObserver(this, "specialpowers-http-notify-request"); |
michael@0 | 73 | } |
michael@0 | 74 | } |
michael@0 | 75 | |
michael@0 | 76 | window.examiner = new examiner(); |
michael@0 | 77 | |
michael@0 | 78 | window.testResult = function(testname, result, msg) { |
michael@0 | 79 | //test already complete.... forget it... remember the first result. |
michael@0 | 80 | if (window.tests[testname] != -1) |
michael@0 | 81 | return; |
michael@0 | 82 | |
michael@0 | 83 | window.tests[testname] = result; |
michael@0 | 84 | is(result, true, testname + ' test: ' + msg); |
michael@0 | 85 | |
michael@0 | 86 | // if any test is incomplete, keep waiting |
michael@0 | 87 | for (var v in window.tests) |
michael@0 | 88 | if(tests[v] == -1) { |
michael@0 | 89 | console.log(v + " is not complete"); |
michael@0 | 90 | return; |
michael@0 | 91 | } |
michael@0 | 92 | |
michael@0 | 93 | // ... otherwise, finish |
michael@0 | 94 | window.examiner.remove(); |
michael@0 | 95 | SimpleTest.finish(); |
michael@0 | 96 | } |
michael@0 | 97 | |
michael@0 | 98 | SimpleTest.waitForExplicitFinish(); |
michael@0 | 99 | |
michael@0 | 100 | SpecialPowers.pushPrefEnv( |
michael@0 | 101 | {'set':[["security.csp.speccompliant", true]]}, |
michael@0 | 102 | function() { |
michael@0 | 103 | // save this for last so that our listeners are registered. |
michael@0 | 104 | // ... this loads the testbed of good and bad requests. |
michael@0 | 105 | document.getElementById('cspframe').src = 'file_CSP_bug941404.html'; |
michael@0 | 106 | }); |
michael@0 | 107 | |
michael@0 | 108 | </script> |
michael@0 | 109 | </pre> |
michael@0 | 110 | </body> |
michael@0 | 111 | </html> |