Bug 833936 - Mochitest that queries NPNVcontentsScaleFactor. r=bsmedberg

This commit is contained in:
Steven Michaud 2013-03-21 15:23:46 -05:00
parent 91d34a2ca0
commit 6f326250c4
4 changed files with 56 additions and 2 deletions

View File

@ -155,6 +155,7 @@ MOCHITEST_FILES += \
cocoa_window_focus.html \
test_cocoa_focus.html \
cocoa_focus.html \
test_queryContentsScaleFactor.html \
$(NULL)
endif

View File

@ -0,0 +1,26 @@
<html>
<head>
<title>NPAPI NPNVcontentsScaleFactor Test</title>
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
</head>
<body onload="runTests()">
<embed id="plugin" type="application/x-test" width="400" height="400"></embed>
<script class="testbody" type="application/javascript">
SimpleTest.waitForExplicitFinish();
function runTests() {
var pluginElement = document.getElementById("plugin");
var contentsScaleFactor;
var exceptionThrown = false;
try {
contentsScaleFactor = pluginElement.queryContentsScaleFactor();
} catch (e) {
exceptionThrown = true;
}
is(exceptionThrown, false, "Exception thrown getting contents scale factor.");
is(isNaN(contentsScaleFactor), false, "Invalid return getting contents scale factor");
SimpleTest.finish();
}
</script>
</body>
</html>

View File

@ -421,3 +421,10 @@ x86-only on some OSes:
* The .enableFPExceptions() method will enable floating-point exceptions,
as evil plugins or extensions might do.
== HiDPI Mode ==
* queryContentsScaleFactor()
Returns the contents scale factor. On platforms without support for this query
always returns 1.0 (a double value). Likewise on hardware without HiDPI mode
support.

View File

@ -167,6 +167,7 @@ static bool setSitesWithDataCapabilities(NPObject* npobj, const NPVariant* args,
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 const NPUTF8* sPluginMethodIdentifierNames[] = {
"npnEvaluateTest",
@ -228,7 +229,8 @@ static const NPUTF8* sPluginMethodIdentifierNames[] = {
"setSitesWithDataCapabilities",
"getLastKeyText",
"getNPNVdocumentOrigin",
"getMouseUpEventCount"
"getMouseUpEventCount",
"queryContentsScaleFactor"
};
static NPIdentifier sPluginMethodIdentifiers[ARRAY_LENGTH(sPluginMethodIdentifierNames)];
static const ScriptableFunction sPluginMethodFunctions[] = {
@ -291,7 +293,8 @@ static const ScriptableFunction sPluginMethodFunctions[] = {
setSitesWithDataCapabilities,
getLastKeyText,
getNPNVdocumentOrigin,
getMouseUpEventCount
getMouseUpEventCount,
queryContentsScaleFactor
};
STATIC_ASSERT(ARRAY_LENGTH(sPluginMethodIdentifierNames) ==
@ -3738,3 +3741,20 @@ bool getMouseUpEventCount(NPObject* npobj, const NPVariant* args, uint32_t argCo
INT32_TO_NPVARIANT(id->mouseUpEventCount, *result);
return true;
}
bool queryContentsScaleFactor(NPObject* npobj, const NPVariant* args, uint32_t argCount, NPVariant* result)
{
if (argCount != 0)
return false;
double scaleFactor = 1.0;
#if defined(XP_MACOSX)
NPError err = NPN_GetValue(static_cast<TestNPObject*>(npobj)->npp,
NPNVcontentsScaleFactor, &scaleFactor);
if (err != NPERR_NO_ERROR) {
return false;
}
#endif
DOUBLE_TO_NPVARIANT(scaleFactor, *result);
return true;
}