Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(302)

Unified Diff: content/test/data/simple_database.html

Issue 10879018: Convert the Web SQL Database pyauto test to content_browsertests. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « content/content_tests.gypi ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/test/data/simple_database.html
===================================================================
--- content/test/data/simple_database.html (revision 152782)
+++ content/test/data/simple_database.html (working copy)
@@ -42,6 +42,52 @@
});
}
+
+// Updates a record at the given index with the given text. The indices are
+// 0-based and are ordered from oldest record, to newest record.
+function updateRecord(index, text) {
+ var didUpdate = false;
+ findId(index, function(rowId) {
+ g_db.transaction(
+ function(tx) {
+ tx.executeSql(
+ "UPDATE table1 SET data=? WHERE ROWID=?",
+ [text, rowId],
+ function(tx, result) {
+ if (result.rowsAffected == 1)
+ didUpdate = true;
+ else if (result.rowsAffected == 0)
+ sendValueToTest("could not update index: " + index);
+ else
+ sendValueToTest("multiple rows with index: " + index);
+ });
+ },
+ function(error) {
+ sendValueToTest("update error: " + error);
+ },
+ function() {
+ if (didUpdate)
+ sendValueToTest("done");
+ });
+ });
+}
+
+// Deletes a record at the given index.
+function deleteRecord(index) {
+ findId(index, function(rowId) {
+ g_db.transaction(
+ function(tx) {
+ tx.executeSql("DELETE FROM table1 WHERE ROWID=?", [rowId]);
+ },
+ function(error) {
+ sendValueToTest("delete error: " + error);
+ },
+ function() {
+ sendValueToTest("done");
+ });
+ });
+}
+
// Gets all the records in the database, ordered by their age.
function getRecords() {
g_db.readTransaction(function(tx) {
@@ -58,11 +104,34 @@
sendValueToTest(items);
},
function(tx, error) {
- sendValueToTest(error);
+ sendValueToTest("getRecords error: " + error);
});
});
}
+// Helper function that finds the ID for a record based on a given index.
+function findId(index, callback) {
+ g_db.readTransaction(function(tx) {
+ // |ROWID| is a special sqlite column. It is unique and is incremented
+ // automatically when a new record is created.
+ // |LIMIT| is a nonstandard clause supported by sqlite that lets us pick
+ // rows from the database by index. E.g., LIMIT 2,10 will give us 10 records
+ // starting at offset 2.
+ tx.executeSql(
+ "SELECT ROWID AS id FROM table1 ORDER BY ROWID LIMIT ?,1",
+ [index],
+ function(tx, result) {
+ if (result.rows.length >= 1)
+ callback(result.rows.item(0).id);
+ else
+ sendValueToTest("could not find row with index: " + index);
+ },
+ function(tx, error) {
+ sendValueToTest("findId error: " + error);
+ });
+ });
+}
+
function sendValueToTest(value) {
//alert(value);
window.domAutomationController.setAutomationId(0);
« no previous file with comments | « content/content_tests.gypi ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698