-
Notifications
You must be signed in to change notification settings - Fork 15
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
Test Automation - clean up #61
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
29070be
result->value for consistency
kdzwinel 8558e30
Flatten test results, separate value from error message.
kdzwinel 79d912e
result -> value for consistency
kdzwinel 919411f
Referrer trimming - flatten results object.
kdzwinel b07247b
Expose click-to-play results in a global variable. Move JS from HTML …
kdzwinel 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
let facebookCalls = 0; | ||
let fbIFrames = 0; | ||
|
||
// object that contains results of all tests | ||
const results = { | ||
jonathanKingston marked this conversation as resolved.
Show resolved
Hide resolved
|
||
page: 'facebook-click-to-load', | ||
date: (new Date()).toUTCString(), | ||
results: [] | ||
}; | ||
|
||
function updateResults () { | ||
results.results = [ | ||
{ | ||
id: 'facebookCalls', | ||
value: facebookCalls | ||
}, | ||
{ | ||
id: 'fbIFrames', | ||
value: fbIFrames | ||
} | ||
]; | ||
|
||
document.getElementById('facebook_iFrames').innerHTML = fbIFrames; | ||
document.getElementById('facebook_call_count').innerHTML = facebookCalls; | ||
} | ||
|
||
// Find all the iFrames currently on page. | ||
const frameNodes = document.querySelectorAll('iFrame'); | ||
fbIFrames = frameNodes.length; | ||
updateResults(); | ||
|
||
// This initializes the facebook SDK. | ||
window.fbAsyncInit = function () { | ||
// eslint-disable-next-line no-undef | ||
FB.init({ | ||
appId: '', | ||
autoLogAppEvents: true, | ||
xfbml: true, | ||
version: 'v9.0' | ||
}); | ||
|
||
function fbLogin () { | ||
const displayArea = document.getElementById('loginResponse'); | ||
displayArea.innerHTML = 'Calling FB SDK... '; | ||
// eslint-disable-next-line no-undef | ||
FB.login(function (response) { | ||
if (response.authResponse) { | ||
displayArea.innerHTML = 'Starting FB login... '; | ||
// eslint-disable-next-line no-undef | ||
FB.api('/me', function (response) { | ||
displayArea.innerHTML = `Logged in as ${response.name}`; | ||
}); | ||
} else { | ||
displayArea.innerHTML = 'User cancelled login or did not fully authorize.'; | ||
} | ||
}); | ||
} | ||
|
||
const loginButton = document.getElementById('custom-fb-login-button'); | ||
loginButton.addEventListener('click', fbLogin); | ||
}; | ||
|
||
function facebookObserver (list, observer) { | ||
const resourceLoads = list.getEntriesByType('resource'); | ||
for (const resource of resourceLoads) { | ||
if (resource.name.match(/facebook.com|facebook.net/)) { | ||
/* Observer still counts calls that fail, but the duration is less. In testing, | ||
* failed iFrames always returned in around 100 or less, with success generally being | ||
* above 200. Occasionally, a loaded resource comes in around 150. If Facebook requests | ||
* are allowed, there will also be other resources that load - scripts and content | ||
* which will always be counted. | ||
*/ | ||
if (resource.initiatorType !== 'iframe' || resource.duration > 150) { | ||
facebookCalls += 1; | ||
} | ||
} | ||
} | ||
|
||
updateResults(); | ||
} | ||
|
||
const observer = new PerformanceObserver(facebookObserver); | ||
observer.observe({ entryTypes: ['resource'] }); | ||
|
||
function downloadTheResults () { | ||
const data = JSON.stringify(results); | ||
const a = document.createElement('a'); | ||
const url = window.URL.createObjectURL(new Blob([data], { type: 'application/json' })); | ||
a.href = url; | ||
a.download = 'facebook-click-to-load-results.json'; | ||
|
||
document.body.appendChild(a); | ||
a.click(); | ||
|
||
window.URL.revokeObjectURL(url); | ||
a.remove(); | ||
} | ||
|
||
const downloadButton = document.querySelector('#download'); | ||
downloadButton.addEventListener('click', () => downloadTheResults()); |
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
Oops, something went wrong.
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.
moved JS code to separate file