Skip to content

Commit

Permalink
tweaks tests (#366)
Browse files Browse the repository at this point in the history
  • Loading branch information
Thorin-Oakenpants authored Nov 29, 2024
1 parent 341e86a commit d63b44a
Show file tree
Hide file tree
Showing 13 changed files with 903 additions and 1,044 deletions.
2 changes: 1 addition & 1 deletion tests/applang.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
</head>

<body>
<div class="appfixed normalized"><div class="appbigger measureScale" id="elementsdiv"></div></div>
<div class="appfixed normalized"><div class="appbigger skew" id="elementsdiv"></div></div>
<!-- offscreen -->
<div class="offscreen">
<div>
Expand Down
206 changes: 39 additions & 167 deletions tests/domrectspoof.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,61 +2,59 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=500">
<title>domrect spoof detection</title>
<meta name="viewport" content="width=800">
<title>domrect spoof aspect ratio</title>
<link rel="stylesheet" type="text/css" href="testindex.css">
<script src="testglobals.js"></script>
<script src="testgeneric.js"></script>
<style>
table {width: 480px;}
#rectTest {
table {width: 780px;}
#tzpRect {
background-color: #545aa7;
top: 0;
left: 0;
width:100px;
height:100px;
transform: rotate(45deg);
/* scaleX, scaleY, skewX, skewY, translateX, translateY */
transform: matrix(.3333, 1.6666, 1, 1, 100, 100);
padding: 0px;
opacity: 0.5;
z-index: -20;
position: fixed; /* must be fixed */
position: fixed;
}
</style>
</head>

<body>
<div id="rectTest"></div>
<div id="tzpRect"></div>

<table>
<tr><td><h2>TorZillaPrint</h2></td></tr>
<tr><td class="blurb"><a class="return" href="../index.html#elements">return to TZP index</a></td></tr>
</table>

<table id="tb15">
<col width="13%"><col width="12%"><col width="25%"><col width="50%">
<thead><tr><th colspan="4">
<div class="nav-title">domrect spoof detection
<col width="1%"><col width="29%"><col width="70%">
<thead><tr><th colspan="3">
<div class="nav-title">domrect spoof detection: aspect ratio
<div class="nav-up"><span class="c perf" id="perf"></span></div>
</div>
</th></tr></thead>
<tr><td colspan="4" class="intro">
<span class="no_color">Measures a fixed element, rotated to forced decimal precision. On gecko
this is an expected known result at any zoom level (try it: it auto-runs on resize) and on any platform.
<tr><td colspan="3" class="intro">
<span class="no_color">Measures a fixed element, transformed to forced decimal precision with
a known aspect ratio to check if width or height have been tampered with.
</span>
</td></tr>
<tr><td colspan="4"><hr></td></tr>
<tr><td colspan="2" class="padr">expected gecko</td><td colspan="2" class="mono spaces" id="expected"></td></tr>
<tr><td colspan="4"></td></tr>
<tr><td colspan="3"><hr></td></tr>

<tr><td colspan="4"><hr></td></tr>
<tr><td colspan="3" class="padr">Element.getBoundingClientRect</td><td class="mono" id="res0"></td></tr>
<tr><td colspan="3" class="padr">Element.getClientRects</td><td class="mono" id="res1"></td></tr>
<tr><td colspan="3" class="padr">range.getBoundingClientRect</td><td class="mono" id="res2"></td></tr>
<tr><td colspan="3" class="padr">range.getClientRects</td><td class="mono" id="res3"></td></tr>
<tr><td colspan="4"></td></tr>
<tr><td colspan="2" class="padr">Element.getBoundingClientRect</td><td class="mono" id="res0"></td></tr>
<tr><td colspan="2" class="padr">Element.getClientRects</td><td class="mono" id="res1"></td></tr>
<tr><td colspan="2" class="padr">range.getBoundingClientRect</td><td class="mono" id="res2"></td></tr>
<tr><td colspan="2" class="padr">range.getClientRects</td><td class="mono" id="res3"></td></tr>
<tr><td colspan="3"></td></tr>

<tr><td colspan="4"><hr></td></tr>
<tr><td>history</td><td colspan="3" class="mono spaces" id="history"></td></tr>
<tr><td colspan="3"><hr></td></tr>
<tr><td>history</td><td colspan="2" class="mono spaces" id="history"></td></tr>

</table>
<br>
Expand All @@ -65,31 +63,21 @@
'use strict';

let aHistory = []
let valid = "4447a487",
valid1 = "f39a5bc7",
valid2 = "dd03a1b3"
let expected = [
s12 +" one: "+ sc + valid1,
" x, left, y, top: -20.716659545898438",
s12 +" two: "+ sc + valid2,
" width, height: 141.41665649414062",
" right, bottom: 120.69999694824219",
s12 +"full: "+ sc + valid,
]
let count = 0
dom.expected.innerHTML = expected.join("<br>")

let sNames = ["Element.getBoundingClientRect", "Element.getClientRects",
"Range.getBoundingClientRect", "Range.getClientRects"]

let oBlinkNew = {}
let knownBlink = [
// standard
0.5, 0.4999999427781113, 0.5000000572218888,
// when page is scrolled so no longer top left = 0
0.4999999427781178,
0.4999998855562356,
]

function get_rect() {
if (aHistory.length > 19) {aHistory = aHistory.slice(-19)}
// clear details
sNames.forEach(function(name) {sDetail[name] = []})

let el = dom.rectTest
let el = dom.tzpRect
let res = []
for (let i=0; i < 4; i++) {
let output = document.getElementById("res"+i)
Expand All @@ -109,39 +97,18 @@
obj = range.getClientRects()[0]
}
}
// 3 unique values, but cover all names
let array1 = [obj.x, obj.left, obj.y, obj.top]
let array2 = [obj.width, obj.height, obj.right, obj.bottom]
let array = array1.concat(array2)

let hash = mini(array.join())
let hash1 = mini(array1.join())
let hash2 = mini(array2.join())

if (isEngine == "blink") {
if (!knownBlink.includes(hash)) {
if (oBlinkNew[hash] == undefined) {oBlinkNew[hash] = array}
}
let array = [obj.width, obj.height, (obj.width / obj.height)]
let display = array.join(" | ")
let mark = ""
if (isFF) {
mark = array[2] == 0.5000000572204611 ? green_tick : red_cross
} else if (isEngine == "blink") {
mark = knownBlink.includes(array[2]) ? green_tick : red_cross
}
output.innerHTML = display + mark

// part 1
let display = hash1
if (isFF) {display += (hash1 == valid1 ? green_tick : red_cross)}
// part 2
display += " | " + hash2
if (isFF) {display += (hash2 == valid2 ? green_tick : red_cross)}
res.push(array[2] + mark)

// always display details clickable unless known full gecko
if (hash !== valid) {
sDetail[sNames[i]] = array
display += buildButton("15", sNames[i] +", true", "details")
}
output.innerHTML = display
if (isFF) {
res.push(hash + (mini(array.join()) == valid ? green_tick : red_cross))
} else {
res.push(hash)
}
} catch(e) {
output.innerHTML = e.name
res.push(zErr)
Expand All @@ -155,101 +122,6 @@
dom.history.innerHTML = aHistory.join("<br>")
}

function outputBlink() {
if (isEngine !== "blink") { return }
if (Object.keys(oBlinkNew).length) {
for (const hash of Object.keys(oBlinkNew)) {
console.log(hash, oBlinkNew[hash])
}
}
}

let knownBlink = []
let oBlinkSamples = {
// windows dpr=1, dpi=1
// all zoom levels, default positions
"2cd8d217": [-20.71068000793457, -20.71068000793457, -20.71068000793457, -20.71068000793457, 141.42135620117188, 141.42135620117188, 120.7106761932373, 120.7106761932373],
"3fcff5df": [-20.710678100585938, -20.710678100585938, -20.710678100585938, -20.710678100585938, 141.42137145996094, 141.42137145996094, 120.710693359375, 120.710693359375],
"5f81a4df": [-20.710678100585938, -20.710678100585938, -20.710678100585938, -20.710678100585938, 141.42135620117188, 141.42135620117188, 120.71067810058594, 120.71067810058594],
"29e0447b": [-20.707441329956055, -20.707441329956055, -20.707441329956055, -20.707441329956055, 141.39926147460938, 141.39926147460938, 120.69182014465332, 120.69182014465332],
"820458b3": [-20.71068000793457, -20.71068000793457, -20.71068000793457, -20.71068000793457, 141.42137145996094, 141.42137145996094, 120.71069145202637, 120.71069145202637],
// zoom 500
"10d1949f": [-20.710681915283203, -20.710681915283203, -20.710681915283203, -20.710681915283203, 141.42137145996094, 141.42137145996094, 120.71068954467773, 120.71068954467773],
"c3ec468d": [-20.710668563842773, -20.710668563842773, -20.710668563842773, -20.710668563842773, 141.42135620117188, 141.42135620117188, 120.7106876373291, 120.7106876373291],
"2d2f0e42": [-20.710668563842773, -20.710668563842773, -20.710668563842773, -20.710668563842773, 141.42137145996094, 141.42135620117188, 120.71068954467773, 120.7106876373291],
// 400 + 200
"1de05d90": [-20.710693359375, -20.710693359375, -20.710678100585938, -20.710678100585938, 141.42137145996094, 141.42135620117188, 120.71067810058594, 120.71067810058594],
// 300
"db71bd4a": [-20.710674285888672, -20.710674285888672, -20.710683822631836, -20.710683822631836, 141.42135620117188, 141.42135620117188, 120.7106819152832, 120.71067237854004],
"baf82439": [-20.710674285888672, -20.710674285888672, -20.710678100585938, -20.710678100585938, 141.42135620117188, 141.42137145996094, 120.7106819152832, 120.710693359375],
"efce3af9": [-20.710674285888672, -20.710674285888672, -20.710678100585938, -20.710678100585938, 141.42135620117188, 141.42135620117188, 120.7106819152832, 120.71067810058594],
"6a972f1e": [-20.710678100585938, -20.710678100585938, -20.710683822631836, -20.710683822631836, 141.42137145996094, 141.42135620117188, 120.710693359375, 120.71067237854004],
"243cc010": [-20.710678100585938, -20.710678100585938, -20.710683822631836, -20.710683822631836, 141.42135620117188, 141.42135620117188, 120.71067810058594, 120.71067237854004],
// 250 + 125
"61b13db7": [-20.710681915283203, -20.710681915283203, -20.710678100585938, -20.710678100585938, 141.42137145996094, 141.42135620117188, 120.71068954467773, 120.71067810058594],
"a699afe9": [-20.710681915283203, -20.710681915283203, -20.710678100585938, -20.710678100585938, 141.42137145996094, 141.42137145996094, 120.71068954467773, 120.710693359375],
// 175
"83d6e13b": [-20.710676193237305, -20.710676193237305, -20.710678100585938, -20.710678100585938, 141.42135620117188, 141.42135620117188, 120.71068000793457, 120.71067810058594],
"2ec16097": [-20.710676193237305, -20.710676193237305, -20.710676193237305, -20.710676193237305, 141.42135620117188, 141.42135620117188, 120.71068000793457, 120.71068000793457],
// 150
"3710b115": [-20.710678100585938, -20.710678100585938, -20.710681915283203, -20.710681915283203, 141.42135620117188, 141.42135620117188, 120.71067810058594, 120.71067428588867],
// 125
"9b7056e0": [-20.710683822631836, -20.710683822631836, -20.710678100585938, -20.710678100585938, 141.42135620117188, 141.42137145996094, 120.71067237854004, 120.710693359375],
"7b7a02ee": [-20.710683822631836, -20.710683822631836, -20.710678100585938, -20.710678100585938, 141.42135620117188, 141.42135620117188, 120.71067237854004, 120.71067810058594],
// 110
"41da0d9e": [-20.710683822631836, -20.710683822631836, -20.710670471191406, -20.710670471191406, 141.42135620117188, 141.4213409423828, 120.71067237854004, 120.7106704711914],
"9395cf12": [-20.710678100585938, -20.710678100585938, -20.710670471191406, -20.710670471191406, 141.4213409423828, 141.4213409423828, 120.71066284179688, 120.7106704711914],
"588e14ad": [-20.710678100585938, -20.710678100585938, -20.710670471191406, -20.710670471191406, 141.42135620117188, 141.4213409423828, 120.71067810058594, 120.7106704711914],
"2033442d": [-20.710678100585938, -20.710678100585938, -20.710670471191406, -20.710670471191406, 141.42137145996094, 141.4213409423828, 120.710693359375, 120.7106704711914],
"ab629b83": [-20.710678100585938, -20.710678100585938, -20.710670471191406, -20.710670471191406, 141.42137145996094, 141.42135620117188, 120.710693359375, 120.71068572998047],
"bbe63d75": [-20.710678100585938, -20.710678100585938, -20.710670471191406, -20.710670471191406, 141.42135620117188, 141.42135620117188, 120.71067810058594, 120.71068572998047],
// 100
"d468b282": [-20.710678100585938, -20.710678100585938, -20.710693359375, -20.710693359375, 141.42135620117188, 141.42137145996094, 120.71067810058594, 120.71067810058594],
// 90
"1067b86e": [-20.71068000793457, -20.71068000793457, -20.7106876373291, -20.7106876373291, 141.42135620117188, 141.42137145996094, 120.7106761932373, 120.71068382263184],
"af2cc7d9": [-20.71068000793457, -20.71068000793457, -20.7106876373291, -20.7106876373291, 141.42137145996094, 141.42137145996094, 120.71069145202637, 120.71068382263184],
// 75
"6403ea2f": [-20.710678100585938, -20.710678100585938, -20.710674285888672, -20.710674285888672, 141.42137145996094, 141.42135620117188, 120.710693359375, 120.7106819152832],
"d9c4977d": [-20.710678100585938, -20.710678100585938, -20.710674285888672, -20.710674285888672, 141.42135620117188, 141.42135620117188, 120.71067810058594, 120.7106819152832],
"0a1577ed": [-20.710678100585938, -20.710678100585938, -20.710678100585938, -20.710678100585938, 141.42137145996094, 141.42135620117188, 120.710693359375, 120.71067810058594],
// 67
"518c2bea": [-20.707441329956055, -20.707441329956055, -20.707443237304688, -20.707443237304688, 141.39926147460938, 141.39926147460938, 120.69182014465332, 120.69181823730469],
// other?
"11882a7d"[-20.710678100585938, -20.710678100585938, -20.710693359375, -20.710693359375, 141.42135620117188, 141.42138671875, 120.71067810058594, 120.710693359375],

}
for (const hash of Object.keys(oBlinkSamples)) {
knownBlink.push(hash)
}

function testBlink() {
for (const hash of Object.keys(oBlinkSamples)) {
let array = oBlinkSamples[hash]
if (mini(array.join()) !== hash) {console.log(hash, "hash mismatch")}

let x = array[0], left = array[1]
let y = array[2], top = array[3]
let width = array[4], height = array[5]
let right = array[6], bottom = array[7]
let aLies = []
if (x !== left) {
aLies.push(["x !== left", x, left].join(", "))
}
if (y !== top) {
aLies.push(["y !== top", y, top].join(", "))
}
if (right - x !== width) {
aLies.push(["right - x !== width", right, x, "expected "+ width, "got "+ (right - x), "diff "+ ((right - x) - width)].join(", "))
}
if (bottom - y !== height) {
aLies.push(["bottom - y !== height", bottom, y, "expected "+ height, "got "+ (bottom - y), "diff "+ ((bottom - y) - height)].join(", "))
}
if (aLies.length) {
console.log(hash +"\n - "+ aLies.join("\n - "))
}
}
}

Promise.all([
get_globals()
]).then(function(){
Expand Down
Loading

0 comments on commit d63b44a

Please sign in to comment.