зеркало из https://github.com/mozilla/gecko-dev.git
Bug 339548. Part 11: tests for complex plugin clipping.
This commit is contained in:
Родитель
2f9e8221d8
Коммит
f474c72e3b
|
@ -52,6 +52,8 @@ _TEST_FILES = \
|
|||
frame_selection_underline-ref.xhtml \
|
||||
frame_selection_underline.css \
|
||||
plugin_clipping_helper.xhtml \
|
||||
plugin_clipping_helper2.xhtml \
|
||||
plugin_clipping_lib.js \
|
||||
test_backspace_delete.xul \
|
||||
test_bug263683.html \
|
||||
test_bug288789.html \
|
||||
|
@ -83,6 +85,7 @@ _TEST_FILES = \
|
|||
test_movement_by_characters.html \
|
||||
test_movement_by_words.html \
|
||||
test_plugin_clipping.xhtml \
|
||||
test_plugin_clipping2.xhtml \
|
||||
test_plugin_position.xhtml \
|
||||
test_selection_underline.html \
|
||||
$(NULL)
|
||||
|
|
|
@ -37,197 +37,20 @@
|
|||
</div>
|
||||
</div>
|
||||
<!-- Clipped by an iframe -->
|
||||
<iframe id="f1" style="position:absolute; left:200px; top:200px; width:200px; height:200px;"></iframe>
|
||||
<iframe id="f1" style="position:absolute; left:200px; top:200px; width:200px; height:200px;"
|
||||
src="data:text/html,<embed style='position:absolute; left:-100px; top:-100px; width:200px; height:200px;' id='p5' type='application/x-test' wmode='window'>"></iframe>
|
||||
|
||||
<script src="plugin_clipping_lib.js"></script>
|
||||
<script class="testbody" type="application/javascript">
|
||||
<![CDATA[
|
||||
|
||||
var windowFrameX, windowFrameY;
|
||||
|
||||
var f1 = document.getElementById("f1");
|
||||
f1.src = "data:text/html," +
|
||||
"<embed style='position:absolute; left:-100px; top:-100px; width:200px; height:200px;'" +
|
||||
"id='p5' type='application/x-test' wmode='window'></embed>";
|
||||
|
||||
// Import test API
|
||||
var is = window.opener.is;
|
||||
var ok = window.opener.ok;
|
||||
var todo = window.opener.todo;
|
||||
var SimpleTest = window.opener.SimpleTest;
|
||||
|
||||
function dumpRegion(rects) {
|
||||
var s = [];
|
||||
for (var i = 0; i < rects.length; ++i) {
|
||||
var r = rects[i];
|
||||
s.push("{" + r.join(",") + "}");
|
||||
}
|
||||
return s.join(", ");
|
||||
}
|
||||
|
||||
function generateSpan(coords) {
|
||||
coords.sort(function(a,b) { return a - b; });
|
||||
var result = [coords[0]];
|
||||
for (var i = 1; i < coords.length; ++i) {
|
||||
if (coords[i] != coords[i - 1]) {
|
||||
result.push(coords[i]);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
function containsRect(r1, r2) {
|
||||
return r1[0] <= r2[0] && r1[2] >= r2[2] &&
|
||||
r1[1] <= r2[1] && r1[3] >= r2[3];
|
||||
}
|
||||
|
||||
function subtractRect(r1, r2, rlist) {
|
||||
var spanX = generateSpan([r1[0], r1[2], r2[0], r2[2]]);
|
||||
var spanY = generateSpan([r1[1], r1[3], r2[1], r2[3]]);
|
||||
for (var i = 1; i < spanX.length; ++i) {
|
||||
for (var j = 1; j < spanY.length; ++j) {
|
||||
var subrect = [spanX[i - 1], spanY[j - 1], spanX[i], spanY[j]];
|
||||
if (containsRect(r1, subrect) && !containsRect(r2, subrect)) {
|
||||
rlist.push(subrect);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function regionContainsRect(rs, r) {
|
||||
var rectList = [r];
|
||||
for (var i = 0; i < rs.length; ++i) {
|
||||
var newList = [];
|
||||
for (var j = 0; j < rectList.length; ++j) {
|
||||
subtractRect(rs[i], rectList[j], newList);
|
||||
}
|
||||
if (newList.length == 0)
|
||||
return true;
|
||||
rectList = newList;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function regionContains(r1s, r2s) {
|
||||
for (var i = 0; i < r2s.length; ++i) {
|
||||
if (!regionContainsRect(r1s, r2s[i]))
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
function equalRegions(r1s, r2s) {
|
||||
return regionContains(r1s, r2s) && regionContains(r2s, r1s);
|
||||
}
|
||||
|
||||
// Checks that a plugin's clip region equals the specified rectangle list.
|
||||
// The rectangles are given relative to the plugin's top-left. They are in
|
||||
// [left, top, right, bottom] format.
|
||||
function checkClipRegionWithDoc(doc, offsetX, offsetY, id, rects) {
|
||||
var p = doc.getElementById(id);
|
||||
var pX = p.getEdge(0);
|
||||
var pY = p.getEdge(1);
|
||||
var pWidth = p.getEdge(2) - pX;
|
||||
var pHeight = p.getEdge(3) - pY;
|
||||
var bounds = p.getBoundingClientRect();
|
||||
|
||||
// First, check regular area
|
||||
is(pX, windowFrameX + bounds.left + offsetX, id + " plugin X");
|
||||
is(pY, windowFrameY + bounds.top + offsetY, id + " plugin Y");
|
||||
is(pWidth, bounds.width, id + " plugin width");
|
||||
is(pHeight, bounds.height, id + " plugin height");
|
||||
|
||||
// Now check clip region. 'rects' is relative to the plugin's top-left.
|
||||
var clipRects = [];
|
||||
var n = p.getClipRegionRectCount();
|
||||
for (var i = 0; i < n; ++i) {
|
||||
// Convert the clip rect to be relative to the plugin's top-left.
|
||||
clipRects[i] = [
|
||||
p.getClipRegionRectEdge(i, 0) - pX,
|
||||
p.getClipRegionRectEdge(i, 1) - pY,
|
||||
p.getClipRegionRectEdge(i, 2) - pX,
|
||||
p.getClipRegionRectEdge(i, 3) - pY
|
||||
];
|
||||
}
|
||||
|
||||
ok(equalRegions(clipRects, rects), "Matching regions for '" + id + "': expected " +
|
||||
dumpRegion(rects) + ", got " + dumpRegion(clipRects));
|
||||
}
|
||||
|
||||
function checkClipRegion(id, rects) {
|
||||
checkClipRegionWithDoc(document, 0, 0, id, rects);
|
||||
}
|
||||
|
||||
function checkClipRegionForFrame(fid, id, rects) {
|
||||
var f = document.getElementById(fid);
|
||||
var bounds = f.getBoundingClientRect();
|
||||
checkClipRegionWithDoc(f.contentDocument, bounds.left, bounds.top, id, rects);
|
||||
}
|
||||
|
||||
function runTests2() {
|
||||
function check(id, doc) {
|
||||
var p = (doc || document).getElementById(id);
|
||||
if (p.getClipRegionRectEdge(0, 0) ==
|
||||
p.getClipRegionRectEdge(0, 2))
|
||||
throw id;
|
||||
}
|
||||
|
||||
try {
|
||||
check("p1");
|
||||
check("p2");
|
||||
check("p3");
|
||||
check("p4");
|
||||
check("p5", f1.contentDocument);
|
||||
} catch (id) {
|
||||
// One or more plugins haven't been updated yet. Wait.
|
||||
setTimeout(runTests2, 100);
|
||||
return;
|
||||
}
|
||||
|
||||
function runTests() {
|
||||
checkClipRegion("p1", [[0, 0, 200, 200]]);
|
||||
checkClipRegion("p2", [[100, 100, 200, 200]]);
|
||||
checkClipRegion("p3", [[100, 100, 200, 200]]);
|
||||
checkClipRegion("p4", [[100, 100, 200, 200]]);
|
||||
checkClipRegionForFrame("f1", "p5", [[100, 100, 200, 200]]);
|
||||
|
||||
SimpleTest.finish();
|
||||
window.close();
|
||||
}
|
||||
|
||||
function runTests() {
|
||||
var h1 = document.getElementById("h1");
|
||||
var h2 = document.getElementById("h2");
|
||||
var hwidth = h2.boxObject.screenX - h1.boxObject.screenX;
|
||||
if (hwidth != 100) {
|
||||
// Maybe it's a DPI issue
|
||||
todo(false, "Unexpected DPI?");
|
||||
SimpleTest.finish();
|
||||
window.close();
|
||||
return;
|
||||
}
|
||||
|
||||
if (!document.getElementById("p1").identifierToStringTest) {
|
||||
todo(false, "Test plugin not available");
|
||||
SimpleTest.finish();
|
||||
window.close();
|
||||
return;
|
||||
}
|
||||
|
||||
if (navigator.platform.indexOf("Win") >= 0) {
|
||||
todo(false, "Windows does not support windowed plugins (yet)");
|
||||
SimpleTest.finish();
|
||||
window.close();
|
||||
return;
|
||||
}
|
||||
|
||||
var bounds = h1.getBoundingClientRect();
|
||||
windowFrameX = h1.boxObject.screenX - bounds.left - window.screenX;
|
||||
windowFrameY = h1.boxObject.screenY - bounds.top - window.screenY;
|
||||
|
||||
runTests2();
|
||||
}
|
||||
|
||||
window.addEventListener("load", runTests, false);
|
||||
|
||||
]]>
|
||||
</script>
|
||||
|
||||
|
|
|
@ -0,0 +1,74 @@
|
|||
<?xml version="1.0"?>
|
||||
<?xml-stylesheet href="/tests/SimpleTest/test.css" type="text/css"?>
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" title="Test Plugin Clipping: Dynamic Tests">
|
||||
<head>
|
||||
<script type="application/javascript" src="/MochiKit/packed.js"></script>
|
||||
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<style>
|
||||
embed { width:300px; height:200px; display:block; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<!-- Use a XUL element here so we can get its boxObject.screenX/Y -->
|
||||
<hbox style="height:10px; position:absolute; left:0; top:0; z-index:-100;" id="h1"
|
||||
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
|
||||
<hbox style="width:100px;"></hbox><hbox id="h2"/>
|
||||
</hbox>
|
||||
|
||||
<div id="d1" style="width:200px; overflow:hidden; position:absolute; top:0; left:0;">
|
||||
<embed id="p1" type="application/x-test" wmode="window" style="position:relative"></embed>
|
||||
</div>
|
||||
<div id="d2" style="width:200px; height:200px; overflow:hidden; position:absolute; top:100px; left:0;">
|
||||
<embed id="p2" type="application/x-test" wmode="window"></embed>
|
||||
<div id="zbox" style="position:absolute; left:50px; top:50px; width:100px; height:100px; background:yellow;">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="scroll"
|
||||
style="position:absolute; top:0; left:0; width:300px; height:400px; overflow:scroll;">
|
||||
<div id="sbox"
|
||||
style="margin-top:350px; margin-left:50px; margin-bottom:1000px; width:100px; height:100px; background:blue;"></div>
|
||||
</div>
|
||||
|
||||
<script src="plugin_clipping_lib.js"></script>
|
||||
<script class="testbody" type="application/javascript">
|
||||
<![CDATA[
|
||||
|
||||
function runTests() {
|
||||
var scroll = document.getElementById("scroll");
|
||||
var zbox = document.getElementById("zbox");
|
||||
var sbox = document.getElementById("sbox");
|
||||
var p1 = document.getElementById("p1");
|
||||
var d1 = document.getElementById("d1");
|
||||
var d2 = document.getElementById("d2");
|
||||
|
||||
checkClipRegion("p1", [[0, 0, 200, 100]]);
|
||||
checkClipRegion("p2", [[0, 0, 200, 50], [0, 50, 50, 150], [150, 50, 200, 150], [0, 150, 200, 200]]);
|
||||
|
||||
scroll.scrollTop = 150;
|
||||
checkClipRegion("p2", [[0, 0, 200, 50], [0, 50, 50, 200], [150, 50, 200, 200]]);
|
||||
|
||||
zbox.style.zIndex = -1;
|
||||
checkClipRegion("p2", [[0, 0, 200, 100], [0, 100, 50, 200], [150, 100, 200, 200]]);
|
||||
|
||||
sbox.style.background = "";
|
||||
checkClipRegion("p2", [[0, 0, 200, 200]]);
|
||||
|
||||
p1.style.zIndex = 1;
|
||||
checkClipRegion("p1", [[0, 0, 200, 200]]);
|
||||
checkClipRegion("p2", [[0, 100, 200, 200]]);
|
||||
|
||||
// Test subpixel stuff
|
||||
p1.style.zIndex = -1;
|
||||
zbox.style.zIndex = 1;
|
||||
zbox.style.top = "50.3px;"
|
||||
d2.style.top = "100.3px";
|
||||
checkClipRegionNoBounds("p2", [[0, 0, 200, 50], [0, 50, 50, 150], [150, 50, 200, 150], [0, 150, 200, 200]]);
|
||||
}
|
||||
|
||||
]]>
|
||||
</script>
|
||||
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,164 @@
|
|||
var checkClipRegion, checkClipRegionForFrame, checkClipRegionNoBounds;
|
||||
|
||||
(function() {
|
||||
var windowFrameX, windowFrameY;
|
||||
|
||||
// Import test API
|
||||
var is = window.opener.is;
|
||||
var ok = window.opener.ok;
|
||||
var todo = window.opener.todo;
|
||||
var finish = window.opener.SimpleTest.finish;
|
||||
window.onerror = function (event) { window.opener.onerror(event); window.close(); };
|
||||
|
||||
function dumpRect(r) {
|
||||
return "{" + r.join(",") + "}";
|
||||
}
|
||||
|
||||
function dumpRegion(rects) {
|
||||
var s = [];
|
||||
for (var i = 0; i < rects.length; ++i) {
|
||||
var r = rects[i];
|
||||
s.push(dumpRect(r));
|
||||
}
|
||||
return s.join(", ");
|
||||
}
|
||||
|
||||
function generateSpan(coords) {
|
||||
coords.sort(function(a,b) { return a - b; });
|
||||
var result = [coords[0]];
|
||||
for (var i = 1; i < coords.length; ++i) {
|
||||
if (coords[i] != coords[i - 1]) {
|
||||
result.push(coords[i]);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
function containsRect(r1, r2) {
|
||||
return r1[0] <= r2[0] && r1[2] >= r2[2] &&
|
||||
r1[1] <= r2[1] && r1[3] >= r2[3];
|
||||
}
|
||||
|
||||
function subtractRect(r1, r2, rlist) {
|
||||
var spanX = generateSpan([r1[0], r1[2], r2[0], r2[2]]);
|
||||
var spanY = generateSpan([r1[1], r1[3], r2[1], r2[3]]);
|
||||
for (var i = 1; i < spanX.length; ++i) {
|
||||
for (var j = 1; j < spanY.length; ++j) {
|
||||
var subrect = [spanX[i - 1], spanY[j - 1], spanX[i], spanY[j]];
|
||||
if (containsRect(r1, subrect) && !containsRect(r2, subrect)) {
|
||||
rlist.push(subrect);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function regionContainsRect(rs, r) {
|
||||
var rectList = [r];
|
||||
for (var i = 0; i < rs.length; ++i) {
|
||||
var newList = [];
|
||||
for (var j = 0; j < rectList.length; ++j) {
|
||||
subtractRect(rectList[j], rs[i], newList);
|
||||
}
|
||||
if (newList.length == 0)
|
||||
return true;
|
||||
rectList = newList;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function regionContains(r1s, r2s) {
|
||||
for (var i = 0; i < r2s.length; ++i) {
|
||||
if (!regionContainsRect(r1s, r2s[i]))
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
function equalRegions(r1s, r2s) {
|
||||
return regionContains(r1s, r2s) && regionContains(r2s, r1s);
|
||||
}
|
||||
|
||||
// Checks that a plugin's clip region equals the specified rectangle list.
|
||||
// The rectangles are given relative to the plugin's top-left. They are in
|
||||
// [left, top, right, bottom] format.
|
||||
function checkClipRegionWithDoc(doc, offsetX, offsetY, id, rects, checkBounds) {
|
||||
var p = doc.getElementById(id);
|
||||
var bounds = p.getBoundingClientRect();
|
||||
var pX = p.getEdge(0);
|
||||
var pY = p.getEdge(1);
|
||||
|
||||
if (checkBounds) {
|
||||
var pWidth = p.getEdge(2) - pX;
|
||||
var pHeight = p.getEdge(3) - pY;
|
||||
|
||||
is(pX, windowFrameX + bounds.left + offsetX, id + " plugin X");
|
||||
is(pY, windowFrameY + bounds.top + offsetY, id + " plugin Y");
|
||||
is(pWidth, bounds.width, id + " plugin width");
|
||||
is(pHeight, bounds.height, id + " plugin height");
|
||||
}
|
||||
|
||||
// Now check clip region. 'rects' is relative to the plugin's top-left.
|
||||
var clipRects = [];
|
||||
var n = p.getClipRegionRectCount();
|
||||
for (var i = 0; i < n; ++i) {
|
||||
// Convert the clip rect to be relative to the plugin's top-left.
|
||||
clipRects[i] = [
|
||||
p.getClipRegionRectEdge(i, 0) - pX,
|
||||
p.getClipRegionRectEdge(i, 1) - pY,
|
||||
p.getClipRegionRectEdge(i, 2) - pX,
|
||||
p.getClipRegionRectEdge(i, 3) - pY
|
||||
];
|
||||
}
|
||||
|
||||
ok(equalRegions(clipRects, rects), "Matching regions for '" + id +
|
||||
"': expected " + dumpRegion(rects) + ", got " + dumpRegion(clipRects));
|
||||
}
|
||||
|
||||
checkClipRegion = function checkClipRegion(id, rects) {
|
||||
checkClipRegionWithDoc(document, 0, 0, id, rects, true);
|
||||
}
|
||||
|
||||
checkClipRegionForFrame = function checkClipRegionForFrame(fid, id, rects) {
|
||||
var f = document.getElementById(fid);
|
||||
var bounds = f.getBoundingClientRect();
|
||||
checkClipRegionWithDoc(f.contentDocument, bounds.left, bounds.top, id, rects, true);
|
||||
}
|
||||
|
||||
checkClipRegionNoBounds = function checkClipRegionNoBounds(id, rects) {
|
||||
checkClipRegionWithDoc(document, 0, 0, id, rects, false);
|
||||
}
|
||||
|
||||
function loaded() {
|
||||
var h1 = document.getElementById("h1");
|
||||
var h2 = document.getElementById("h2");
|
||||
var hwidth = h2.boxObject.screenX - h1.boxObject.screenX;
|
||||
if (hwidth != 100) {
|
||||
// Maybe it's a DPI issue
|
||||
todo(false, "Unexpected DPI?");
|
||||
finish();
|
||||
window.close();
|
||||
return;
|
||||
}
|
||||
|
||||
if (!document.getElementById("p1").identifierToStringTest) {
|
||||
todo(false, "Test plugin not available");
|
||||
finish();
|
||||
window.close();
|
||||
return;
|
||||
}
|
||||
|
||||
var bounds = h1.getBoundingClientRect();
|
||||
windowFrameX = h1.boxObject.screenX - bounds.left - window.screenX;
|
||||
windowFrameY = h1.boxObject.screenY - bounds.top - window.screenY;
|
||||
|
||||
// Run actual test code
|
||||
runTests();
|
||||
|
||||
finish();
|
||||
window.close();
|
||||
}
|
||||
|
||||
// Need to run 'loaded' after painting is unsuppressed, or we'll set clip
|
||||
// regions to empty.
|
||||
window.addEventListener("load", function () { setTimeout(loaded, 0); }, false);
|
||||
})();
|
|
@ -10,11 +10,7 @@
|
|||
<script class="testbody" type="application/javascript">
|
||||
<![CDATA[
|
||||
|
||||
function runTests() {
|
||||
window.open("plugin_clipping_helper.xhtml", "", "width=620,height=320");
|
||||
}
|
||||
|
||||
addLoadEvent(runTests);
|
||||
window.open("plugin_clipping_helper.xhtml", "", "width=620,height=320");
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
|
||||
]]>
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
<?xml version="1.0"?>
|
||||
<?xml-stylesheet href="/tests/SimpleTest/test.css" type="text/css"?>
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" title="Test Plugin Clipping: Dynamic Tests">
|
||||
<head>
|
||||
<script type="application/javascript" src="/MochiKit/packed.js"></script>
|
||||
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<script class="testbody" type="application/javascript">
|
||||
<![CDATA[
|
||||
if (navigator.platform.indexOf("Mac") == 0) {
|
||||
todo(false, "Mac plugins do not support complex clipping");
|
||||
} else {
|
||||
window.open("plugin_clipping_helper2.xhtml", "", "width=620,height=320");
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
}
|
||||
]]>
|
||||
</script>
|
||||
|
||||
</body>
|
||||
</html>
|
Загрузка…
Ссылка в новой задаче