On Github RickyChien / research-slide
Created by Ricky Chien
For better software quality, we need to write tests
Coverage tool can give us a statistics report after testing
Blanket.js - JavaScript test coverage tool
Nowadays, web is going to become more complicated
Browser can take more jobs than server
How to reduce network traffic is a significant problem
Before
After
Browser instrumentation / Server instrumentation
Sometimes we need to interact with a real server
In browser instrumentation
The report of Firefox OS email app should covered 21 modules
Prevalent web dynamic lazy loading scheme
Lazyload-sampleMake it possible to cover dynamic lazy loading scripts
Analyze web script loading approachs
<script src="path-to/script.js"></script>
var xhr = new XMLHttpRequest(); xhr.open('GET', 'path-to/script.js'); // Assign script url xhr.onload = function (script) { eval(script); // Execute script }; xhr.send();
document.write('<script src="path-to/script.js"></script>');
appendChild / insertBefore / replaceChild
var script = document.createElement("script"); script.src = url; // Assign script url document.head.appendChild(script); parentNode.insertBefore(script, node); parentNode.replaceChild(script, oldNode);
Famous module loader library such as RequireJS using syntax :
require(["path-to/script.js"], function() { // This function is called after path-to/script.js has loaded. });
Most of dynamic lazy loading approachs are through DOM modification API and XHR
Overwrite DOM modification API and XHR to detect dynamic lazy loading
Tests are needed to ensure our method is safe
var originalAppendChild = Element.prototype.appendChild; Element.prototype.appendChild = function(newElement) { // Do our hack here return originalAppendChild.apply(this, args); // invoke native method };
var originalXHROpen = XMLHttpRequest.prototype.open; XMLHttpRequest.prototype.open = function(method, url) { // Do our hack here return originalXHROpen.apply(this, args); // invoke native method };
We demonstrated the zero coverage issue
Analyzed source instrumentation mechanism and dynamic lazy loading schemes
Proposed a solution to overwrite native Web APIs to detect dynamic lazy loading
Solution was succssful and safe that even integrated into FFOS testing framework
New feature has proposed to Blanket