1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/devtools/webconsole/test/test_page_errors.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,97 @@ 1.4 +<!DOCTYPE HTML> 1.5 +<html lang="en"> 1.6 +<head> 1.7 + <meta charset="utf8"> 1.8 + <title>Test for page errors</title> 1.9 + <script type="text/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script> 1.10 + <script type="text/javascript;version=1.8" src="common.js"></script> 1.11 + <!-- Any copyright is dedicated to the Public Domain. 1.12 + - http://creativecommons.org/publicdomain/zero/1.0/ --> 1.13 +</head> 1.14 +<body> 1.15 +<p>Test for page errors</p> 1.16 + 1.17 +<script class="testbody" type="text/javascript;version=1.8"> 1.18 +SimpleTest.waitForExplicitFinish(); 1.19 + 1.20 +let expectedPageErrors = []; 1.21 + 1.22 +function doPageErrors() 1.23 +{ 1.24 + expectedPageErrors = [ 1.25 + { 1.26 + errorMessage: /fooColor/, 1.27 + sourceName: /test_page_errors/, 1.28 + category: "CSS Parser", 1.29 + timeStamp: /^\d+$/, 1.30 + error: false, 1.31 + warning: true, 1.32 + exception: false, 1.33 + strict: false, 1.34 + }, 1.35 + { 1.36 + errorMessage: /doTheImpossible/, 1.37 + sourceName: /test_page_errors/, 1.38 + category: "chrome javascript", 1.39 + timeStamp: /^\d+$/, 1.40 + error: false, 1.41 + warning: false, 1.42 + exception: true, 1.43 + strict: false, 1.44 + }, 1.45 + ]; 1.46 + 1.47 + let container = document.createElement("script"); 1.48 + document.body.appendChild(container); 1.49 + container.textContent = "document.body.style.color = 'fooColor';"; 1.50 + document.body.removeChild(container); 1.51 + 1.52 + SimpleTest.expectUncaughtException(); 1.53 + 1.54 + container = document.createElement("script"); 1.55 + document.body.appendChild(container); 1.56 + container.textContent = "document.doTheImpossible();"; 1.57 + document.body.removeChild(container); 1.58 +} 1.59 + 1.60 +function startTest() 1.61 +{ 1.62 + removeEventListener("load", startTest); 1.63 + 1.64 + attachConsole(["PageError"], onAttach); 1.65 +} 1.66 + 1.67 +function onAttach(aState, aResponse) 1.68 +{ 1.69 + onPageError = onPageError.bind(null, aState); 1.70 + aState.dbgClient.addListener("pageError", onPageError); 1.71 + doPageErrors(); 1.72 +} 1.73 + 1.74 +let pageErrors = []; 1.75 + 1.76 +function onPageError(aState, aType, aPacket) 1.77 +{ 1.78 + is(aPacket.from, aState.actor, "page error actor"); 1.79 + 1.80 + pageErrors.push(aPacket.pageError); 1.81 + if (pageErrors.length != expectedPageErrors.length) { 1.82 + return; 1.83 + } 1.84 + 1.85 + aState.dbgClient.removeListener("pageError", onPageError); 1.86 + 1.87 + expectedPageErrors.forEach(function(aMessage, aIndex) { 1.88 + info("checking received page error #" + aIndex); 1.89 + checkObject(pageErrors[aIndex], expectedPageErrors[aIndex]); 1.90 + }); 1.91 + 1.92 + closeDebugger(aState, function() { 1.93 + SimpleTest.finish(); 1.94 + }); 1.95 +} 1.96 + 1.97 +addEventListener("load", startTest); 1.98 +</script> 1.99 +</body> 1.100 +</html>