Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(206)

Delta Between Two Patch Sets: gears/test/testcases/database2_tests.js

Issue 717: Database2Values, argument conversion implemented (Closed) SVN Base: http://google-gears.googlecode.com/svn/contrib/dimitri.glazkov/database2/
Left Patch Set: Removed post-increment Created 4 months, 1 week ago
Right Patch Set: ready for another look. Created 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
LEFTRIGHT
1 // Copyright 2008, Google Inc. 1 // Copyright 2008, Google Inc.
2 // 2 //
3 // Redistribution and use in source and binary forms, with or without 3 // Redistribution and use in source and binary forms, with or without
4 // modification, are permitted provided that the following conditions are met: 4 // modification, are permitted provided that the following conditions are met:
5 // 5 //
6 // 1. Redistributions of source code must retain the above copyright notice, 6 // 1. Redistributions of source code must retain the above copyright notice,
7 // this list of conditions and the following disclaimer. 7 // this list of conditions and the following disclaimer.
8 // 2. Redistributions in binary form must reproduce the above copyright notice, 8 // 2. Redistributions in binary form must reproduce the above copyright notice,
9 // this list of conditions and the following disclaimer in the documentation 9 // this list of conditions and the following disclaimer in the documentation
10 // and/or other materials provided with the distribution. 10 // and/or other materials provided with the distribution.
(...skipping 61 matching lines...) Show 10 above Show 10 below
72 }, null, method + ' requires a callback'); 72 }, null, method + ' requires a callback');
73 73
74 var method = 'Database2.synchronousTransaction()'; 74 var method = 'Database2.synchronousTransaction()';
75 assert(db.synchronousTransaction, method + ' should be present'); 75 assert(db.synchronousTransaction, method + ' should be present');
76 76
77 var method = 'Database2.changeVersion()'; 77 var method = 'Database2.changeVersion()';
78 assert(db.changeVersion, method + ' should be present'); 78 assert(db.changeVersion, method + ' should be present');
79 }); 79 });
80 } 80 }
81 81
82 // TODO(dimitri.glazkov): Uncomment when functionality implemented 82 function testDatabaseTransaction() {
83 //function testDatabaseTransaction() { 83 withDb(function(db) {
84 // withDb(function(db) { 84 var method = 'Database2.transaction()';
85 // var method = 'Database2.transaction()'; 85 var inFlight;
86 // var inFlight; 86 var outOfOrder = 0;
87 // var outOfOrder = 0; 87 // this tests the fact that the transaction callback is called
88 // // this tests the fact that the transaction callback is called 88 // asynchronously and whether the callback is invoked in a proper sequence
89 // // asynchronously and whether the callback is invoked in a proper sequence 89 // if startAsync times out, the callback is not invoked at all
90 // // if startAsync times out, the callback is not invoked at all 90 db.transaction(function(tx) {
91 // db.transaction(function(tx) { 91 inFlight = true;
92 // inFlight = true; 92 outOfOrder--;
93 // outOfOrder--; 93 if (outOfOrder) {
94 // if (outOfOrder) { 94 assert(false, method + ' invokes callback out of sequence');
95 // assert(false, method + ' invokes callback out of sequence'); 95 }
96 // } 96 completeAsync();
97 // completeAsync(); 97 });
98 // }); 98 outOfOrder++;
99 // outOfOrder++; 99 if (inFlight) {
100 // if (inFlight) { 100 assert(false, method + ' is not called asynchronously');
101 // assert(false, method + ' is not called asynchronously'); 101 }
102 // } 102 startAsync();
103 // startAsync(); 103 });
104 // }); 104 }
105 //}
106 105
107 function testDatabaseSynchronousTransaction() { 106 function testDatabaseSynchronousTransaction() {
108 withDb(function(db) { 107 withDb(function(db) {
109 var method = 'Database2.synchronousTransaction() '; 108 var method = 'Database2.synchronousTransaction() ';
110 var inFlight; 109 var inFlight;
111 var outOfOrder = 0; 110 var outOfOrder = 0;
112 // this tests the fact that the transaction callback is called 111 // this tests the fact that the transaction callback is called
113 // synchronously and whether the callback is invoked in a proper sequence 112 // synchronously and whether the callback is invoked in a proper sequence
114 db.synchronousTransaction(function(tx) { 113 db.synchronousTransaction(function(tx) {
115 inFlight = true; 114 inFlight = true;
(...skipping 33 matching lines...) Show 10 above Show 10 below
149 }, null, 'Function arguments are not allowed'); 148 }, null, 'Function arguments are not allowed');
150 // invalid arguments: object 149 // invalid arguments: object
151 assertError(function() { 150 assertError(function() {
152 tx.executeSql('SELECT * FROM Pages WHERE pageId = ? and version = ?', 151 tx.executeSql('SELECT * FROM Pages WHERE pageId = ? and version = ?',
153 [ { you: 'is wrong' }, '1.0.0.0' ]); 152 [ { you: 'is wrong' }, '1.0.0.0' ]);
154 }, null, 'Function arguments are not allowed'); 153 }, null, 'Function arguments are not allowed');
155 }); 154 });
156 }); 155 });
157 } 156 }
158 157
159 // TODO(dimitri.glazkov): Add tests for type fidelity, large integers, and
160 // unsupported types.
161 // TODO(dimitri.glazkov): Rework the tests to create/drop test tables with setup
162 // and tear-down methods.
163 function testSyncExecution() {
164 withDb(function(db) {
165 db.synchronousTransaction(function(tx) {
166 var rs;
167 tx.executeSql('CREATE TABLE IF NOT EXISTS Pages(' +
168 ' pageId INTEGER PRIMARY KEY,' +
169 ' version TEXT)');
170 var pageId;
171 rs = tx.executeSql('SELECT IFNULL(MAX(pageId) + 1, 1) AS max FROM Pages');
172 assert(rs, 'Synchronous execute should return a result set');
173 assert(rs.rows, 'result set must contain rows');
174 assert(rs.rows.length, 'result set must contain one row');
175 assert(rs.rows[0].max,
176 'result set must return one non-zero int value with the key of "max"');
177 pageId = rs.rows[0].max;
178 tx.executeSql('INSERT INTO Pages(pageId, version) ' +
179 'VALUES(?,?)', [ pageId, 'test' ]);
180 var rs = tx.executeSql('SELECT * FROM Pages WHERE pageId = ?',
181 [ pageId ]);
182 assert(rs.rows[0].pageId == pageId,
183 'result set must return the last returned value');
184 });
185 });
186 }
187
188 function testSQLTransactionApiSig() { 158 function testSQLTransactionApiSig() {
189 withDb(function(db) { 159 withDb(function(db) {
190 var method = 'SQLTransaction.executeSql'; 160 var method = 'SQLTransaction.executeSql';
191 db.transaction(function(tx) { 161 db.transaction(function(tx) {
192 assert(tx.executeSQL, method + ' should be present'); 162 assert(tx.executeSQL, method + ' should be present');
193 }); 163 });
194 }); 164 });
195 } 165 }
196 166
197 function withDb(fn, version) { 167 function withDb(fn, version) {
198 db_manager && fn && fn.call( 168 db_manager && fn && fn.call(
199 this, db_manager.openDatabase('unit_test_db', version || '')); 169 this, db_manager.openDatabase('unit_test_db', version || ''));
200 } 170 }
171
LEFTRIGHT

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld r338