1 var DB_UPDATE_INTERVAL = 100;
2 var SEND_XHR_INTERVAL = 100;
3 var BACK_INTERVAL = 100;
4 var CREATE_HEALTH_TABLE = 'CREATE TABLE IF NOT EXISTS health (key VARCHAR(16) PRIMARY KEY);';
5 var UPDATE_DATA = 'REPLACE INTO health VALUES("health-check-key");';
7 var db = openDatabaseWithSuffix('bug25710', '1.0', 'LayoutTest for bug 25710', 102400);
10 var backFctIntervalId;
11 var successCheckIntervalId;
17 function stopIntervals()
19 stoppedIntervals = true;
20 clearInterval(dbFctIntervalId);
21 clearInterval(xhrFctIntervalId);
22 clearInterval(backFctIntervalId);
25 function stopTest(message)
27 if (!stoppedIntervals)
32 if (window.testRunner)
33 testRunner.notifyDone();
36 function updateDatabase()
39 db.transaction(function(transaction) {
40 transaction.executeSql(UPDATE_DATA, [], function() {}, errorHandler);
41 }, errorHandler, function() {
46 function checkForSuccess()
48 if (successes == databaseUpdates) {
49 stopTest('Test Complete, SUCCESS');
50 clearInterval(successCheckIntervalId);
54 function errorHandler(tx, error)
56 log('DB error, code: ' + error.code + ', msg: ' + error.message);
57 stopTest('Test Complete, FAILED');
62 xhr = new XMLHttpRequest();
63 xhr.open('GET', location.href, true);
74 // Allow a little time for all the database transactions to complete now we've stopped making them.
75 successCheckIntervalId = setInterval(checkForSuccess, 250);
76 // If we don't finish before this time, then we consider the test failed.
77 setTimeout(function() { stopTest('Timed out waiting for transactions to complete. FAILED'); }, 20000);
84 // Location changes need to happen outside the onload handler to generate history entries.
85 setTimeout(runTestsInner, 0);
88 function runTestsInner()
91 consecutiveFailures = 0;
94 stoppedIntervals = false;
96 // Create some hashes so we can call history.back().
97 log('Changing the hash to create history entries.');
98 for (var i = 0; i < backIterations; i++) {
102 // Init the database.
103 db.transaction(function(transaction) {
104 transaction.executeSql(CREATE_HEALTH_TABLE, [], function() {}, errorHandler);
105 }, errorHandler, function() {
106 // Give a little for the database to 'warm up' before making xhr requests
107 // and calling history.back().
108 setTimeout(function() {
109 log('Db is warmed up');
111 // NOTE: If we don't make any xhr requests, then the test
112 // successfully passes (comment this line out).
113 xhrFctIntervalId = setInterval(sendXhr, SEND_XHR_INTERVAL);
114 backFctIntervalId = setInterval(invokeBack, BACK_INTERVAL);
115 dbFctIntervalId = setInterval(updateDatabase, DB_UPDATE_INTERVAL);