Bug 1171182 - Mochitest for NPAPI Zoom; r=bsmedberg
authorKyle Machulis <kyle@nonpolynomial.com>
Thu, 17 Mar 2016 12:02:04 -0700
changeset 289438 4a3d5109a73e0a9297d0607acc07c143fd4917f9
parent 289437 e32d4804b6760cc3ab76a83233bd41a044fa7342
child 289439 b40d8bae66f1097f3c7cb1833614d9e58e87cd2a
push id19656
push usergwagner@mozilla.com
push dateMon, 04 Apr 2016 13:43:23 +0000
treeherderb2g-inbound@e99061fde28a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbsmedberg
bugs1171182
milestone48.0a1
Bug 1171182 - Mochitest for NPAPI Zoom; r=bsmedberg
dom/plugins/test/mochitest/mochitest.ini
dom/plugins/test/mochitest/test_queryCSSZoomFactor.html
dom/plugins/test/testplugin/nptest.cpp
dom/plugins/test/testplugin/nptest.h
--- a/dom/plugins/test/mochitest/mochitest.ini
+++ b/dom/plugins/test/mochitest/mochitest.ini
@@ -112,16 +112,17 @@ support-files =
 [test_pluginstream_seek.html]
 [test_pluginstream_seek_close.html]
 [test_pluginstream_src.html]
 [test_pluginstream_src_dynamic.html]
 [test_pluginstream_src_referer.html]
 [test_positioning.html]
 skip-if = true # disabled due to oddness, perhaps scrolling of the mochitest window?
 [test_propertyAndMethod.html]
+[test_queryCSSZoomFactor.html]
 [test_queryContentsScaleFactor.html]
 skip-if = toolkit != "cocoa"
 [test_redirect_handling.html]
 [test_secondPlugin.html]
 [test_src_url_change.html]
 [test_streamNotify.html]
 [test_stringHandling.html]
 [test_streamatclose.html]
new file mode 100644
--- /dev/null
+++ b/dom/plugins/test/mochitest/test_queryCSSZoomFactor.html
@@ -0,0 +1,48 @@
+<html>
+  <head>
+    <title>NPAPI NPNVcontentsScaleFactor Test</title>
+    <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+    <script type="application/javascript" src="plugin-utils.js"></script>
+  </head>
+
+  <body onload="runTests()">
+    <script class="testbody" type="application/javascript">
+     SimpleTest.waitForExplicitFinish();
+     setTestPluginEnabledState(SpecialPowers.Ci.nsIPluginTag.STATE_ENABLED);
+
+     function checkZoomFactor(zoomFactor, expectedValue) {
+       // Done as if/ok instead of is() so we don't spam test results
+       if (isNaN(zoomFactor)) {
+         ok(false, "Return should be valid when getting CSS zoom factor");
+       }
+       return (expectedValue - zoomFactor) < 0.00001;
+     }
+
+     function testZoom() {
+       var pluginElement = document.getElementById("plugin");
+       // setTimeout loop on value checks, as zoom value updates can take some
+       // time and we don't have a good event to listen for.
+       if (!checkZoomFactor(pluginElement.queryCSSZoomFactorGetValue(), 2.0) ||
+           !checkZoomFactor(pluginElement.queryCSSZoomFactorSetValue(), 2.0)) {
+         setTimeout(testZoom, 0);
+         return;
+       }
+       ok(true, "Zoom values set to 2.0 as expected");
+       // set back to 1 when we're done otherwise later tests can fail
+       SpecialPowers.setFullZoom(window, 1.0);
+       SimpleTest.finish();
+     }
+
+     function runTests() {
+       var pluginElement = document.getElementById("plugin");
+       // Don't check SetValue yet, needs to happen after zoom has been explicitly set.
+       ok(checkZoomFactor(pluginElement.queryCSSZoomFactorGetValue(), 1.0), "Zoom values set to 1.0 as expected");
+       SpecialPowers.setFullZoom(window, 2.0);
+       // Check for new zoom value sometime after we've spun event loop to repaint.
+       setTimeout(testZoom, 0);
+     }
+    </script>
+
+    <embed id="plugin" type="application/x-test" width="400" height="400"></embed>
+  </body>
+</html>
--- a/dom/plugins/test/testplugin/nptest.cpp
+++ b/dom/plugins/test/testplugin/nptest.cpp
@@ -163,16 +163,18 @@ static bool isVisible(NPObject* npobj, c
 static bool getWindowPosition(NPObject* npobj, const NPVariant* args, uint32_t argCount, NPVariant* result);
 static bool constructObject(NPObject* npobj, const NPVariant* args, uint32_t argCount, NPVariant* result);
 static bool setSitesWithData(NPObject* npobj, const NPVariant* args, uint32_t argCount, NPVariant* result);
 static bool setSitesWithDataCapabilities(NPObject* npobj, const NPVariant* args, uint32_t argCount, NPVariant* result);
 static bool getLastKeyText(NPObject* npobj, const NPVariant* args, uint32_t argCount, NPVariant* result);
 static bool getNPNVdocumentOrigin(NPObject* npobj, const NPVariant* args, uint32_t argCount, NPVariant* result);
 static bool getMouseUpEventCount(NPObject* npobj, const NPVariant* args, uint32_t argCount, NPVariant* result);
 static bool queryContentsScaleFactor(NPObject* npobj, const NPVariant* args, uint32_t argCount, NPVariant* result);
+static bool queryCSSZoomFactorGetValue(NPObject* npobj, const NPVariant* args, uint32_t argCount, NPVariant* result);
+static bool queryCSSZoomFactorSetValue(NPObject* npobj, const NPVariant* args, uint32_t argCount, NPVariant* result);
 static bool echoString(NPObject* npobj, const NPVariant* args, uint32_t argCount, NPVariant* result);
 static bool startAudioPlayback(NPObject* npobj, const NPVariant* args, uint32_t argCount, NPVariant* result);
 static bool stopAudioPlayback(NPObject* npobj, const NPVariant* args, uint32_t argCount, NPVariant* result);
 static bool getAudioMuted(NPObject* npobj, const NPVariant* args, uint32_t argCount, NPVariant* result);
 static bool nativeWidgetIsVisible(NPObject* npobj, const NPVariant* args, uint32_t argCount, NPVariant* result);
 static bool getLastCompositionText(NPObject* npobj, const NPVariant* args, uint32_t argCount, NPVariant* result);
 
 static const NPUTF8* sPluginMethodIdentifierNames[] = {
@@ -235,16 +237,18 @@ static const NPUTF8* sPluginMethodIdenti
   "getWindowPosition",
   "constructObject",
   "setSitesWithData",
   "setSitesWithDataCapabilities",
   "getLastKeyText",
   "getNPNVdocumentOrigin",
   "getMouseUpEventCount",
   "queryContentsScaleFactor",
+  "queryCSSZoomFactorSetValue",
+  "queryCSSZoomFactorGetValue",
   "echoString",
   "startAudioPlayback",
   "stopAudioPlayback",
   "audioMuted",
   "nativeWidgetIsVisible",
   "getLastCompositionText",
 };
 static NPIdentifier sPluginMethodIdentifiers[MOZ_ARRAY_LENGTH(sPluginMethodIdentifierNames)];
@@ -308,16 +312,18 @@ static const ScriptableFunction sPluginM
   getWindowPosition,
   constructObject,
   setSitesWithData,
   setSitesWithDataCapabilities,
   getLastKeyText,
   getNPNVdocumentOrigin,
   getMouseUpEventCount,
   queryContentsScaleFactor,
+  queryCSSZoomFactorGetValue,
+  queryCSSZoomFactorSetValue,
   echoString,
   startAudioPlayback,
   stopAudioPlayback,
   getAudioMuted,
   nativeWidgetIsVisible,
   getLastCompositionText,
 };
 
@@ -850,16 +856,17 @@ NPP_New(NPMIMEType pluginType, NPP insta
   instanceData->closeStream = false;
   instanceData->wantsAllStreams = false;
   instanceData->mouseUpEventCount = 0;
   instanceData->bugMode = -1;
   instanceData->asyncDrawing = AD_NONE;
   instanceData->frontBuffer = nullptr;
   instanceData->backBuffer = nullptr;
   instanceData->placeholderWnd = nullptr;
+  instanceData->cssZoomFactor = 1.0;
   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");
     delete instanceData;
     return NPERR_GENERIC_ERROR;
   }
@@ -1591,16 +1598,21 @@ NPP_SetValue(NPP instance, NPNVariable v
     instanceData->lastReportedPrivateModeState = bool(*static_cast<NPBool*>(value));
     return NPERR_NO_ERROR;
   }
   if (variable == NPNVmuteAudioBool) {
     InstanceData* instanceData = (InstanceData*)(instance->pdata);
     instanceData->audioMuted = bool(*static_cast<NPBool*>(value));
     return NPERR_NO_ERROR;
   }
+  if (variable == NPNVCSSZoomFactor) {
+    InstanceData* instanceData = (InstanceData*)(instance->pdata);
+    instanceData->cssZoomFactor = *static_cast<double*>(value);
+    return NPERR_NO_ERROR;
+  }
   return NPERR_GENERIC_ERROR;
 }
 
 void
 NPP_URLRedirectNotify(NPP instance, const char* url, int32_t status, void* notifyData)
 {
   if (notifyData) {
     URLNotifyData* nd = static_cast<URLNotifyData*>(notifyData);
@@ -3915,16 +3927,48 @@ bool queryContentsScaleFactor(NPObject* 
   if (err != NPERR_NO_ERROR) {
     return false;
   }
 #endif
   DOUBLE_TO_NPVARIANT(scaleFactor, *result);
   return true;
 }
 
+bool queryCSSZoomFactorSetValue(NPObject* npobj, const NPVariant* args, uint32_t argCount, NPVariant* result)
+{
+  if (argCount != 0)
+    return false;
+
+  NPP npp = static_cast<TestNPObject*>(npobj)->npp;
+  if (!npp) {
+    return false;
+  }
+  InstanceData* id = static_cast<InstanceData*>(npp->pdata);
+  if (!id) {
+    return false;
+  }
+  DOUBLE_TO_NPVARIANT(id->cssZoomFactor, *result);
+  return true;
+}
+
+bool queryCSSZoomFactorGetValue(NPObject* npobj, const NPVariant* args, uint32_t argCount, NPVariant* result)
+{
+  if (argCount != 0)
+    return false;
+
+  double zoomFactor = 1.0;
+  NPError err = NPN_GetValue(static_cast<TestNPObject*>(npobj)->npp,
+                             NPNVCSSZoomFactor, &zoomFactor);
+  if (err != NPERR_NO_ERROR) {
+    return false;
+  }
+  DOUBLE_TO_NPVARIANT(zoomFactor, *result);
+  return true;
+}
+
 bool echoString(NPObject* npobj, const NPVariant* args, uint32_t argCount, NPVariant* result)
 {
   if (argCount != 1) {
     return false;
   }
 
   if (!NPVARIANT_IS_STRING(args[0])) {
     return false;
--- a/dom/plugins/test/testplugin/nptest.h
+++ b/dom/plugins/test/testplugin/nptest.h
@@ -153,16 +153,17 @@ typedef struct InstanceData {
   int32_t mouseUpEventCount;
   int32_t bugMode;
   std::string javaCodebase;
   AsyncDrawing asyncDrawing;
   NPAsyncSurface *frontBuffer;
   NPAsyncSurface *backBuffer;
   std::string lastComposition;
   void* placeholderWnd;
+  double cssZoomFactor;
 } InstanceData;
 
 void notifyDidPaint(InstanceData* instanceData);
 
 #if defined(XP_WIN)
 bool setupDxgiSurfaces(NPP npp, InstanceData* instanceData);
 void drawDxgiBitmapColor(InstanceData* instanceData);
 #endif