-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Surrogates test #32
Merged
Merged
Surrogates test #32
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
c132e31
add surrogate tests
0d325fe
update test
jdorweiler ccade59
remove temp file
jdorweiler f6ba5fb
lint, global results
jdorweiler a37a71e
make linter happy 🙄
jdorweiler 6e026ce
update surrogate test
jdorweiler 02c5c15
update failing test logic
jdorweiler File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8"> | ||
<meta name="viewport" content="width=device-width"> | ||
<title>Tracker surrogates</title> | ||
<style> | ||
#results-table { | ||
font-family: Arial, Helvetica, sans-serif; | ||
border-collapse: collapse; | ||
width: 70%; | ||
} | ||
|
||
#results-table td, #results-table th { | ||
border: 1px solid #ddd; | ||
padding: 8px; | ||
} | ||
|
||
#results-table th { | ||
padding-top: 12px; | ||
padding-bottom: 12px; | ||
text-align: left; | ||
background-color: #f2f2f2; | ||
color: black; | ||
} | ||
</style> | ||
</head> | ||
<p><a href="../index.html">[Home]</a></p> | ||
|
||
<p><b>Test blocking and redirecting to a surrogate</b></p> | ||
<table id='results-table'> | ||
<tr><th>Surrogate</th><th>Loaded</th><th>Passed Test</th><th>Notes</th></tr> | ||
</table> | ||
</body> | ||
<script src='./main.js'></script> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
const results = {}; | ||
|
||
function updateTable ({ name, testData, error }) { | ||
const table = document.getElementById('results-table'); | ||
const row = table.insertRow(-1); | ||
const testName = row.insertCell(0); | ||
const loaded = row.insertCell(1); | ||
const passed = row.insertCell(2); | ||
const note = row.insertCell(3); | ||
|
||
// set default values and colors | ||
testName.innerText = name; | ||
loaded.innerText = 'failed'; | ||
passed.innerText = 'failed'; | ||
row.style.backgroundColor = '#f97268'; | ||
note.style.backgroundColor = '#ffff'; | ||
|
||
results[name] = { pass: true }; | ||
|
||
let testPassed = true; | ||
|
||
if (!error && testData.shouldFail) { | ||
testPassed = false; | ||
} | ||
|
||
if (testPassed) { | ||
loaded.innerText = 'pass'; | ||
|
||
const result = testData.test(); | ||
if (result) { | ||
passed.innerText = 'pass'; | ||
row.style.backgroundColor = '#71bf69'; | ||
} else { | ||
results[name].pass = false; | ||
loaded.innerText = 'failed'; | ||
} | ||
} | ||
|
||
if (testData.notes) { | ||
results[name].notes = testData.notes; | ||
note.innerText = testData.notes; | ||
} | ||
|
||
if (testData.cleanUp) { | ||
testData.cleanUp(); | ||
} | ||
} | ||
|
||
const surrogates = { | ||
'google-analytics.com/analytics.js, crossOrigin': { | ||
url: 'https://google-analytics.com/analytics.js', | ||
crossOrigin: 'anonymous', | ||
notes: 'Test loading with crossOrigin set on element (should fail on Firefox) https://bugzilla.mozilla.org/show_bug.cgi?id=1694679', | ||
shouldFail: false, | ||
test: () => { return !!(window.ga && Object.keys(window.ga.create()).length === 0); }, | ||
cleanUp: () => { delete window.ga; } | ||
}, | ||
'google-analytics.com/analytics.js': { | ||
url: 'https://google-analytics.com/analytics.js', | ||
shouldFail: false, | ||
test: () => { return !!(window.ga && Object.keys(window.ga.create()).length === 0); }, | ||
cleanUp: () => { delete window.ga; } | ||
}, | ||
'Directly accessing a web resouce': { | ||
url: 'chrome-extension://bkdgflcldnnnapblkhphbgpggdiikppg/web_accessible_resources/analytics.js', | ||
kdzwinel marked this conversation as resolved.
Show resolved
Hide resolved
|
||
notes: 'Chromium browsers Only: need access key for web resources', | ||
shouldFail: true, | ||
test: () => { return true; } | ||
} | ||
}; | ||
|
||
(async function loadSurrogates () { | ||
for (const [name, testData] of Object.entries(surrogates)) { | ||
await new Promise((resolve, reject) => { | ||
const s = document.createElement('script'); | ||
|
||
if (testData.crossOrigin) { | ||
s.crossOrigin = testData.crossOrigin; | ||
} | ||
|
||
s.onload = () => { | ||
updateTable({ name, testData }); | ||
resolve(); | ||
}; | ||
|
||
s.onerror = (error) => { | ||
updateTable({ name, testData, error }); | ||
resolve(); | ||
}; | ||
|
||
s.src = testData.url; | ||
|
||
document.body.appendChild(s); | ||
}); | ||
} | ||
})(); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we are not waiting for test to load/fail, so all tests are running at once - can there be a race condition when they overlap (e.g. two tests use
window.ga
)?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, fixed it 👀