From 52d6a08986d0aaafbc3d263962fbeb3ca690cf35 Mon Sep 17 00:00:00 2001 From: "ncbray@chromium.org" Date: Thu, 6 Dec 2012 22:47:42 +0000 Subject: PPAPI: make browser tests to fail fast if a NaCl module does not load. BUG= 164493 Review URL: https://chromiumcodereview.appspot.com/11447019 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@171616 0039d316-1c4b-4281-b951-d872f2087c98 --- ppapi/tests/test_case.html | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'ppapi') diff --git a/ppapi/tests/test_case.html b/ppapi/tests/test_case.html index 6c53f88..96d3a38 100644 --- a/ppapi/tests/test_case.html +++ b/ppapi/tests/test_case.html @@ -117,6 +117,18 @@ function LogHTML(html) { window.document.getElementById("console").innerHTML += html; } +// If something goes really wrong, the test running inside the plugin may not +// terminate. For example, if the plugin does not load, the test will never +// send "PASS" to the browser. In this case we should explicitly use the +// automation controller to terminate the test. +function InternalError(msg) { + LogHTML("

" + msg); + if (window.domAutomationController) { + domAutomationController.setAutomationId(0); + domAutomationController.send(msg); + } +} + function SetCookie(key_value_string) { window.document.cookie = key_value_string + "; path=/"; } @@ -236,11 +248,22 @@ onload = function() { var container = document.getElementById("container"); container.addEventListener("message", handleTestingMessage, true); + // "error" and "crash" events will only fire for NaCl, but adding these + // listeners doesn't hurt in the non-NaCl cases. + obj.addEventListener("error", function() { + InternalError("Plugin did not load. '" + obj.lastError + "'"); + }, true); + obj.addEventListener("crash", function() { + InternalError("Plugin crashed. '" + obj.lastError + "'"); + }, true); // Register a bad dispatchEvent to make sure it isn't used. See 'EVIL' note // below. + var original = obj.dispatchEvent; obj.dispatchEvent = function() { LogHTML("

Bad dispatchEvent called! " + "see crbug.com/109775)"); + // Pass it on anyways, we need the event to detect load errors. + original.apply(obj, arguments); } container.appendChild(obj); } -- cgit v1.1