Nothing Special »
Address
:
[go:
up one dir
,
main page
]
Include Form
Remove Scripts
Accept Cookies
Show Images
Show Referer
Rotate13
Base64
Strip Meta
Strip Title
Session Cookies
Bugzilla
Quick Search
Browse
Advanced Search
Reports
Quick Search Help
Documentation
New Account
Log In
Login with GitHub
Remember
Forgot Password
Mozilla Home
Privacy
Cookies
Legal
Attachment 8356418 Details for
Bug 918189
[patch]
Part 2: Add tests for convertPoint/Rect/QuadFromNode
918189-convert-tests (text/plain), 15.71 KB, created by
Robert O'Callahan (:roc) (email my personal email if necessary)
(
hide
)
Description:
Part 2: Add tests for convertPoint/Rect/QuadFromNode
Filename:
MIME Type:
Creator:
Robert O'Callahan (:roc) (email my personal email if necessary)
Size:
15.71 KB
patch
obsolete
># HG changeset patch ># User Robert O'Callahan <robert@ocallahan.org> ># Date 1379672531 -43200 ># Node ID 873e5463e4a8531527eb3a7bdb1052400828ec15 ># Parent b0ec8232b89ccebe935c1af79412edc7f3f2b1be >Bug 918189. Part 2: Add tests for convertPoint/Rect/QuadFromNode. r=mats > >diff --git a/layout/base/tests/test_getBoxQuads_convertPointRectQuad.html b/layout/base/tests/test_getBoxQuads_convertPointRectQuad.html >--- a/layout/base/tests/test_getBoxQuads_convertPointRectQuad.html >+++ b/layout/base/tests/test_getBoxQuads_convertPointRectQuad.html >@@ -7,16 +7,22 @@ > </head> > <body > <p id="display"></p> > <script> > // Global variables we want eval() to be able to reference from anywhere > var f1d; > var text; > var suppressedText; >+var suppressedText2; >+var comment; >+var openedWindow; >+var zeroPoint = new DOMPoint(0,0); >+var zeroRect = new DOMRect(0,0,0,0); >+var zeroQuad = new DOMQuad(zeroRect); > var notInDocument = document.createElement('div'); > > function isEval(expr, b) { > is(eval(expr), b, expr); > } > > function isApprox(a, b, msg, options) { > if (a != b && 'tolerance' in options && >@@ -33,16 +39,115 @@ function makeQuadsExpr(fromStr, options) > getBoxQuadsOptionParts.push("box:'" + options.box + "'"); > } > if ('toStr' in options) { > getBoxQuadsOptionParts.push("relativeTo:" + options.toStr); > } > return fromStr + ".getBoxQuads({" + getBoxQuadsOptionParts.join(',') + "})"; > } > >+function makePointExpr(fromStr, options, x, y) { >+ var convertPointOptionParts = []; >+ if ('box' in options) { >+ convertPointOptionParts.push("fromBox:'" + options.box + "'"); >+ } >+ if ('toBox' in options) { >+ convertPointOptionParts.push("toBox:'" + options.toBox + "'"); >+ } >+ return ('toStr' in options ? options.toStr : "document") + >+ ".convertPointFromNode(new DOMPoint(" + x + "," + y + ")," + fromStr + ",{" + >+ convertPointOptionParts.join(",") + "})"; >+} >+ >+function checkConvertPoints(fromStr, options, x1, y1, x2, y2, x3, y3, x4, y4) { >+ var selfQuads = eval(fromStr).getBoxQuads( >+ {box:options.box == "" ? "border" : options.box, >+ relativeTo:eval(fromStr)}); >+ var boxWidth = selfQuads[0].bounds.width; >+ var boxHeight = selfQuads[0].bounds.height; >+ >+ var convertTopLeftPointExpr = makePointExpr(fromStr, options, 0, 0); >+ var topLeft = eval(convertTopLeftPointExpr); >+ isApprox(topLeft.x, x1, convertTopLeftPointExpr + ".x", options); >+ isApprox(topLeft.y, y1, convertTopLeftPointExpr + ".y", options); >+ >+ var convertTopRightPointExpr = makePointExpr(fromStr, options, boxWidth, 0); >+ var topRight = eval(convertTopRightPointExpr); >+ isApprox(topRight.x, x2, convertTopRightPointExpr + ".x", options); >+ isApprox(topRight.y, y2, convertTopRightPointExpr + ".y", options); >+ >+ var convertBottomRightPointExpr = makePointExpr(fromStr, options, boxWidth, boxHeight); >+ var bottomRight = eval(convertBottomRightPointExpr); >+ isApprox(bottomRight.x, x3, convertBottomRightPointExpr + ".x", options); >+ isApprox(bottomRight.y, y3, convertBottomRightPointExpr + ".y", options); >+ >+ var convertBottomLeftPointExpr = makePointExpr(fromStr, options, 0, boxHeight); >+ var bottomLeft = eval(convertBottomLeftPointExpr); >+ isApprox(bottomLeft.x, x4, convertBottomLeftPointExpr + ".x", options); >+ isApprox(bottomLeft.y, y4, convertBottomLeftPointExpr + ".y", options); >+} >+ >+function checkConvertRect(fromStr, options, x1, y1, x2, y2, x3, y3, x4, y4) { >+ var selfQuads = eval(fromStr).getBoxQuads( >+ {box:options.box == "" ? "border" : options.box, >+ relativeTo:eval(fromStr)}); >+ var boxWidth = selfQuads[0].bounds.width; >+ var boxHeight = selfQuads[0].bounds.height; >+ >+ var convertPointOptionParts = []; >+ if ('box' in options) { >+ convertPointOptionParts.push("fromBox:'" + options.box + "'"); >+ } >+ if ('toBox' in options) { >+ convertPointOptionParts.push("toBox:'" + options.toBox + "'"); >+ } >+ >+ var convertRectExpr = ('toStr' in options ? options.toStr : "document") + >+ ".convertRectFromNode(new DOMRect(0,0," + boxWidth + "," + boxHeight + ")," + >+ fromStr + ",{" + convertPointOptionParts.join(",") + "})"; >+ var quad = eval(convertRectExpr); >+ isApprox(quad.p1.x, x1, convertRectExpr + ".p1.x", options); >+ isApprox(quad.p1.y, y1, convertRectExpr + ".p1.y", options); >+ isApprox(quad.p2.x, x2, convertRectExpr + ".p2.x", options); >+ isApprox(quad.p2.y, y2, convertRectExpr + ".p2.y", options); >+ isApprox(quad.p3.x, x3, convertRectExpr + ".p3.x", options); >+ isApprox(quad.p3.y, y3, convertRectExpr + ".p3.y", options); >+ isApprox(quad.p4.x, x4, convertRectExpr + ".p4.x", options); >+ isApprox(quad.p4.y, y4, convertRectExpr + ".p4.y", options); >+} >+ >+function checkConvertQuad(fromStr, options, x1, y1, x2, y2, x3, y3, x4, y4) { >+ var selfQuads = eval(fromStr).getBoxQuads( >+ {box:options.box == "" ? "border" : options.box, >+ relativeTo:eval(fromStr)}); >+ var boxWidth = selfQuads[0].bounds.width; >+ var boxHeight = selfQuads[0].bounds.height; >+ >+ var convertPointOptionParts = []; >+ if ('box' in options) { >+ convertPointOptionParts.push("fromBox:'" + options.box + "'"); >+ } >+ if ('toBox' in options) { >+ convertPointOptionParts.push("toBox:'" + options.toBox + "'"); >+ } >+ >+ var convertQuadExpr = ('toStr' in options ? options.toStr : "document") + >+ ".convertQuadFromNode(new DOMQuad(new DOMRect(0,0," + boxWidth + "," + boxHeight + "))," + >+ fromStr + ",{" + convertPointOptionParts.join(",") + "})"; >+ var quad = eval(convertQuadExpr); >+ isApprox(quad.p1.x, x1, convertQuadExpr + ".p1.x", options); >+ isApprox(quad.p1.y, y1, convertQuadExpr + ".p1.y", options); >+ isApprox(quad.p2.x, x2, convertQuadExpr + ".p2.x", options); >+ isApprox(quad.p2.y, y2, convertQuadExpr + ".p2.y", options); >+ isApprox(quad.p3.x, x3, convertQuadExpr + ".p3.x", options); >+ isApprox(quad.p3.y, y3, convertQuadExpr + ".p3.y", options); >+ isApprox(quad.p4.x, x4, convertQuadExpr + ".p4.x", options); >+ isApprox(quad.p4.y, y4, convertQuadExpr + ".p4.y", options); >+} >+ > function checkQuadIsRect(fromStr, options, x, y, w, h) { > var quadsExpr = makeQuadsExpr(fromStr, options); > var quads = eval(quadsExpr); > is(quads.length, 1, quadsExpr + " checking quad count"); > var q = quads[0]; > isApprox(q.p1.x, x, quadsExpr + " checking quad.p1.x", options); > isApprox(q.p1.y, y, quadsExpr + " checking quad.p1.y", options); > isApprox(q.p2.x, x + w, quadsExpr + " checking quad.p2.x", options); >@@ -51,16 +156,20 @@ function checkQuadIsRect(fromStr, option > isApprox(q.p3.y, y + h, quadsExpr + " checking quad.p3.y", options); > isApprox(q.p4.x, x, quadsExpr + " checking quad.p4.x", options); > isApprox(q.p4.y, y + h, quadsExpr + " checking quad.p4.y", options); > > isApprox(q.bounds.left, x, quadsExpr + " checking quad.bounds.left", options); > isApprox(q.bounds.top, y, quadsExpr + " checking quad.bounds.top", options); > isApprox(q.bounds.width, w, quadsExpr + " checking quad.bounds.width", options); > isApprox(q.bounds.height, h, quadsExpr + " checking quad.bounds.height", options); >+ >+ checkConvertPoints(fromStr, options, x, y, x + w, y, x + w, y + h, x, y + h); >+ checkConvertRect(fromStr, options, x, y, x + w, y, x + w, y + h, x, y + h); >+ checkConvertQuad(fromStr, options, x, y, x + w, y, x + w, y + h, x, y + h); > } > > function checkQuadIsQuad(fromStr, options, x1, y1, x2, y2, x3, y3, x4, y4) { > var quadsExpr = makeQuadsExpr(fromStr, options); > var quads = eval(quadsExpr); > is(quads.length, 1, quadsExpr + " checking quad count"); > var q = quads[0]; > isApprox(q.p1.x, x1, quadsExpr + " checking quad.p1.x", options); >@@ -71,16 +180,43 @@ function checkQuadIsQuad(fromStr, option > isApprox(q.p3.y, y3, quadsExpr + " checking quad.p3.y", options); > isApprox(q.p4.x, x4, quadsExpr + " checking quad.p4.x", options); > isApprox(q.p4.y, y4, quadsExpr + " checking quad.p4.y", options); > > isApprox(q.bounds.left, Math.min(x1,x2,x3,x4), quadsExpr + " checking quad.bounds.left", options); > isApprox(q.bounds.top, Math.min(y1,y2,y3,y4), quadsExpr + " checking quad.bounds.top", options); > isApprox(q.bounds.right, Math.max(x1,x2,x3,x4), quadsExpr + " checking quad.bounds.right", options); > isApprox(q.bounds.bottom, Math.max(y1,y2,y3,y4), quadsExpr + " checking quad.bounds.bottom", options); >+ >+ checkConvertPoints(fromStr, options, x1, y1, x2, y2, x3, y3, x4, y4); >+ checkConvertRect(fromStr, options, x1, y1, x2, y2, x3, y3, x4, y4); >+ checkConvertQuad(fromStr, options, x1, y1, x2, y2, x3, y3, x4, y4); >+} >+ >+function checkException(expr, name) { >+ try { >+ eval(expr); >+ ok(false, "Exception should have been thrown for " + expr); >+ } catch (ex) { >+ is(ex.name, name, "Checking exception type for " + expr); >+ } >+} >+ >+function checkNotFound(fromStr, toStr, x1, y1, x2, y2) { >+ var convertPointExpr = toStr + ".convertPointFromNode(new DOMPoint(" + x1 + >+ "," + y1 + ")," + fromStr + ")"; >+ checkException(convertPointExpr, "NotFoundError"); >+ >+ var convertRectExpr = toStr + ".convertRectFromNode(new DOMRect(" + x1 + >+ "," + y1 + "," + x2 + "," + y2 + ")," + fromStr + ")"; >+ checkException(convertRectExpr, "NotFoundError"); >+ >+ var convertQuadExpr = toStr + ".convertQuadFromNode(new DOMQuad(new DOMRect(" + x1 + >+ "," + y1 + "," + x2 + "," + y2 + "))," + fromStr + ")"; >+ checkException(convertQuadExpr, "NotFoundError"); > } > </script> > <style> > em { > display:inline-block; height:10px; background:gray; > } > </style> > <div id="dContainer" >@@ -131,16 +267,17 @@ That ensures the first quad's X position > > <div style="width:200px; border:2px solid black;" > ><em style="width:150px;"></em > ><span id="textContainer">T > TextTextTextTextTextTextTextTextTextTextTextTextTextTextTextTextTextTextTextTextTextTextTextText</span > ></div> > > <div id="suppressedTextContainer"> </div> >+<div id="suppressedTextContainer2"> </div> > > <div id="commentContainer"><!-- COMMENT --></div> > > <div id="displayNone" style="display:none"></div> > > <div id="overflowHidden" > style="overflow:hidden; width:120px; height:90px; padding:1px 2px 3px 4px; > border-width:5px 6px 7px 8px; border-style:solid; border-color:yellow; >@@ -220,16 +357,18 @@ function startTest() { > ["layout.css.convertFromNode.enabled", true]]}, runTest); > } > > function runTest() { > // Setup globals > f1d = f1.contentWindow.f1d; > text = textContainer.firstChild; > suppressedText = suppressedTextContainer.firstChild; >+ suppressedText2 = suppressedTextContainer2.firstChild; >+ comment = commentContainer.firstChild; > > // Test basic BoxQuadOptions.box. > var dX = d.getBoundingClientRect().left; > var dY = d.getBoundingClientRect().top; > var dW = d.getBoundingClientRect().width; > var dH = d.getBoundingClientRect().height; > > checkQuadIsRect("d", {box:"content"}, >@@ -287,16 +426,18 @@ function runTest() { > > // Test that we skip anonymous boxes when finding the right box to be relative to. > checkQuadIsRect("d", {toStr:"ibSplit"}, > dX - ibSplitPart1X, dY - ibSplitY, dW, dH); > var tableX = table.getClientRects()[0].left; > var tableY = table.getClientRects()[0].top; > checkQuadIsRect("d", {toStr:"table"}, > dX - tableX, dY - tableY, dW, dH); >+ isEval("ibSplit.convertPointFromNode(zeroPoint,d).x", dX - ibSplitPart1X); >+ isEval("table.convertPointFromNode(zeroPoint,d).x", dX - table.getClientRects()[0].left); > > // Test boxes generated by block splitting. Check for borders being placed correctly. > var colSplitY = colSplit.getClientRects()[0].top; > isEval("colSplit.getBoxQuads().length", 2); > isEval("colSplit.getBoxQuads()[0].bounds.top", colSplitY); > isEval("colSplit.getBoxQuads()[0].bounds.height", 60); > isEval("colSplit.getBoxQuads()[1].bounds.top", colSplitY - 20); > isEval("colSplit.getBoxQuads()[1].bounds.height", 45); >@@ -336,35 +477,35 @@ function runTest() { > isEval("text.getBoxQuads({box:'margin'})[1].bounds.left", textX - 150); > > // Check that a text node whose layout might have been optimized away gives > // correct results. > var suppressedTextContainerX = suppressedTextContainer.getBoundingClientRect().left; > isEval("suppressedText.getBoxQuads().length", 1); > isEval("suppressedText.getBoxQuads()[0].bounds.left", suppressedTextContainerX); > isEval("suppressedText.getBoxQuads()[0].bounds.width", 0); >+ var suppressedTextContainer2X = suppressedTextContainer2.getBoundingClientRect().left; >+ isEval("document.convertPointFromNode(zeroPoint,suppressedText2).x", >+ suppressedTextContainer2X); > >- var comment = commentContainer.firstChild; >- try { >- comment.getBoxQuads(); >- ok(false, "Exception should have been thrown"); >- } catch (ex) { >- is(ex.name, "TypeError", >- "Exception for comment.getBoxQuads()"); >- } >- try { >- d.getBoxQuads({relativeTo:comment}); >- ok(false, "Exception should have been thrown"); >- } catch (ex) { >- is(ex.name, "TypeError", >- "Exception for getBoxQuads({relativeTo:comment})"); >- } >+ checkException("comment.getBoxQuads()", "TypeError"); >+ checkException("d.getBoxQuads({relativeTo:comment})", "TypeError"); >+ checkException("comment.convertPointFromNode(zeroPoint,document)", "TypeError"); >+ checkException("document.convertPointFromNode(zeroPoint,comment)", "TypeError"); >+ checkException("comment.convertRectFromNode(zeroRect,document)", "TypeError"); >+ checkException("document.convertRectFromNode(zeroRect,comment)", "TypeError"); >+ checkException("comment.convertQuadFromNode(zeroQuad,document)", "TypeError"); >+ checkException("document.convertQuadFromNode(zeroQuad,comment)", "TypeError"); > > isEval("displayNone.getBoxQuads().length", 0); > isEval("notInDocument.getBoxQuads().length", 0); >+ checkNotFound("displayNone", "document", 1, 2, 3, 4); >+ checkNotFound("notInDocument", "document", 1, 2, 3, 4); >+ checkNotFound("document", "displayNone", 1, 2, 3, 4); >+ checkNotFound("document", "notInDocument", 1, 2, 3, 4); > > // Test an overflow:hidden version of d. overflow:hidden should not affect > // the quads, basically. > var oHX = overflowHidden.getBoundingClientRect().left; > var oHY = overflowHidden.getBoundingClientRect().top; > checkQuadIsRect("overflowHidden", {box:"content"}, > oHX + 4 + 8, oHY + 1 + 5, 120, 90); > checkQuadIsRect("overflowHidden", {box:"padding"}, >@@ -486,25 +627,26 @@ function runTest() { > // Test foreignObject inside an SVG transform. > checkQuadIsRect("foreign", {}, > svgContainerX + 100, svgContainerY + 40, 200, 120); > > // XXX Test SVG text (probably broken; unclear what the best way is to handle it) > > // Test that converting between nodes in different toplevel browsing contexts > // throws an exception. >- var openedWindow = window.open("data:text/html,<div id='d'>",""); >+ openedWindow = window.open("data:text/html,<div id='d'>",""); > openedWindow.addEventListener("load", function() { >- try { >- openedWindow.d.getBoxQuads({relativeTo:document}); >- ok(false, "Exception should have been thrown"); >- } catch (ex) { >- is(ex.name, "NotFoundError", >- "Exception for getBoxQuads on nodes in different toplevel browsing contexts"); >- } >+ checkException("openedWindow.d.getBoxQuads({relativeTo:document})", "NotFoundError"); >+ checkException("document.getBoxQuads({relativeTo:openedWindow.d})", "NotFoundError"); >+ checkException("openedWindow.d.convertPointFromNode(zeroPoint,document)", "NotFoundError"); >+ checkException("document.convertPointFromNode(zeroPoint,openedWindow.d)", "NotFoundError"); >+ checkException("openedWindow.d.convertRectFromNode(zeroRect,document)", "NotFoundError"); >+ checkException("document.convertRectFromNode(zeroRect,openedWindow.d)", "NotFoundError"); >+ checkException("openedWindow.d.convertQuadFromNode(zeroQuad,document)", "NotFoundError"); >+ checkException("document.convertQuadFromNode(zeroQuad,openedWindow.d)", "NotFoundError"); > openedWindow.close(); > > SimpleTest.finish(); > }); > } > </script> > </body> > </html>
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
Flags:
MatsPalmgren_bugz
: review+
Actions:
View
|
Diff
|
Review
Attachments on
bug 918189
:
807614
|
807615
|
807616
|
807617
|
8356417
| 8356418 |
8388511
|
8388513
|
8389634