Bug 813906 - Mochitest for unified base URI usage. r=bsmedberg
authorGeorg Fritzsche <georg.fritzsche@googlemail.com>
Fri, 23 Nov 2012 20:35:49 +0100
changeset 121756 7ec124ace4cbf38baa0a94643fd8314f0e7acff3
parent 121755 c8479bdaf0c869029948e78eb78517ed84cf0a57
child 121757 2da3edf254fb39ad77385834a3c1b11333c7d2b2
push id24307
push useremorley@mozilla.com
push dateThu, 14 Feb 2013 10:47:46 +0000
treeherdermozilla-central@aceeea086ccb [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbsmedberg
bugs813906
milestone21.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 813906 - Mochitest for unified base URI usage. r=bsmedberg
dom/plugins/test/mochitest/Makefile.in
dom/plugins/test/mochitest/test_bug813906.html
dom/plugins/test/testplugin/nptest.cpp
dom/plugins/test/testplugin/nptest.h
--- a/dom/plugins/test/mochitest/Makefile.in
+++ b/dom/plugins/test/mochitest/Makefile.in
@@ -60,16 +60,17 @@ MOCHITEST_FILES = \
   test_GCrace.html \
   test_propertyAndMethod.html \
   test_bug539565-1.html \
   test_bug539565-2.html \
   test_bug771202.html \
   file_bug771202.html \
   test_bug777098.html \
   test_bug751809.html \
+  test_bug813906.html \
   test_enumerate.html \
   test_npruntime_construct.html \
   307-xo-redirect.sjs \
   test_redirect_handling.html \
   test_zero_opacity.html \
   test_NPPVpluginWantsAllNetworkStreams.html \
   test_npruntime_npnsetexception.html \
   test_NPNVdocumentOrigin.html \
new file mode 100644
--- /dev/null
+++ b/dom/plugins/test/mochitest/test_bug813906.html
@@ -0,0 +1,47 @@
+<!doctype html>
+<html>
+<head>
+  <title>Test for Bug 813906</title>
+  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
+
+  <meta http-equiv="content-type" content="text/html; charset=utf-8">
+  <base href="chrome://browser/content/">
+</head>
+<body>
+
+<script type="application/javascript">
+function f() {
+  document.getElementsByTagName("base")[0].href = "http://www.safe.com/";
+}
+</script>
+
+<svg>
+  <symbol id="a">
+    <foreignObject>
+      <object bugmode="813906" frame="frame1"></object>
+    </foreignObject>
+  </symbol>
+  <use />
+</svg>
+
+<script type="application/javascript">
+SimpleTest.waitForExplicitFinish();
+
+var frameLoadCount = 0;
+function frameLoaded() {
+  frameLoadCount++;
+  if (frameLoadCount == 1) {
+    document.getElementsByTagName("object")[0].type = "application/x-test";
+    document.getElementsByTagName("use")[0].setAttributeNS("http://www.w3.org/1999/xlink", "href", location.href + "#a");
+  } else if (frameLoadCount == 2) {
+    isnot(SpecialPowers.wrap(window.frame1).location.href.indexOf('chrome://'),
+          0, 'plugin shouldnt be able to cause navigation to chrome URLs');
+    SimpleTest.finish();
+  }
+}
+</script>
+
+<iframe name="frame1" onload="frameLoaded()"></iframe>
+</body>
+</html>
--- a/dom/plugins/test/testplugin/nptest.cpp
+++ b/dom/plugins/test/testplugin/nptest.cpp
@@ -52,16 +52,18 @@
 #include <float.h>
 #include <windows.h>
 #define getpid _getpid
 #else
 #include <unistd.h>
 #include <pthread.h>
 #endif
 
+#include "mozilla/NullPtr.h"
+
 using namespace std;
 
 #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])
 
 extern const char *sPluginName;
@@ -578,16 +580,42 @@ drawAsyncBitmapColor(InstanceData* insta
   }
 
   NPN_SetCurrentAsyncSurface(npp, instanceData->backBuffer, NULL);
   NPAsyncSurface *oldFront = instanceData->frontBuffer;
   instanceData->frontBuffer = instanceData->backBuffer;
   instanceData->backBuffer = oldFront;
 }
 
+static bool bug813906(NPP npp, const char* const function, const char* const url, const char* const frame)
+{
+  NPObject *windowObj = nullptr;
+  NPError err = NPN_GetValue(npp, NPNVWindowNPObject, &windowObj);
+  if (err != NPERR_NO_ERROR) {
+    return false;
+  }
+
+  NPVariant result;
+  bool res = NPN_Invoke(npp, windowObj, NPN_GetStringIdentifier(function), nullptr, 0, &result);
+  NPN_ReleaseObject(windowObj);
+  if (!res) {
+    return false;
+  }
+
+  NPN_ReleaseVariantValue(&result);
+
+  err = NPN_GetURL(npp, url, frame);
+  if (err != NPERR_NO_ERROR) {
+    err = NPN_GetURL(npp, "about:blank", frame);
+    return false;
+  }
+
+  return true;
+}
+
 //
 // function signatures
 //
 
 NPObject* scriptableAllocate(NPP npp, NPClass* aClass);
 void scriptableDeallocate(NPObject* npobj);
 void scriptableInvalidate(NPObject* npobj);
 bool scriptableHasMethod(NPObject* npobj, NPIdentifier name);
@@ -789,16 +817,17 @@ NPP_New(NPMIMEType pluginType, NPP insta
   instanceData->focusEventCount = 0;
   instanceData->eventModel = 0;
   instanceData->closeStream = false;
   instanceData->wantsAllStreams = false;
   instanceData->asyncDrawing = AD_NONE;
   instanceData->frontBuffer = NULL;
   instanceData->backBuffer = NULL;
   instanceData->mouseUpEventCount = 0;
+  instanceData->bugMode = -1;
   instance->pdata = instanceData;
 
   TestNPObject* scriptableObject = (TestNPObject*)NPN_CreateObject(instance, &sNPClass);
   if (!scriptableObject) {
     printf("NPN_CreateObject failed to create an object, can't create a plugin instance\n");
     free(instanceData);
     return NPERR_GENERIC_ERROR;
   }
@@ -919,16 +948,19 @@ NPP_New(NPMIMEType pluginType, NPP insta
     // window gets destroyed).
     if (strcmp(argn[i], "cleanupwidget") == 0 &&
         strcmp(argv[i], "false") == 0) {
       instanceData->cleanupWidget = false;
     }
     if (!strcmp(argn[i], "closestream")) {
       instanceData->closeStream = true;
     }
+    if (strcmp(argn[i], "bugmode") == 0) {
+      instanceData->bugMode = atoi(argv[i]);
+    }
   }
 
   if (!browserSupportsWindowless || !pluginSupportsWindowlessMode()) {
     requestWindow = true;
   } else if (!pluginSupportsWindowMode()) {
     requestWindow = false;
   }
   if (requestWindow) {
@@ -1011,16 +1043,20 @@ NPP_New(NPMIMEType pluginType, NPP insta
   else if (instanceData->testFunction == FUNCTION_NPP_GETURLNOTIFY) {
     NPError err = NPN_GetURLNotify(instance, instanceData->testUrl.c_str(), 
                                    NULL, static_cast<void*>(&kNotifyData));
     if (err != NPERR_NO_ERROR) {
       instanceData->err << "NPN_GetURLNotify returned " << err;
     }
   }
 
+  if ((instanceData->bugMode == 813906) && instanceData->frame.length()) {
+    bug813906(instance, "f", "browser.xul", instanceData->frame.c_str());
+  }
+
   return NPERR_NO_ERROR;
 }
 
 NPError
 NPP_Destroy(NPP instance, NPSavedData** save)
 {
   printf("NPP_Destroy\n");
   InstanceData* instanceData = (InstanceData*)(instance->pdata);
--- a/dom/plugins/test/testplugin/nptest.h
+++ b/dom/plugins/test/testplugin/nptest.h
@@ -146,13 +146,14 @@ typedef struct InstanceData {
   int32_t eventModel;
   bool closeStream;
   std::string lastKeyText;
   bool wantsAllStreams;
   AsyncDrawing asyncDrawing;
   NPAsyncSurface *frontBuffer;
   NPAsyncSurface *backBuffer;
   int32_t mouseUpEventCount;
+  int32_t bugMode;
 } InstanceData;
 
 void notifyDidPaint(InstanceData* instanceData);
 
 #endif // nptest_h_