Bug 749257 - Improve test plugin. r=josh, r=bsmedberg
authorDavid Keeler <dkeeler@mozilla.com>
Mon, 13 Aug 2012 10:40:15 -0700
changeset 107809 1230521b11d32352d89f2da2bde168bde56f428b
parent 107808 3f2e53e13f401fbc3ef04898b62b555872da2146
child 107810 3b7250c5316a60b2442d76b666bd6362ee8d5bd0
push idunknown
push userunknown
push dateunknown
reviewersjosh, bsmedberg
bugs749257
milestone17.0a1
Bug 749257 - Improve test plugin. r=josh, r=bsmedberg
dom/plugins/test/mochitest/Makefile.in
dom/plugins/test/mochitest/test_secondPlugin.html
dom/plugins/test/testplugin/Makefile.in
dom/plugins/test/testplugin/nptest.cpp
dom/plugins/test/testplugin/nptest_name.cpp
dom/plugins/test/testplugin/secondplugin/Info.plist
dom/plugins/test/testplugin/secondplugin/Makefile.in
dom/plugins/test/testplugin/secondplugin/nptest.def
dom/plugins/test/testplugin/secondplugin/nptest.rc
dom/plugins/test/testplugin/secondplugin/nptest_name.cpp
dom/plugins/test/testplugin/testplugin.mk
testing/mochitest/Makefile.in
--- a/dom/plugins/test/mochitest/Makefile.in
+++ b/dom/plugins/test/mochitest/Makefile.in
@@ -75,16 +75,17 @@ MOCHITEST_FILES = \
   test_instance_re-parent.html \
   test_instance_unparent1.html \
   test_instance_unparent2.html \
   test_instance_unparent3.html \
   test_pluginstream_referer.html \
   test_pluginstream_src_referer.html \
   plugin-stream-referer.sjs \
   test_src_url_change.html \
+  test_secondPlugin.html \
   $(NULL)
 
 #  test_plugin_scroll_painting.html \ bug 596491
 
 ifeq ($(OS_ARCH),WINNT)
 MOCHITEST_FILES += \
   test_windowed_invalidate.html \
   $(NULL)
new file mode 100644
--- /dev/null
+++ b/dom/plugins/test/mochitest/test_secondPlugin.html
@@ -0,0 +1,33 @@
+<html>
+  <head>
+     <title>Second Test Plug-in Test</title>
+
+    <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+    <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
+  </head>
+
+  <body onload="run()">
+    <object id="plugin" type="application/x-second-test" width=200 height=200></object>
+
+    <script class="testbody" type="application/javascript">
+      SimpleTest.waitForExplicitFinish();
+
+      function run() {
+        var foundFirstPlugin = false;
+        var foundSecondPlugin = false;
+        for (var index in navigator.plugins) {
+          var plugin = navigator.plugins[index];
+          if (plugin.name == "Test Plug-in") foundFirstPlugin = true;
+          if (plugin.name == "Second Test Plug-in") foundSecondPlugin = true;
+        }
+        ok(foundFirstPlugin, "Should have a plugin named 'Test Plug-in'");
+        ok(foundSecondPlugin, "Should have a plugin named 'Second Test Plug-in'");
+
+        var pluginElement = document.getElementById("plugin");
+        is(pluginElement.identifierToStringTest("foo"), "foo", "Should be able to call a function provided by the plugin");
+
+        SimpleTest.finish();
+      }
+    </script>
+  </body>
+</html>
--- a/dom/plugins/test/testplugin/Makefile.in
+++ b/dom/plugins/test/testplugin/Makefile.in
@@ -8,90 +8,14 @@ topsrcdir = @top_srcdir@
 srcdir    = @srcdir@
 VPATH     = @srcdir@
 
 include $(DEPTH)/config/autoconf.mk
 
 MODULE       = nptest
 LIBRARY_NAME = nptest
 MODULE_NAME  = TestPlugin
-FORCE_SHARED_LIB = 1
 
-# Don't use STL wrappers; nptest isn't Gecko code
-STL_FLAGS =
-
-# must link statically with the CRT; nptest isn't Gecko code
-USE_STATIC_LIBS = 1
-
-# Need to custom install plugins
-NO_DIST_INSTALL	= 1
-NO_INSTALL = 1
-
-VPATH += $(topsrcdir)/build
-
-CPPSRCS   =  \
-  nptest.cpp \
-  nptest_utils.cpp \
-  $(NULL)
-
-ifeq ($(MOZ_WIDGET_TOOLKIT),cocoa)
-CMMSRCS = nptest_macosx.mm
-endif
-
-ifeq ($(MOZ_WIDGET_TOOLKIT),gtk2)
-CPPSRCS += nptest_gtk2.cpp
-endif
-
-ifeq ($(MOZ_WIDGET_TOOLKIT),android)
-CPPSRCS += nptest_droid.cpp
-endif
-
-ifeq ($(MOZ_WIDGET_TOOLKIT),os2)
-CPPSRCS += nptest_os2.cpp
-endif
+DIRS = secondplugin
 
-ifeq ($(MOZ_WIDGET_TOOLKIT),qt)
-CPPSRCS += nptest_qt.cpp
-include $(topsrcdir)/config/config.mk
-CXXFLAGS        += $(MOZ_QT_CFLAGS)
-CFLAGS          += $(MOZ_QT_CFLAGS)
-EXTRA_DSO_LDOPTS = \
-                $(MOZ_QT_LIBS) \
-                $(XLDFLAGS) \
-                $(XLIBS)
-endif
-
-ifeq ($(MOZ_WIDGET_TOOLKIT),windows)
-CPPSRCS  += nptest_windows.cpp
-RCFILE    = nptest.rc
-RESFILE   = nptest.res
-DEFFILE   = $(win_srcdir)/nptest.def
-OS_LIBS  += $(call EXPAND_LIBNAME,msimg32)
-
-# Windows opt builds without PGO break nptest.dll
-MOZ_OPTIMIZE=
-endif
-
-include $(topsrcdir)/config/rules.mk
-
-ifndef __LP64__
-ifeq ($(MOZ_WIDGET_TOOLKIT),cocoa)
-EXTRA_DSO_LDOPTS += -framework Carbon
-endif
-endif
-
-ifeq ($(MOZ_WIDGET_TOOLKIT),gtk2)
-CXXFLAGS        += $(MOZ_GTK2_CFLAGS)
-CFLAGS          += $(MOZ_GTK2_CFLAGS)
-EXTRA_DSO_LDOPTS += $(MOZ_GTK2_LIBS) $(XLDFLAGS) $(XLIBS) $(XEXT_LIBS)
-endif
-
-install-plugin: $(SHARED_LIBRARY)
-ifdef SHARED_LIBRARY
-ifeq ($(MOZ_WIDGET_TOOLKIT),cocoa)
-	$(INSTALL) $(srcdir)/Info.plist $(DIST)/bin/plugins/Test.plugin/Contents
-	$(INSTALL) $(SHARED_LIBRARY) $(DIST)/bin/plugins/Test.plugin/Contents/MacOS
-else
-	$(INSTALL) $(SHARED_LIBRARY) $(DIST)/bin/plugins
-endif
-endif
-
-libs:: install-plugin
+RELATIVE_PATH=.
+COCOA_NAME=Test
+include @srcdir@/testplugin.mk
--- a/dom/plugins/test/testplugin/nptest.cpp
+++ b/dom/plugins/test/testplugin/nptest.cpp
@@ -54,29 +54,23 @@
 #define getpid _getpid
 #else
 #include <unistd.h>
 #include <pthread.h>
 #endif
 
 using namespace std;
 
-#define PLUGIN_NAME        "Test Plug-in"
-#define PLUGIN_DESCRIPTION "Plug-in for testing purposes.\xE2\x84\xA2 "          \
-    "(\xe0\xa4\xb9\xe0\xa4\xbf\xe0\xa4\xa8\xe0\xa5\x8d\xe0\xa4\xa6\xe0\xa5\x80 " \
-    "\xe4\xb8\xad\xe6\x96\x87 "                                                  \
-    "\xd8\xa7\xd9\x84\xd8\xb9\xd8\xb1\xd8\xa8\xd9\x8a\xd8\xa9)"
 #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])
 
-static char sPluginName[] = PLUGIN_NAME; 
-static char sPluginDescription[] = PLUGIN_DESCRIPTION;
+extern const char *sPluginName;
+extern const char *sPluginDescription;
 static char sPluginVersion[] = PLUGIN_VERSION;
 
 //
 // Intentional crash
 //
 
 int gCrashCount = 0;
 
@@ -598,36 +592,36 @@ bool scriptableConstruct(NPObject* npobj
 #ifdef XP_UNIX
 NP_EXPORT(char*)
 NP_GetPluginVersion()
 {
   return sPluginVersion;
 }
 #endif
 
-static char sMimeDescription[] = "application/x-test:tst:Test mimetype";
+extern const char *sMimeDescription;
 
 #if defined(XP_UNIX)
 NP_EXPORT(const char*) NP_GetMIMEDescription()
 #elif defined(XP_WIN) || defined(XP_OS2)
 const char* NP_GetMIMEDescription()
 #endif
 {
   return sMimeDescription;
 }
 
 #ifdef XP_UNIX
 NP_EXPORT(NPError)
 NP_GetValue(void* future, NPPVariable aVariable, void* aValue) {
   switch (aVariable) {
     case NPPVpluginNameString:
-      *((char**)aValue) = sPluginName;
+      *((const char**)aValue) = sPluginName;
       break;
     case NPPVpluginDescriptionString:
-      *((char**)aValue) = sPluginDescription;
+      *((const char**)aValue) = sPluginDescription;
       break;
     default:
       return NPERR_INVALID_PARAM;
       break;
   }
   return NPERR_NO_ERROR;
 }
 #endif
@@ -1955,17 +1949,17 @@ scriptableInvokeDefault(NPObject* npobj,
         const NPString* argstr = &NPVARIANT_TO_STRING(args[i]);
         NPN_SetException(npobj, argstr->UTF8Characters);
       }
     }
     return false;
   }
 
   ostringstream value;
-  value << PLUGIN_NAME;
+  value << sPluginName;
   for (uint32_t i = 0; i < argCount; i++) {
     switch(args[i].type) {
       case NPVariantType_Int32:
         value << ";" << NPVARIANT_TO_INT32(args[i]);
         break;
       case NPVariantType_String: {
         const NPString* argstr = &NPVARIANT_TO_STRING(args[i]);
         value << ";" << argstr->UTF8Characters;
new file mode 100644
--- /dev/null
+++ b/dom/plugins/test/testplugin/nptest_name.cpp
@@ -0,0 +1,6 @@
+const char *sPluginName = "Test Plug-in";
+const char *sPluginDescription = "Plug-in for testing purposes.\xE2\x84\xA2 "  \
+  "(\xe0\xa4\xb9\xe0\xa4\xbf\xe0\xa4\xa8\xe0\xa5\x8d\xe0\xa4\xa6\xe0\xa5\x80 " \
+  "\xe4\xb8\xad\xe6\x96\x87 "                                                  \
+  "\xd8\xa7\xd9\x84\xd8\xb9\xd8\xb1\xd8\xa8\xd9\x8a\xd8\xa9)";
+const char *sMimeDescription = "application/x-test:tst:Test mimetype";
new file mode 100644
--- /dev/null
+++ b/dom/plugins/test/testplugin/secondplugin/Info.plist
@@ -0,0 +1,38 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+	<key>CFBundleDevelopmentRegion</key>
+	<string>English</string>
+	<key>CFBundleExecutable</key>
+	<string>libnpsecondtest.dylib</string>
+	<key>CFBundleIdentifier</key>
+	<string>org.mozilla.SecondTestPlugin</string>
+	<key>CFBundleInfoDictionaryVersion</key>
+	<string>6.0</string>
+	<key>CFBundlePackageType</key>
+	<string>BRPL</string>
+	<key>CFBundleShortVersionString</key>
+	<string>1.0.0.0</string>
+	<key>CFBundleSignature</key>
+	<string>SECONDTEST</string>
+	<key>CFBundleVersion</key>
+	<string>1.0.0.0</string>
+	<key>WebPluginName</key>
+	<string>Second Test Plug-in</string>
+	<key>WebPluginDescription</key>
+	<string>Second plug-in for testing purposes.</string>
+	<key>WebPluginMIMETypes</key>
+	<dict>
+		<key>application/x-second-test</key>
+		<dict>
+			<key>WebPluginExtensions</key>
+			<array>
+				<string>ts2</string>
+			</array>
+			<key>WebPluginTypeDescription</key>
+			<string>Second test type</string>
+		</dict>
+	</dict>
+</dict>
+</plist>
new file mode 100644
--- /dev/null
+++ b/dom/plugins/test/testplugin/secondplugin/Makefile.in
@@ -0,0 +1,19 @@
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this file,
+# You can obtain one at http://mozilla.org/MPL/2.0/.
+
+DEPTH     = ../../../../..
+topsrcdir = @top_srcdir@
+srcdir    = @srcdir@
+VPATH     = @srcdir@
+
+include $(DEPTH)/config/autoconf.mk
+
+MODULE       = npsecondtest
+LIBRARY_NAME = npsecondtest
+MODULE_NAME  = SecondTestPlugin
+
+RELATIVE_PATH=..
+COCOA_NAME=SecondTest
+include @srcdir@/../testplugin.mk
new file mode 100644
--- /dev/null
+++ b/dom/plugins/test/testplugin/secondplugin/nptest.def
@@ -0,0 +1,7 @@
+LIBRARY   NPSECONDTEST
+
+EXPORTS
+  NP_GetEntryPoints     @1
+  NP_Initialize         @2
+  NP_Shutdown           @3
+  NP_GetMIMEDescription @4
new file mode 100644
--- /dev/null
+++ b/dom/plugins/test/testplugin/secondplugin/nptest.rc
@@ -0,0 +1,42 @@
+#include<winver.h>
+
+
+/////////////////////////////////////////////////////////////////////////////
+//
+// Version
+//
+
+VS_VERSION_INFO VERSIONINFO
+ FILEVERSION    1,0,0,0
+ PRODUCTVERSION 1,0,0,0
+ FILEFLAGSMASK 0x3fL
+#ifdef _DEBUG
+ FILEFLAGS 0x1L
+#else
+ FILEFLAGS 0x0L
+#endif
+ FILEOS VOS__WINDOWS32
+ FILETYPE VFT_DLL
+ FILESUBTYPE 0x0L
+BEGIN
+    BLOCK "StringFileInfo"
+    BEGIN
+        BLOCK "040904e4"
+        BEGIN
+            VALUE "CompanyName", "mozilla.org"
+            VALUE "FileDescription", L"Second plug-in for testing purposes."
+            VALUE "FileExtents", "ts2"
+            VALUE "FileOpenName", "Second test type"
+            VALUE "FileVersion", "1.0"
+            VALUE "InternalName", "npsecondtest"
+            VALUE "MIMEType", "application/x-second-test"
+            VALUE "OriginalFilename", "npsecondtest.dll"
+            VALUE "ProductName", "Second Test Plug-in"
+            VALUE "ProductVersion", "1.0"
+        END
+    END
+    BLOCK "VarFileInfo"
+    BEGIN
+        VALUE "Translation", 0x409, 1252
+    END
+END
new file mode 100644
--- /dev/null
+++ b/dom/plugins/test/testplugin/secondplugin/nptest_name.cpp
@@ -0,0 +1,7 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this file,
+ * You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+const char *sPluginName = "Second Test Plug-in";
+const char *sPluginDescription = "Second plug-in for testing purposes.";
+const char *sMimeDescription = "application/x-second-test:ts2:Second test type";
new file mode 100644
--- /dev/null
+++ b/dom/plugins/test/testplugin/testplugin.mk
@@ -0,0 +1,88 @@
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this file,
+# You can obtain one at http://mozilla.org/MPL/2.0/.
+
+FORCE_SHARED_LIB = 1
+
+# Don't use STL wrappers; nptest isn't Gecko code
+STL_FLAGS =
+
+# must link statically with the CRT; nptest isn't Gecko code
+USE_STATIC_LIBS = 1
+
+# Need to custom install plugins
+NO_DIST_INSTALL	= 1
+NO_INSTALL = 1
+
+VPATH += $(topsrcdir)/build
+
+CPPSRCS   =  \
+  $(RELATIVE_PATH)/nptest.cpp \
+  $(RELATIVE_PATH)/nptest_utils.cpp \
+  nptest_name.cpp \
+  $(NULL)
+
+ifeq ($(MOZ_WIDGET_TOOLKIT),cocoa)
+CMMSRCS = $(RELATIVE_PATH)/nptest_macosx.mm
+endif
+
+ifeq ($(MOZ_WIDGET_TOOLKIT),gtk2)
+CPPSRCS += $(RELATIVE_PATH)/nptest_gtk2.cpp
+endif
+
+ifeq ($(MOZ_WIDGET_TOOLKIT),android)
+CPPSRCS += $(RELATIVE_PATH)/nptest_droid.cpp
+endif
+
+ifeq ($(MOZ_WIDGET_TOOLKIT),os2)
+CPPSRCS += $(RELATIVE_PATH)/nptest_os2.cpp
+endif
+
+ifeq ($(MOZ_WIDGET_TOOLKIT),qt)
+CPPSRCS += $(RELATIVE_PATH)/nptest_qt.cpp
+include $(topsrcdir)/config/config.mk
+CXXFLAGS        += $(MOZ_QT_CFLAGS)
+CFLAGS          += $(MOZ_QT_CFLAGS)
+EXTRA_DSO_LDOPTS = \
+                $(MOZ_QT_LIBS) \
+                $(XLDFLAGS) \
+                $(XLIBS)
+endif
+
+ifeq ($(MOZ_WIDGET_TOOLKIT),windows)
+CPPSRCS  += $(RELATIVE_PATH)/nptest_windows.cpp
+RCFILE    = nptest.rc
+RESFILE   = nptest.res
+DEFFILE   = $(win_srcdir)/nptest.def
+OS_LIBS  += $(call EXPAND_LIBNAME,msimg32)
+
+# Windows opt builds without PGO break nptest.dll
+MOZ_OPTIMIZE=
+endif
+
+include $(topsrcdir)/config/rules.mk
+
+ifndef __LP64__
+ifeq ($(MOZ_WIDGET_TOOLKIT),cocoa)
+EXTRA_DSO_LDOPTS += -framework Carbon
+endif
+endif
+
+ifeq ($(MOZ_WIDGET_TOOLKIT),gtk2)
+CXXFLAGS        += $(MOZ_GTK2_CFLAGS)
+CFLAGS          += $(MOZ_GTK2_CFLAGS)
+EXTRA_DSO_LDOPTS += $(MOZ_GTK2_LIBS) $(XLDFLAGS) $(XLIBS) $(XEXT_LIBS)
+endif
+
+install-plugin: $(SHARED_LIBRARY)
+ifdef SHARED_LIBRARY
+ifeq ($(MOZ_WIDGET_TOOLKIT),cocoa)
+	$(INSTALL) $(srcdir)/Info.plist $(DIST)/bin/plugins/$(COCOA_NAME).plugin/Contents
+	$(INSTALL) $(SHARED_LIBRARY) $(DIST)/bin/plugins/$(COCOA_NAME).plugin/Contents/MacOS
+else
+	$(INSTALL) $(SHARED_LIBRARY) $(DIST)/bin/plugins
+endif
+endif
+
+libs:: install-plugin
--- a/testing/mochitest/Makefile.in
+++ b/testing/mochitest/Makefile.in
@@ -161,20 +161,22 @@ endif
 # the build, but that we need for the test harness.
 TEST_HARNESS_COMPONENTS := \
   test_necko.xpt \
   $(NULL)
 
 # We need the test plugin as some tests rely on it
 ifeq (Darwin,$(OS_TARGET))
 TEST_HARNESS_PLUGINS := \
-  Test.plugin/
+  Test.plugin/ \
+  SecondTest.plugin/
 else
 TEST_HARNESS_PLUGINS := \
-  $(DLL_PREFIX)nptest$(DLL_SUFFIX)
+  $(DLL_PREFIX)nptest$(DLL_SUFFIX) \
+  $(DLL_PREFIX)npsecondtest$(DLL_SUFFIX)
 endif
 
 # Rules for staging the necessary harness bits for a test package
 PKG_STAGE = $(DIST)/test-package-stage
 DIST_BIN = $(DIST)/bin
 
 PKG_CHROMEJAR = $(PKG_STAGE)/mochitest/content/