Add a .crash() method to the testplugin, and test that crashing throws exceptions in the parent.

This commit is contained in:
Benjamin Smedberg 2009-12-03 15:33:25 -05:00
Родитель f1d7c769d8
Коммит 3e52740eeb
5 изменённых файлов: 83 добавлений и 0 удалений

Просмотреть файл

@ -69,6 +69,13 @@ _MOCHITEST_FILES = \
# test_npruntime_npnsetexception.html \ Disabled for e10s
ifdef MOZ_IPC
_MOCHITEST_FILES += \
test_crashing.html \
crashing_subpage.html \
$(NULL)
endif
ifeq ($(OS_ARCH),WINNT)
_MOCHITEST_FILES += \
test_windowed_invalidate.html \

Просмотреть файл

@ -0,0 +1,4 @@
<html>
<body onload="window.parent.frameLoaded()">
<h1>Crashing subpage</h1>
<embed id="plugin1" type="application/x-test" width="400" height="400" drawmode="solid" color="FF00FFFF"></embed>

Просмотреть файл

@ -0,0 +1,59 @@
<head>
<title>Plugin crashing</title>
<script type="application/javascript" src="chrome://mochikit/content/MochiKit/packed.js"></script>
<script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
<body>
<iframe id="iframe1" src="crashing_subpage.html" width="600" height="600"></iframe>
<script class="testbody" type="application/javascript">
SimpleTest.waitForExplicitFinish();
var iframe = document.getElementById('iframe1');
window.frameLoaded = function frameLoaded_toCrash() {
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
var prefs = Components.classes['@mozilla.org/preferences-service;1']
.getService(Components.interfaces.nsIPrefBranch);
if (!prefs.getBoolPref('dom.ipc.plugins.enabled')) {
ok(true, "Skipping this test when IPC plugins are not enabled.");
SimpleTest.finish();
return;
}
var p = iframe.contentDocument.getElementById('plugin1');
p.setColor("FFFF00FF");
try {
p.crash();
ok(false, "p.crash() should throw an exception");
}
catch (e) {
ok(true, "p.crash() should throw an exception");
}
try {
p.setColor("FFFF0000");
ok(false, "p.setColor should throw after the plugin crashes");
}
catch (e) {
ok(true, "p.setColor should throw after the plugin crashes");
}
window.frameLoaded = function reloaded() {
var p = iframe.contentDocument.getElementById('plugin1');
try {
p.setColor('FF00FF00');
ok(true, "Reloading worked");
}
catch (e) {
ok(false, "Reloading didn't give us a usable plugin");
}
SimpleTest.finish();
}
iframe.contentWindow.location.reload();
}
</script>

Просмотреть файл

@ -72,6 +72,8 @@ used as the exception message. Example:
Returns a string consisting of the plugin name, concatenated with any
arguments passed to the method.
* .crash() - Crashes the plugin
== Private browsing ==
The test plugin object supports the following scriptable methods:

Просмотреть файл

@ -95,6 +95,7 @@ static bool throwExceptionNextInvoke(NPObject* npobj, const NPVariant* args, uin
static bool convertPointX(NPObject* npobj, const NPVariant* args, uint32_t argCount, NPVariant* result);
static bool convertPointY(NPObject* npobj, const NPVariant* args, uint32_t argCount, NPVariant* result);
static bool streamTest(NPObject* npobj, const NPVariant* args, uint32_t argCount, NPVariant* result);
static bool crash(NPObject* npobj, const NPVariant* args, uint32_t argCount, NPVariant* result);
static const NPUTF8* sPluginMethodIdentifierNames[] = {
"npnEvaluateTest",
@ -123,6 +124,7 @@ static const NPUTF8* sPluginMethodIdentifierNames[] = {
"convertPointX",
"convertPointY",
"streamTest",
"crash",
};
static NPIdentifier sPluginMethodIdentifiers[ARRAY_LENGTH(sPluginMethodIdentifierNames)];
static const ScriptableFunction sPluginMethodFunctions[ARRAY_LENGTH(sPluginMethodIdentifierNames)] = {
@ -152,6 +154,7 @@ static const ScriptableFunction sPluginMethodFunctions[ARRAY_LENGTH(sPluginMetho
convertPointX,
convertPointY,
streamTest,
crash,
};
struct URLNotifyData
@ -2015,6 +2018,14 @@ streamTest(NPObject* npobj, const NPVariant* args, uint32_t argCount, NPVariant*
return true;
}
static bool
crash(NPObject* npobj, const NPVariant* args, uint32_t argCount, NPVariant* result)
{
void (*funcptr)() = NULL;
funcptr(); // Crash calling null function pointer
return true;
}
static bool
setColor(NPObject* npobj, const NPVariant* args, uint32_t argCount, NPVariant* result)
{