diff options
author | Leon Clarke <leonclarke@google.com> | 2010-06-03 14:33:32 +0100 |
---|---|---|
committer | Leon Clarke <leonclarke@google.com> | 2010-06-08 12:24:51 +0100 |
commit | 5af96e2c7b73ebc627c6894727826a7576d31758 (patch) | |
tree | f9d5e6f6175ccd7e3d14de9b290f08937a0d17ba /LayoutTests/storage/hash-change-with-xhr.js | |
parent | 8cc4fcf4f6adcbc0e0aebfc24fbad9a4cddf2cfb (diff) | |
download | external_webkit-5af96e2c7b73ebc627c6894727826a7576d31758.zip external_webkit-5af96e2c7b73ebc627c6894727826a7576d31758.tar.gz external_webkit-5af96e2c7b73ebc627c6894727826a7576d31758.tar.bz2 |
Merge webkit.org at r60469 : Initial merge by git.
Change-Id: I66a0047aa2af802f66bb0c7f2a8b02247a596234
Diffstat (limited to 'LayoutTests/storage/hash-change-with-xhr.js')
-rw-r--r-- | LayoutTests/storage/hash-change-with-xhr.js | 112 |
1 files changed, 112 insertions, 0 deletions
diff --git a/LayoutTests/storage/hash-change-with-xhr.js b/LayoutTests/storage/hash-change-with-xhr.js new file mode 100644 index 0000000..4290681 --- /dev/null +++ b/LayoutTests/storage/hash-change-with-xhr.js @@ -0,0 +1,112 @@ +var DB_UPDATE_INTERVAL = 100; +var SEND_XHR_INTERVAL = 100; +var BACK_INTERVAL = 100; +var CREATE_HEALTH_TABLE = 'CREATE TABLE IF NOT EXISTS health (key VARCHAR(16) PRIMARY KEY);'; +var UPDATE_DATA = 'REPLACE INTO health VALUES("health-check-key");'; + +var db = openDatabaseWithSuffix('bug25710', '1.0', 'LayoutTest for bug 25710', 102400); +var backIterations; +var xhrFctIntervalId; +var backFctIntervalId; +var successCheckIntervalId; +var dbFctIntervalId; +var successes; +var databaseUpdates; +var stoppedIntervals; + +function stopIntervals() +{ + stoppedIntervals = true; + clearInterval(dbFctIntervalId); + clearInterval(xhrFctIntervalId); + clearInterval(backFctIntervalId); +} + +function stopTest(message) +{ + if (!stoppedIntervals) + stopIntervals(); + + log(message); + + if (window.layoutTestController) + layoutTestController.notifyDone(); +} + +function updateDatabase() +{ + databaseUpdates++; + db.transaction(function(transaction) { + transaction.executeSql(UPDATE_DATA, [], function() {}, errorHandler); + }, errorHandler, function() { + successes++; + }); +} + +function checkForSuccess() +{ + if (successes == databaseUpdates) { + stopTest('Test Complete, SUCCESS'); + clearInterval(successCheckIntervalId); + } +} + +function errorHandler(tx, error) +{ + log('DB error, code: ' + error.code + ', msg: ' + error.message); + stopTest('Test Complete, FAILED'); +} + +function sendXhr() +{ + xhr = new XMLHttpRequest(); + xhr.open('GET', location.href, true); + xhr.send(''); +} + +function invokeBack() +{ + backIterations--; + if (backIterations) { + history.back(); + } else { + stopIntervals(); + // Allow a little time for all the database transactions to complete now we've stopped making them. + successCheckIntervalId = setInterval(checkForSuccess, 250); + // If we don't finish before this time, then we consider the test failed. + setTimeout(function() { stopTest('Timed out waiting for transactions to complete. FAILED'); }, 20000); + + } +} + +function runTest() +{ + backIterations = 10; + consecutiveFailures = 0; + successes = 0; + databaseUpdates = 0; + stoppedIntervals = false; + + // Create some hashes so we can call history.back(). + log('Changing the hash to create history entries.'); + for (var i = 0; i < backIterations; i++) { + setLocationHash(i); + } + + // Init the database. + db.transaction(function(transaction) { + transaction.executeSql(CREATE_HEALTH_TABLE, [], function() {}, errorHandler); + }, errorHandler, function() { + // Give a little for the database to 'warm up' before making xhr requests + // and calling history.back(). + setTimeout(function() { + log('Db is warmed up'); + + // NOTE: If we don't make any xhr requests, then the test + // successfully passes (comment this line out). + xhrFctIntervalId = setInterval(sendXhr, SEND_XHR_INTERVAL); + backFctIntervalId = setInterval(invokeBack, BACK_INTERVAL); + dbFctIntervalId = setInterval(updateDatabase, DB_UPDATE_INTERVAL); + }, 500); + }); +} |