test_bug873229.html (2656B)
1 <!DOCTYPE HTML> 2 <html> 3 <!-- 4 https://bugzilla.mozilla.org/show_bug.cgi?id=873229 5 --> 6 <head> 7 <meta charset="utf-8"> 8 <title>Test for Bug 873229</title> 9 <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> 10 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> 11 <script type="application/javascript"> 12 13 /** Test for Bug 873229 */ 14 SimpleTest.waitForExplicitFinish(); 15 addLoadEvent(function() { 16 // We're going to need to be tricky: we want to trigger onerror without 17 // getting an exception thrown in our face. Use event dispatch! 18 var f = $("f").contentWindow; 19 is(typeof(bar), "function", "bar should be a function"); 20 is(typeof(f.bar), "function", "bar should be a function in the subframe"); 21 var string; 22 var url; 23 var line; 24 25 var oldOnerror = window.onerror; 26 27 // Now we have to be very careful to not trigger any errors we don't 28 // expect! 29 var errorCount = 0; 30 31 window.onerror = function(exceptionString, exceptionURL, exceptionLine) { 32 string = exceptionString; 33 url = exceptionURL; 34 line = exceptionLine; 35 ++errorCount; 36 } 37 38 document.documentElement.onclick = function() { 39 bar(); 40 }; 41 string = "FAIL"; 42 url = "FAIL"; 43 line = "FAIL"; 44 document.documentElement.dispatchEvent(new Event("click")); 45 is(string, "Script error.", "Did not sanitize string"); 46 is(url, 47 "http://example.com/tests/dom/tests/mochitest/bugs/file_bug873229.js", 48 "Should not sanitize URL"); 49 is(line, 0, "Did not sanitize line"); 50 51 document.documentElement.onclick = function() { 52 f.bar(); 53 }; 54 string = "FAIL"; 55 url = "FAIL"; 56 line = "FAIL"; 57 document.documentElement.dispatchEvent(new Event("click")); 58 is(string, "Script error.", "Did not sanitize string in iframe"); 59 is(url, 60 "http://example.com/tests/dom/tests/mochitest/bugs/file_bug873229.js", 61 "Should not sanitize URL in iframe"); 62 is(line, 0, "Did not sanitize line in iframe"); 63 64 document.documentElement.onclick = null; 65 66 is(errorCount, 2, "Should have had two exceptions"); 67 window.onerror = oldOnerror; 68 SimpleTest.finish(); 69 }); 70 71 </script> 72 <script src="http://example.com/tests/dom/tests/mochitest/bugs/file_bug873229.js"></script> 73 </head> 74 <body> 75 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=873229">Mozilla Bug 873229</a> 76 <p id="display"></p> 77 <div id="content" style="display: none"> 78 <iframe id="f" srcdoc="<script src='http://example.com/tests/dom/tests/mochitest/bugs/file_bug873229.js'></script>"></iframe> 79 </div> 80 <pre id="test"> 81 </pre> 82 </body> 83 </html>