eventTestHarness.js (1500B)
1 storageEventList = []; 2 iframe = document.createElement("IFRAME"); 3 document.body.appendChild(iframe); 4 5 function runAfterNStorageEvents(callback, expectedNumEvents) 6 { 7 countStorageEvents(callback, expectedNumEvents, 0) 8 } 9 10 function countStorageEvents(callback, expectedNumEvents, times) 11 { 12 function onTimeout() 13 { 14 var currentCount = storageEventList.length; 15 if (currentCount == expectedNumEvents) { 16 callback(); 17 } else if (currentCount > expectedNumEvents) { 18 msg = "got at least " + currentCount + ", expected only " + expectedNumEvents + " events"; 19 callback(msg); 20 } else if (times > 50) { 21 msg = "Timeout: only got " + currentCount + ", expected " + expectedNumEvents + " events"; 22 callback(msg); 23 } else { 24 countStorageEvents(callback, expectedNumEvents, times+1); 25 } 26 } 27 setTimeout(onTimeout, 20); 28 } 29 30 function clearStorage(storageName, callback) 31 { 32 if (window[storageName].length === 0) { 33 storageEventList = []; 34 setTimeout(callback, 0); 35 } else { 36 window[storageName].clear(); 37 runAfterNStorageEvents(function() { 38 storageEventList = []; 39 callback(); 40 }, 1); 41 } 42 } 43 44 function testStorages(testCallback) 45 { 46 testCallback("sessionStorage"); 47 var hit = false; 48 add_result_callback(function() { 49 if (!hit) { 50 hit = true; 51 testCallback("localStorage"); 52 } 53 }); 54 }