1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/plugins/test/mochitest/test_convertpoint.xul Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,84 @@ 1.4 +<?xml version="1.0"?> 1.5 +<?xml-stylesheet href="chrome://global/skin" type="text/css"?> 1.6 +<?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css" 1.7 + type="text/css"?> 1.8 +<window title="Basic Plugin Tests" 1.9 + xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> 1.10 + <script type="application/javascript" 1.11 + src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js" /> 1.12 + <script type="application/javascript" src="utils.js"></script> 1.13 + <script type="application/javascript"> 1.14 + setTestPluginEnabledState(SpecialPowers.Ci.nsIPluginTag.STATE_ENABLED); 1.15 + </script> 1.16 +<body xmlns="http://www.w3.org/1999/xhtml" onload="runTests()"> 1.17 +<embed id="plugin1" type="application/x-test" width="200" height="200"></embed> 1.18 +</body> 1.19 +<script class="testbody" type="application/javascript"> 1.20 +<![CDATA[ 1.21 +SimpleTest.waitForExplicitFinish(); 1.22 + 1.23 +function runTests() { 1.24 + var pluginElement = document.getElementById("plugin1"); 1.25 + // Poll to see if the plugin is in the right place yet. 1.26 + // Check if x-coordinate 0 in plugin space is 0 in window space. If it is, 1.27 + // the plugin hasn't been placed yet. 1.28 + if (pluginElement.convertPointX(1, 0, 0, 2) == 0) { 1.29 + setTimeout(runTests, 0); 1.30 + return; 1.31 + } 1.32 + 1.33 + var domWindowUtils = window.QueryInterface(Components.interfaces.nsIInterfaceRequestor) 1.34 + .getInterface(Components.interfaces.nsIDOMWindowUtils); 1.35 + var devPxPerCSSPx = domWindowUtils.screenPixelsPerCSSPixel; 1.36 + 1.37 + var pluginRect = pluginElement.getBoundingClientRect(); 1.38 + var pluginX = (pluginRect.left * devPxPerCSSPx) + ((window.mozInnerScreenX * devPxPerCSSPx) - window.screenX); 1.39 + var pluginY = (pluginRect.top * devPxPerCSSPx) + ((window.mozInnerScreenY * devPxPerCSSPx) - window.screenY); 1.40 + 1.41 + var windowX = window.screenX; 1.42 + var windowY = window.screenY; 1.43 + var windowHeight = window.outerHeight; 1.44 + 1.45 + var screenHeight = window.screen.height; 1.46 + 1.47 + // arbitrary coordinates of test point in plugin top-left origin terms 1.48 + var xOffset = 5; 1.49 + var yOffset = 5; 1.50 + 1.51 + var NPCoordinateSpacePluginX = 0 + xOffset; 1.52 + var NPCoordinateSpacePluginY = 0 + yOffset; 1.53 + 1.54 + var NPCoordinateSpaceWindowX = pluginX + xOffset; 1.55 + var NPCoordinateSpaceWindowY = (windowHeight - pluginY) - yOffset; 1.56 + 1.57 + var NPCoordinateSpaceFlippedWindowX = pluginX + xOffset; 1.58 + var NPCoordinateSpaceFlippedWindowY = pluginY + yOffset; 1.59 + 1.60 + var NPCoordinateSpaceScreenX = windowX + pluginX + xOffset; 1.61 + var NPCoordinateSpaceScreenY = ((screenHeight - windowY) - pluginY) - yOffset; 1.62 + 1.63 + var NPCoordinateSpaceFlippedScreenX = windowX + pluginX + xOffset; 1.64 + var NPCoordinateSpaceFlippedScreenY = windowY + pluginY + yOffset; 1.65 + 1.66 + // these are in coordinate space enumeration order 1.67 + var xValues = new Array(NPCoordinateSpacePluginX, NPCoordinateSpaceWindowX, NPCoordinateSpaceFlippedWindowX, NPCoordinateSpaceScreenX, NPCoordinateSpaceFlippedScreenX); 1.68 + var yValues = new Array(NPCoordinateSpacePluginY, NPCoordinateSpaceWindowY, NPCoordinateSpaceFlippedWindowY, NPCoordinateSpaceScreenY, NPCoordinateSpaceFlippedScreenY); 1.69 + 1.70 + var i; 1.71 + for (i = 0; i < 5; i = i + 1) { 1.72 + var sourceCoordSpaceValue = i + 1; 1.73 + var j; 1.74 + for (j = 0; j < 5; j = j + 1) { 1.75 + var destCoordSpaceValue = j + 1; 1.76 + xResult = pluginElement.convertPointX(sourceCoordSpaceValue, xValues[i], yValues[i], destCoordSpaceValue); 1.77 + yResult = pluginElement.convertPointY(sourceCoordSpaceValue, xValues[i], yValues[i], destCoordSpaceValue); 1.78 + is(xResult, xValues[j], "convertPointX: space " + sourceCoordSpaceValue + " to space " + destCoordSpaceValue + " mismatch"); 1.79 + is(yResult, yValues[j], "convertPointY: space " + sourceCoordSpaceValue + " to space " + destCoordSpaceValue + " mismatch"); 1.80 + } 1.81 + } 1.82 + 1.83 + SimpleTest.finish(); 1.84 +} 1.85 +]]> 1.86 +</script> 1.87 +</window>