Merge backout
authorChris Jones <jones.chris.g@gmail.com>
Thu, 11 Mar 2010 05:07:25 -0600
changeset 39274 ae008deedbda235e4524b056566178ad004ffa58
parent 39272 a94a5275742c44c6b0a1ab7ed65a4901b5bbe8c7 (current diff)
parent 39273 2f09728dc1edeedb06cecf875e4a3b92a7fe7814 (diff)
child 39276 e968afb45a8d912d3673fbdd47b4ddc6d93fdbb1
push id12111
push usercjones@mozilla.com
push dateThu, 11 Mar 2010 11:09:52 +0000
treeherdermozilla-central@e968afb45a8d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
milestone1.9.3a3pre
Merge backout
modules/plugin/test/mochitest/test_crash_nested_loop.html
modules/plugin/test/testplugin/nptest_gtk2.cpp
--- a/modules/plugin/test/mochitest/Makefile.in
+++ b/modules/plugin/test/mochitest/Makefile.in
@@ -111,17 +111,16 @@ ifeq (cocoa,$(MOZ_WIDGET_TOOLKIT))
 _MOCHICHROME_FILES += \
   test_convertpoint.xul \
   $(NULL)
 endif
 
 ifeq (gtk2,$(MOZ_WIDGET_TOOLKIT))
 _MOCHITEST_FILES += \
 		test_copyText.html \
-		test_crash_nested_loop.html \
 		$(NULL)
 endif
 
 ifdef MOZ_IPC
 _MOCHICHROME_FILES += \
   test_crash_notify.xul \
   test_crash_notify_no_report.xul \
   $(NULL)
deleted file mode 100644
--- a/modules/plugin/test/mochitest/test_crash_nested_loop.html
+++ /dev/null
@@ -1,40 +0,0 @@
-<head>
-  <title>Plugin crashing in nested loop</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');
-
-    try {
-      p.crashInNestedLoop();
-      ok(false, "p.crashInNestedLoop() should throw an exception");
-    }
-    catch (e) {
-      ok(true, "p.crashInNestedLoop() should throw an exception");
-    }
-
-    // this test is for bug 550026, which is inherently
-    // nondeterministic.  if we hit that bug, the browser process
-    // would have crashed by now.  if not, we'll pass "spuriously"
-    SimpleTest.finish();
-  }
-
-  </script>
--- a/modules/plugin/test/testplugin/nptest.cpp
+++ b/modules/plugin/test/testplugin/nptest.cpp
@@ -55,26 +55,24 @@
 
  using namespace std;
 
 #define PLUGIN_NAME        "Test Plug-in"
 #define PLUGIN_DESCRIPTION "Plug-in for testing purposes."
 #define PLUGIN_VERSION     "1.0.0.0"
 
 #define ARRAY_LENGTH(a) (sizeof(a)/sizeof(a[0]))
-#define STATIC_ASSERT(condition)                                \
-    extern void np_static_assert(int arg[(condition) ? 1 : -1])
 
 //
 // Intentional crash
 //
 
 int gCrashCount = 0;
 
-void
+static void
 NoteIntentionalCrash()
 {
   char* bloatLog = getenv("XPCOM_MEM_BLOAT_LOG");
   if (bloatLog) {
     char* logExt = strstr(bloatLog, ".log");
     if (logExt) {
       bloatLog[strlen(bloatLog) - strlen(logExt)] = '\0';
     }
@@ -84,19 +82,21 @@ NoteIntentionalCrash()
       bloatName << ".log";
     }
     FILE* processfd = fopen(bloatName.str().c_str(), "a");
     fprintf(processfd, "==> process %d will purposefully crash\n", getpid());
     fclose(processfd);
   }
 }
 
-void
+static void
 IntentionalCrash()
 {
+  NoteIntentionalCrash();
+
   int *pi = NULL;
   *pi = 55; // Crash dereferencing null pointer
   ++gCrashCount;
 }
 
 //
 // static data
 //
@@ -151,17 +151,16 @@ static bool enableFPExceptions(NPObject*
 static bool setCookie(NPObject* npobj, const NPVariant* args, uint32_t argCount, NPVariant* result);
 static bool getCookie(NPObject* npobj, const NPVariant* args, uint32_t argCount, NPVariant* result);
 static bool getAuthInfo(NPObject* npobj, const NPVariant* args, uint32_t argCount, NPVariant* result);
 static bool asyncCallbackTest(NPObject* npobj, const NPVariant* args, uint32_t argCount, NPVariant* result);
 static bool checkGCRace(NPObject* npobj, const NPVariant* args, uint32_t argCount, NPVariant* result);
 static bool hangPlugin(NPObject* npobj, const NPVariant* args, uint32_t argCount, NPVariant* result);
 static bool getClipboardText(NPObject* npobj, const NPVariant* args, uint32_t argCount, NPVariant* result);
 static bool callOnDestroy(NPObject* npobj, const NPVariant* args, uint32_t argCount, NPVariant* result);
-static bool crashPluginInNestedLoop(NPObject* npobj, const NPVariant* args, uint32_t argCount, NPVariant* result);
 
 static const NPUTF8* sPluginMethodIdentifierNames[] = {
   "npnEvaluateTest",
   "npnInvokeTest",
   "npnInvokeDefaultTest",
   "setUndefinedValueTest",
   "identifierToStringTest",
   "timerTest",
@@ -193,20 +192,19 @@ static const NPUTF8* sPluginMethodIdenti
   "setCookie",
   "getCookie",
   "getAuthInfo",
   "asyncCallbackTest",
   "checkGCRace",
   "hang",
   "getClipboardText",
   "callOnDestroy",
-  "crashInNestedLoop",
 };
 static NPIdentifier sPluginMethodIdentifiers[ARRAY_LENGTH(sPluginMethodIdentifierNames)];
-static const ScriptableFunction sPluginMethodFunctions[] = {
+static const ScriptableFunction sPluginMethodFunctions[ARRAY_LENGTH(sPluginMethodIdentifierNames)] = {
   npnEvaluateTest,
   npnInvokeTest,
   npnInvokeDefaultTest,
   setUndefinedValueTest,
   identifierToStringTest,
   timerTest,
   queryPrivateModeState,
   lastReportedPrivateModeState,
@@ -236,22 +234,18 @@ static const ScriptableFunction sPluginM
   setCookie,
   getCookie,
   getAuthInfo,
   asyncCallbackTest,
   checkGCRace,
   hangPlugin,
   getClipboardText,
   callOnDestroy,
-  crashPluginInNestedLoop,
 };
 
-STATIC_ASSERT(ARRAY_LENGTH(sPluginMethodIdentifierNames) ==
-              ARRAY_LENGTH(sPluginMethodFunctions));
-
 struct URLNotifyData
 {
   const char* cookie;
   NPObject* callback;
   uint32_t size;
   char* data;
 };
 
@@ -706,17 +700,16 @@ NPP_New(NPMIMEType pluginType, NPP insta
       }
       if (range.length()) addRange(instanceData, range.c_str());
     }
     if (strcmp(argn[i], "newstream") == 0 &&
         strcmp(argv[i], "true") == 0) {
       instanceData->npnNewStream = true;
     }
     if (strcmp(argn[i], "newcrash") == 0) {
-      NoteIntentionalCrash();
       IntentionalCrash();
     }
   }
 
   if (!browserSupportsWindowless || !pluginSupportsWindowlessMode()) {
     requestWindow = true;
   } else if (!pluginSupportsWindowMode()) {
     requestWindow = false;
@@ -789,20 +782,18 @@ NPP_New(NPMIMEType pluginType, NPP insta
 }
 
 NPError
 NPP_Destroy(NPP instance, NPSavedData** save)
 {
   printf("NPP_Destroy\n");
   InstanceData* instanceData = (InstanceData*)(instance->pdata);
 
-  if (instanceData->crashOnDestroy) {
-    NoteIntentionalCrash();
+  if (instanceData->crashOnDestroy)
     IntentionalCrash();
-  }
 
   if (instanceData->callOnDestroy) {
     NPVariant result;
     NPN_InvokeDefault(instance, instanceData->callOnDestroy, NULL, 0, &result);
     NPN_ReleaseVariantValue(&result);
     NPN_ReleaseObject(instanceData->callOnDestroy);
   }
 
@@ -2149,17 +2140,16 @@ streamTest(NPObject* npobj, const NPVari
   }
 
   return true;
 }
 
 static bool
 crashPlugin(NPObject* npobj, const NPVariant* args, uint32_t argCount, NPVariant* result)
 {
-  NoteIntentionalCrash();
   IntentionalCrash();
   VOID_TO_NPVARIANT(*result);
   return true;
 }
 
 static bool
 crashOnDestroy(NPObject* npobj, const NPVariant* args, uint32_t argCount, NPVariant* result)
 {
@@ -2636,39 +2626,22 @@ getClipboardText(NPObject* npobj, const 
   selCopy[len] = '\0';
 
   STRINGN_TO_NPVARIANT(selCopy, len, *result);
   // *result owns str now
 
   return true;
 }
 
-bool
-crashPluginInNestedLoop(NPObject* npobj, const NPVariant* args,
-                        uint32_t argCount, NPVariant* result)
-{
-  NPP npp = static_cast<TestNPObject*>(npobj)->npp;
-  InstanceData* id = static_cast<InstanceData*>(npp->pdata);
-  return pluginCrashInNestedLoop(id);
-}
-
 #else
 bool
 getClipboardText(NPObject* npobj, const NPVariant* args, uint32_t argCount,
                  NPVariant* result)
 {
-  // XXX Not implemented!
-  return false;
-}
-
-bool
-crashPluginInNestedLoop(NPObject* npobj, const NPVariant* args,
-                        uint32_t argCount, NPVariant* result)
-{
-  // XXX Not implemented!
+  /// XXX Not implemented!
   return false;
 }
 #endif
 
 bool
 callOnDestroy(NPObject* npobj, const NPVariant* args, uint32_t argCount, NPVariant* result)
 {
   NPP npp = static_cast<TestNPObject*>(npobj)->npp;
--- a/modules/plugin/test/testplugin/nptest.h
+++ b/modules/plugin/test/testplugin/nptest.h
@@ -122,12 +122,9 @@ typedef struct InstanceData {
   TestRange* testrange;
   void* streamBuf;
   void* fileBuf;
   bool crashOnDestroy;
 } InstanceData;
 
 void notifyDidPaint(InstanceData* instanceData);
 
-void NoteIntentionalCrash();
-void IntentionalCrash();
-
 #endif // nptest_h_
--- a/modules/plugin/test/testplugin/nptest_gtk2.cpp
+++ b/modules/plugin/test/testplugin/nptest_gtk2.cpp
@@ -30,25 +30,22 @@
  * Contributor(s):
  *   Josh Aas <josh@mozilla.com>
  *   Michael Ventnor <mventnor@mozilla.com>
  * 
  * ***** END LICENSE BLOCK ***** */
 
 #include "nptest_platform.h"
 #include "npapi.h"
-#include <pthread.h>
 #include <gdk/gdk.h>
 #ifdef MOZ_X11
 #include <gdk/gdkx.h>
 #include <X11/extensions/shape.h>
 #endif
-#include <glib.h>
 #include <gtk/gtk.h>
-#include <unistd.h>
 
  using namespace std;
 
 struct _PlatformData {
 #ifdef MOZ_X11
   Display* display;
   Visual* visual;
   Colormap colormap;
@@ -633,73 +630,8 @@ pluginGetClipboardText(InstanceData* ins
   // deprecated interface only to test nested event loop handling.
   gchar* text = gtk_clipboard_wait_for_text(cb);
   string retText = text ? text : "";
 
   g_free(text);
 
   return retText;
 }
-
-//-----------------------------------------------------------------------------
-// NB: this test is quite gross in that it's not only
-// nondeterministic, but dependent on the guts of the nested glib
-// event loop handling code in PluginModule.  We first sleep long
-// enough to make sure that the "detection timer" will be pending when
-// we enter the nested glib loop, then similarly for the "process browser
-// events" timer.  Then we "schedule" the crasher thread to run at about the
-// same time we expect that the PluginModule "process browser events" task
-// will run.  If all goes well, the plugin process will crash and generate the
-// XPCOM "plugin crashed" task, and the browser will run that task while still
-// in the "process some events" loop.
-
-static void*
-CrasherThread(void* data)
-{
-  // Give the parent thread a chance to send the message.
-  usleep(200);
-
-  IntentionalCrash();
-
-  // not reached
-  return(NULL);
-}
-
-bool
-pluginCrashInNestedLoop(InstanceData* instanceData)
-{
-  // wait at least long enough for nested loop detector task to be pending ...
-  sleep(1);
-
-  // Run the nested loop detector.  Other events are not expected.
-  if (!g_main_context_iteration(NULL, TRUE)) {
-    g_warning("DetectNestedEventLoop did not fire");
-    return true; // trigger a test failure
-
-  }
-
-  // wait at least long enough for the "process browser events" task to be
-  // pending ...
-  sleep(1);
-
-  // we'll be crashing soon, note that fact now to avoid messing with
-  // timing too much
-  NoteIntentionalCrash();
-
-  // schedule the crasher thread ...
-  pthread_t crasherThread;
-  if (0 != pthread_create(&crasherThread, NULL, CrasherThread, NULL)) {
-    g_warning("Failed to create thread");
-    return true; // trigger a test failure
-  }
-
-  // .. and hope the time it takes to spawn means that it crashes at about the
-  // same time as the "process browser events" task that should run next is
-  // being processed in the parent.  Other events are not expected.
-  if (g_main_context_iteration(NULL, TRUE)) {
-    g_warning("Should have crashed in ProcessBrowserEvents");
-  } else {
-    g_warning("ProcessBrowserEvents did not fire");
-  }
-
-  // if we get here without crashing, then we'll trigger a test failure
-  return true;
-}
--- a/modules/plugin/test/testplugin/nptest_platform.h
+++ b/modules/plugin/test/testplugin/nptest_platform.h
@@ -121,17 +121,9 @@ int32_t pluginGetClipRegionRectEdge(Inst
 void pluginDoInternalConsistencyCheck(InstanceData* instanceData, std::string& error);
 
 /**
  * Get the current clipboard item as text.  If the clipboard item
  * isn't text, the returned value is undefined.
  */
 std::string pluginGetClipboardText(InstanceData* instanceData);
 
-/**
- * Crash while in a nested event loop.  The goal is to catch the
- * browser processing the XPCOM event generated from the plugin's
- * crash while other plugin code is still on the stack. 
- * See https://bugzilla.mozilla.org/show_bug.cgi?id=550026.
- */
-bool pluginCrashInNestedLoop(InstanceData* instanceData);
-
 #endif // nptest_platform_h_