-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a54a0cc
commit a02b0fe
Showing
20 changed files
with
1,121 additions
and
1,120 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,126 +1,126 @@ | ||
const startButton = document.querySelector('#start') | ||
const downloadButton = document.querySelector('#download') | ||
const startButton = document.querySelector('#start'); | ||
const downloadButton = document.querySelector('#download'); | ||
|
||
const testsDiv = document.querySelector('#tests') | ||
const testsSummaryDiv = document.querySelector('#tests-summary') | ||
const testsDetailsDiv = document.querySelector('#tests-details') | ||
const testsDiv = document.querySelector('#tests'); | ||
const testsSummaryDiv = document.querySelector('#tests-summary'); | ||
const testsDetailsDiv = document.querySelector('#tests-details'); | ||
|
||
const tests = [ | ||
{ | ||
id: 'test-test', | ||
run: () => { | ||
// function returning either a value or a promise | ||
let res | ||
const promise = new Promise((resolve, reject) => { res = resolve }) | ||
let res; | ||
const promise = new Promise((resolve, reject) => { res = resolve; }); | ||
|
||
setTimeout(() => res('ok'), 1000) | ||
setTimeout(() => res('ok'), 1000); | ||
|
||
return promise | ||
return promise; | ||
} | ||
} | ||
] | ||
]; | ||
|
||
// object that contains results of all tests | ||
const results = { | ||
page: 'name-of-the-test', // FILL ME OUT! | ||
date: null, | ||
results: [] | ||
} | ||
}; | ||
|
||
function resultToHTML (data) { | ||
if (Array.isArray(data)) { | ||
return `<ul>${data.map(r => `<li>${r.test} - ${r.result}</li>`).join('')}</ul>` | ||
return `<ul>${data.map(r => `<li>${r.test} - ${r.result}</li>`).join('')}</ul>`; | ||
} else if (data) { | ||
return JSON.stringify(data, null, 2) | ||
return JSON.stringify(data, null, 2); | ||
} | ||
|
||
return null | ||
return null; | ||
} | ||
|
||
/** | ||
* Test runner | ||
*/ | ||
function runTests () { | ||
startButton.setAttribute('disabled', 'disabled') | ||
downloadButton.removeAttribute('disabled') | ||
testsDiv.removeAttribute('hidden') | ||
startButton.setAttribute('disabled', 'disabled'); | ||
downloadButton.removeAttribute('disabled'); | ||
testsDiv.removeAttribute('hidden'); | ||
|
||
results.results.length = 0 | ||
results.date = (new Date()).toUTCString() | ||
let all = 0 | ||
let failed = 0 | ||
results.results.length = 0; | ||
results.date = (new Date()).toUTCString(); | ||
let all = 0; | ||
let failed = 0; | ||
|
||
testsDetailsDiv.innerHTML = '' | ||
testsDetailsDiv.innerHTML = ''; | ||
|
||
function updateSummary () { | ||
testsSummaryDiv.innerText = `Performed ${all} tests${failed > 0 ? ` (${failed} failed)` : ''}. Click for details.` | ||
testsSummaryDiv.innerText = `Performed ${all} tests${failed > 0 ? ` (${failed} failed)` : ''}. Click for details.`; | ||
} | ||
|
||
for (const test of tests) { | ||
const resultObj = { | ||
id: test.id, | ||
value: null | ||
} | ||
results.results.push(resultObj) | ||
}; | ||
results.results.push(resultObj); | ||
|
||
const li = document.createElement('li') | ||
li.id = `test-${test.id.replace(' ', '-')}` | ||
li.innerHTML = `${test.id} - <span class='value'>…</span>` | ||
const valueSpan = li.querySelector('.value') | ||
const li = document.createElement('li'); | ||
li.id = `test-${test.id.replace(' ', '-')}`; | ||
li.innerHTML = `${test.id} - <span class='value'>…</span>`; | ||
const valueSpan = li.querySelector('.value'); | ||
|
||
testsDetailsDiv.appendChild(li) | ||
testsDetailsDiv.appendChild(li); | ||
|
||
try { | ||
const result = test.run() | ||
const result = test.run(); | ||
|
||
if (result instanceof Promise) { | ||
result | ||
.then(data => { | ||
valueSpan.innerHTML = resultToHTML(data) | ||
resultObj.value = data || null | ||
valueSpan.innerHTML = resultToHTML(data); | ||
resultObj.value = data || null; | ||
}) | ||
.catch(e => { | ||
failed++ | ||
valueSpan.innerHTML = `❌ error thrown ("${e.message ? e.message : e}")` | ||
updateSummary() | ||
}) | ||
failed++; | ||
valueSpan.innerHTML = `❌ error thrown ("${e.message ? e.message : e}")`; | ||
updateSummary(); | ||
}); | ||
} else { | ||
valueSpan.innerHTML = resultToHTML(data) | ||
resultObj.value = result || null | ||
valueSpan.innerHTML = resultToHTML(data); | ||
resultObj.value = result || null; | ||
} | ||
} catch (e) { | ||
failed++ | ||
valueSpan.innerHTML = `❌ error thrown ("${e.message ? e.message : e}")` | ||
failed++; | ||
valueSpan.innerHTML = `❌ error thrown ("${e.message ? e.message : e}")`; | ||
} | ||
|
||
all++ | ||
all++; | ||
} | ||
|
||
updateSummary() | ||
updateSummary(); | ||
|
||
startButton.removeAttribute('disabled') | ||
startButton.removeAttribute('disabled'); | ||
} | ||
|
||
function downloadTheResults () { | ||
const data = JSON.stringify(results, null, 2) | ||
const a = document.createElement('a') | ||
const url = window.URL.createObjectURL(new Blob([data], { type: 'application/json' })) | ||
a.href = url | ||
a.download = 'fingerprinting-results.json' | ||
const data = JSON.stringify(results, null, 2); | ||
const a = document.createElement('a'); | ||
const url = window.URL.createObjectURL(new Blob([data], { type: 'application/json' })); | ||
a.href = url; | ||
a.download = 'fingerprinting-results.json'; | ||
|
||
document.body.appendChild(a) | ||
a.click() | ||
document.body.appendChild(a); | ||
a.click(); | ||
|
||
window.URL.revokeObjectURL(url) | ||
a.remove() | ||
window.URL.revokeObjectURL(url); | ||
a.remove(); | ||
} | ||
|
||
downloadButton.addEventListener('click', () => downloadTheResults()) | ||
downloadButton.addEventListener('click', () => downloadTheResults()); | ||
|
||
// run tests if button was clicked or… | ||
startButton.addEventListener('click', () => runTests()) | ||
startButton.addEventListener('click', () => runTests()); | ||
|
||
// if url query is '?run' | ||
if (document.location.search === '?run') { | ||
runTests() | ||
runTests(); | ||
} |
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 |
---|---|---|
@@ -1,22 +1,22 @@ | ||
/* globals log */ | ||
|
||
(() => { | ||
const base = new URL(document.currentScript.src) | ||
const party = base.origin === window.top.location.origin ? 'first' : 'third' | ||
const scriptName = `${party} party script` | ||
const base = new URL(document.currentScript.src); | ||
const party = base.origin === window.top.location.origin ? 'first' : 'third'; | ||
const scriptName = `${party} party script`; | ||
|
||
log(scriptName, new Error().stack) | ||
log(scriptName, new Error().stack); | ||
|
||
const worker = new Worker('./worker.js') | ||
const worker = new Worker('./worker.js'); | ||
worker.addEventListener('message', msg => { | ||
const { source, stackValue } = msg.data | ||
log(`${scriptName} loading ${source}`, stackValue) | ||
}) | ||
worker.postMessage({ action: 'setup' }) | ||
const { source, stackValue } = msg.data; | ||
log(`${scriptName} loading ${source}`, stackValue); | ||
}); | ||
worker.postMessage({ action: 'setup' }); | ||
|
||
setTimeout(() => { | ||
log(`${scriptName} setTimeout`, new Error().stack) | ||
}, 0) | ||
log(`${scriptName} setTimeout`, new Error().stack); | ||
}, 0); | ||
|
||
document.write(`<script>log('${scriptName} write', new Error().stack);</script>`) | ||
})() | ||
document.write(`<script>log('${scriptName} write', new Error().stack);</script>`); | ||
})(); |
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 |
---|---|---|
@@ -1,17 +1,17 @@ | ||
function log (source, stackValue) { | ||
postMessage({ source, stackValue }) | ||
postMessage({ source, stackValue }); | ||
} | ||
|
||
self.addEventListener('message', msg => { | ||
if (msg.data.action && msg.data.action === 'setup') { | ||
setup() | ||
setup(); | ||
} | ||
}) | ||
}); | ||
|
||
function setup () { | ||
log('worker', new Error().stack) | ||
log('worker', new Error().stack); | ||
|
||
setTimeout(() => { | ||
log('worker setTimeout', new Error().stack) | ||
}, 0) | ||
log('worker setTimeout', new Error().stack); | ||
}, 0); | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
Oops, something went wrong.