Skip to content

Commit d2e5138

Browse files
authored
Expand element hiding privacy test page (#130)
* add csp * expand element hiding tests to cover improved heuristics
1 parent e5f66be commit d2e5138

File tree

2 files changed

+44
-6
lines changed

2 files changed

+44
-6
lines changed

features/element-hiding/index.html

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
.container {
1010
width: 400px;
1111
height: 200px;
12+
display: block;
1213
background-color: rgb(249, 251, 251);
1314
color: rgb(88, 104, 113);
1415
font-size: 16px;
@@ -76,6 +77,27 @@
7677
<iframe scrolling="no" width="400" height="200" src="about:blank" id="hide-empty-about-blank-frame" style="border: none; overflow: hidden; display: block;">
7778
</iframe>
7879
</div>
80+
<div class="container hide-empty-test" id="hide-empty-img-element">
81+
<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==" width='25' height='25'/>
82+
</div>
83+
<div class="container hide-empty-test" id="hide-empty-svg-element">
84+
<svg>
85+
<circle cx="50" cy="50" r="40" stroke="orange" stroke-width="5" fill="blue"></circle>
86+
</svg>
87+
</div>
88+
<div class="container hide-empty-test" id="hide-empty-pixel-element">
89+
<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==" width='1' height='1'/>
90+
</div>
91+
<input class="hide-empty-test" id="hide-empty-input">
92+
<div class="container hide-empty-test" id="hide-empty-form-element">
93+
<form>
94+
<input>
95+
</form>
96+
</div>
97+
<div class="container hide-empty-test" id="hide-empty-media-element">
98+
<canvas id="demo-canvas">
99+
</canvas>
100+
</div>
79101
</div>
80102

81103
<div id="closest-empty">
@@ -107,10 +129,9 @@
107129
<div class="container closest-empty-test frame-container-delayed">
108130
</div>
109131
</div>
110-
<div class="container">
111-
<div id="closest-empty-intermediate-element">
112-
<div class="closest-empty-test">
113-
</div>
132+
<div id="closest-empty-img-element">
133+
<div class="container closest-empty-test">
134+
<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==" width='25' height='25'/>
114135
</div>
115136
</div>
116137
<div id="closest-empty-delayed-parent">

features/element-hiding/main.js

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,24 @@ const expectedResults = [
77
{ id: 'hide-empty-no-content', description: 'hide-empty rule: element containing no content is hidden', hidden: true },
88
{ id: 'hide-empty-ad-label', description: 'hide-empty rule: element containing ad label content is hidden', hidden: true },
99
{ id: 'hide-empty-delayed', description: 'hide-empty rule: empty element added to page after delay is hidden', hidden: true },
10+
{ id: 'hide-empty-pixel-element', description: 'hide-empty rule: element should be hidden when it contains tracking pixels', hidden: true },
1011
{ id: 'closest-empty-single-div', description: 'closest-empty rule: element containing no content is hidden', hidden: true },
1112
{ id: 'closest-empty-single-nested-div', description: 'closest-empty rule: parent of target element is hidden', hidden: true },
1213
{ id: 'closest-empty-siblings-nested-div', description: 'closest-empty rule: parent of target element with empty siblings is hidden', hidden: true },
1314
{ id: 'closest-empty-delayed-parent', description: 'closest-empty rule: parent of empty element added to page after delay is hidden', hidden: true },
15+
{ id: 'hide-empty-img-element', description: 'hide-empty rule: element should not be hidden when it contains image content', hidden: false },
16+
{ id: 'hide-empty-svg-element', description: 'hide-empty rule: element should not be hidden when it contains image content', hidden: false },
17+
{ id: 'hide-empty-input', description: 'hide-empty rule: input elements should not be hidden', hidden: false },
18+
{ id: 'hide-empty-form-element', description: 'hide-empty rule: elements containing forms should not be hidden', hidden: false },
19+
{ id: 'hide-empty-media-element', description: 'hide-empty rule: elements containing media should not be hidden', hidden: false },
1420
{ id: 'hide-empty-text-content', description: 'hide-empty rule: element containing text content is not hidden', hidden: false },
1521
{ id: 'hide-empty-frame-content', description: 'hide-empty rule: element containing iframe is not hidden', hidden: false },
1622
{ id: 'hide-empty-delayed-frame', description: 'hide-empty rule: element that loads 3p frame after delay is not hidden', hidden: false },
1723
{ id: 'hide-empty-frame-changed', description: 'hide-empty rule: about:blank iframe that changes src to load content after delay is not hidden', hidden: false },
1824
{ id: 'closest-empty-siblings-content-nested-div', description: 'closest-empty rule: parent of target element with non-empty siblings is not hidden', hidden: false },
1925
{ id: 'closest-empty-frame-content', description: 'closest-empty rule: parent of element containing iframe is not hidden', hidden: false },
2026
{ id: 'closest-empty-delayed-frame', description: 'closest-empty rule: parent of element that loads 3p frame after delay is not hidden', hidden: false },
21-
{ id: 'closest-empty-intermediate-element', description: 'closest-empty rule: intermediate elements should not be hidden when target is nested', hidden: false },
27+
{ id: 'closest-empty-img-element', description: 'closest-empty rule: element should not be hidden when it contains image content', hidden: false },
2228
{ id: 'override-basic', description: 'override rule: element is not hidden when override rule present', hidden: false }
2329
];
2430

@@ -41,14 +47,18 @@ function init () {
4147
// inject frames and other content after delay
4248
injectDelayedContent();
4349

50+
// initialize canvas
51+
initializeCanvas();
52+
4453
// wait 2s then check results
4554
setTimeout(checkResults, 2000);
4655
}
4756

4857
function checkResults () {
4958
for (const testCase of expectedResults) {
5059
const element = document.getElementById(testCase.id);
51-
const isHidden = element.style.getPropertyValue('display') === 'none';
60+
const boundingRect = element.getBoundingClientRect();
61+
const isHidden = boundingRect.height === 0 && boundingRect.width === 0;
5262
const result = testCase.hidden === isHidden;
5363
updateTable(testCase.id, testCase.description, result);
5464
}
@@ -80,6 +90,13 @@ function updateTable (name, description, testPassed) {
8090
results.results.push(result);
8191
}
8292

93+
function initializeCanvas () {
94+
const canvas = document.getElementById('demo-canvas');
95+
const ctx = canvas.getContext('2d');
96+
ctx.fillStyle = '#FF0000';
97+
ctx.fillRect(0, 0, 80, 80);
98+
}
99+
83100
function injectDelayedContent () {
84101
setTimeout(() => {
85102
// inject iframes

0 commit comments

Comments
 (0)