OLD | NEW |
---|---|
1 #!/usr/bin/python | 1 #!/usr/bin/python |
2 # Copyright (c) 2010 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2010 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 import simplejson | 6 import simplejson |
7 import os | 7 import os |
8 | 8 |
9 import pyauto_functional | 9 import pyauto_functional |
10 import pyauto | 10 import pyauto |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
117 array of all the records in the database | 117 array of all the records in the database |
118 | 118 |
119 Args: | 119 Args: |
120 tab_index: index of the tab that will query the database | 120 tab_index: index of the tab that will query the database |
121 windex: index of the window containing the tab that will query the | 121 windex: index of the window containing the tab that will query the |
122 database | 122 database |
123 """ | 123 """ |
124 json = self.CallJavascriptFunc('getRecords', [], tab_index, windex) | 124 json = self.CallJavascriptFunc('getRecords', [], tab_index, windex) |
125 return self._ParseAndCheckResultFromTestPage(json)['returnValue'] | 125 return self._ParseAndCheckResultFromTestPage(json)['returnValue'] |
126 | 126 |
127 def _HasTable(self, tab_index=0, windex=0): | |
128 """Returns whether the page has a table in its database.""" | |
129 try: | |
130 self._GetRecords(tab_index, windex) | |
131 except SQLExecutionError: | |
132 return False | |
133 return True | |
134 | |
127 def testInsertRecord(self): | 135 def testInsertRecord(self): |
128 """Insert records to the database.""" | 136 """Insert records to the database.""" |
129 self.NavigateToURL(self.TEST_PAGE_URL) | 137 self.NavigateToURL(self.TEST_PAGE_URL) |
130 self._CreateTable() | 138 self._CreateTable() |
131 self._InsertRecord('text') | 139 self._InsertRecord('text') |
132 self.assertEquals(['text'], self._GetRecords()) | 140 self.assertEquals(['text'], self._GetRecords()) |
133 self._InsertRecord('text2') | 141 self._InsertRecord('text2') |
134 self.assertEquals(['text', 'text2'], self._GetRecords()) | 142 self.assertEquals(['text', 'text2'], self._GetRecords()) |
135 | 143 |
136 def testUpdateRecord(self): | 144 def testUpdateRecord(self): |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
169 self.assertEquals(['0', '2'], self._GetRecords()) | 177 self.assertEquals(['0', '2'], self._GetRecords()) |
170 | 178 |
171 def testDeleteNonexistentRow(self): | 179 def testDeleteNonexistentRow(self): |
172 """Attempts to delete a nonexistent row in the table.""" | 180 """Attempts to delete a nonexistent row in the table.""" |
173 self.NavigateToURL(self.TEST_PAGE_URL) | 181 self.NavigateToURL(self.TEST_PAGE_URL) |
174 self._CreateTable() | 182 self._CreateTable() |
175 self._InsertRecord('text') | 183 self._InsertRecord('text') |
176 did_throw_exception = False | 184 did_throw_exception = False |
177 try: | 185 try: |
178 self._DeleteRecord(1) | 186 self._DeleteRecord(1) |
179 except: | 187 except SQLExecutionError: |
180 did_throw_exception = True | 188 did_throw_exception = True |
181 self.assertTrue(did_throw_exception) | 189 self.assertTrue(did_throw_exception) |
182 self.assertEquals(['text'], self._GetRecords()) | 190 self.assertEquals(['text'], self._GetRecords()) |
183 | 191 |
184 def testDatabaseOperations(self): | 192 def testDatabaseOperations(self): |
185 """Insert, update, and delete records in the database.""" | 193 """Insert, update, and delete records in the database.""" |
186 self.NavigateToURL(self.TEST_PAGE_URL) | 194 self.NavigateToURL(self.TEST_PAGE_URL) |
187 self._CreateTable() | 195 self._CreateTable() |
188 | 196 |
189 for i in range(10): | 197 for i in range(10): |
(...skipping 20 matching lines...) Expand all Loading... | |
210 | 218 |
211 def testIncognitoCannotReadRegularDatabase(self): | 219 def testIncognitoCannotReadRegularDatabase(self): |
212 """Attempt to read a database created in a regular browser from an incognito | 220 """Attempt to read a database created in a regular browser from an incognito |
213 browser. | 221 browser. |
214 """ | 222 """ |
215 self.NavigateToURL(self.TEST_PAGE_URL) | 223 self.NavigateToURL(self.TEST_PAGE_URL) |
216 self._CreateTable() | 224 self._CreateTable() |
217 self._InsertRecord('text') | 225 self._InsertRecord('text') |
218 self.RunCommand(pyauto.IDC_NEW_INCOGNITO_WINDOW) | 226 self.RunCommand(pyauto.IDC_NEW_INCOGNITO_WINDOW) |
219 self.NavigateToURL(self.TEST_PAGE_URL, 1, 0) | 227 self.NavigateToURL(self.TEST_PAGE_URL, 1, 0) |
220 can_read_regular_database = False | 228 self.assertFalse(self._HasTable(windex=1)) |
221 try: | |
222 # |_GetRecords| should throw an error because the table does not exist. | |
223 if len(self._GetRecords(windex=1)) == 1: | |
224 can_read_regular_database = True | |
225 except SQLExecutionError: | |
226 pass | |
227 self.assertFalse(can_read_regular_database) | |
228 self._CreateTable(windex=1) | 229 self._CreateTable(windex=1) |
229 self.assertEqual(0, len(self._GetRecords(windex=1))) | 230 self.assertFalse(self._GetRecords(windex=1)) |
230 | 231 |
231 def testRegularCannotReadIncognitoDatabase(self): | 232 def testRegularCannotReadIncognitoDatabase(self): |
232 """Attempt to read a database created in an incognito browser from a regular | 233 """Attempt to read a database created in an incognito browser from a regular |
233 browser. | 234 browser. |
234 """ | 235 """ |
235 self.RunCommand(pyauto.IDC_NEW_INCOGNITO_WINDOW) | 236 self.RunCommand(pyauto.IDC_NEW_INCOGNITO_WINDOW) |
236 self.NavigateToURL(self.TEST_PAGE_URL, 1, 0) | 237 self.NavigateToURL(self.TEST_PAGE_URL, 1, 0) |
237 self._CreateTable(windex=1) | 238 self._CreateTable(windex=1) |
238 self._InsertRecord('text', windex=1) | 239 self._InsertRecord('text', windex=1) |
239 | 240 |
240 # Verify a regular browser cannot read the incognito database. | 241 # Verify a regular browser cannot read the incognito database. |
241 self.NavigateToURL(self.TEST_PAGE_URL) | 242 self.NavigateToURL(self.TEST_PAGE_URL) |
242 can_read_incognito_database = False | 243 self.assertFalse(self._HasTable()) |
243 try: | 244 self._CreateTable() |
244 # |_GetRecords| should throw an error because the table does not exist. | 245 self.assertFalse(self._GetRecords()) |
245 if len(self._GetRecords()) == 1: | |
246 can_read_incognito_database = True | |
247 except SQLExecutionError: | |
248 pass | |
249 self.assertFalse(can_read_incognito_database) | |
250 | 246 |
251 def testDbModificationPersistInSecondTab(self): | 247 def testDbModificationPersistInSecondTab(self): |
252 """Verify DB changes within first tab are present in the second tab.""" | 248 """Verify DB changes within first tab are present in the second tab.""" |
253 self.NavigateToURL(self.TEST_PAGE_URL) | 249 self.NavigateToURL(self.TEST_PAGE_URL) |
254 self._CreateTable() | 250 self._CreateTable() |
255 self._InsertRecord('text') | 251 self._InsertRecord('text') |
256 self.AppendTab(pyauto.GURL(self.TEST_PAGE_URL)) | 252 self.AppendTab(pyauto.GURL(self.TEST_PAGE_URL)) |
257 self._UpdateRecord(0, '0', tab_index=0) | 253 self._UpdateRecord(0, '0', tab_index=0) |
258 tab1_records = self._GetRecords(tab_index=0) | 254 tab1_records = self._GetRecords(tab_index=0) |
259 tab2_records = self._GetRecords(tab_index=1) | 255 tab2_records = self._GetRecords(tab_index=1) |
260 self.assertEquals(1, len(tab1_records)) | 256 self.assertEquals(1, len(tab1_records)) |
261 self.assertEquals('0', tab1_records[0]) | 257 self.assertEquals('0', tab1_records[0]) |
262 self.assertEquals(1, len(tab2_records)) | 258 self.assertEquals(1, len(tab2_records)) |
263 self.assertEquals(tab1_records[0], tab2_records[0]) | 259 self.assertEquals(tab1_records[0], tab2_records[0]) |
264 | 260 |
261 def testIncognitoDatabaseNotPersistent(self): | |
262 """Verify incognito database is removed after incognito window closes.""" | |
263 self.RunCommand(pyauto.IDC_NEW_INCOGNITO_WINDOW) | |
264 self.NavigateToURL(self.TEST_PAGE_URL, 1, 0) | |
265 self._CreateTable(windex=1) | |
266 self._InsertRecord('text', windex=1) | |
267 self.CloseBrowserWindow(1) | |
268 self.RunCommand(pyauto.IDC_NEW_INCOGNITO_WINDOW) | |
269 self.NavigateToURL(self.TEST_PAGE_URL, 1, 0) | |
270 self.assertFalse(self._HasTable(windex=1)) | |
271 | |
272 def testModificationsPersistAfterRendererCrash(self): | |
273 """Verify database modifications persist after crashing tab.""" | |
274 self.NavigateToURL(self.TEST_PAGE_URL) | |
275 self._CreateTable() | |
276 self._InsertRecord('1') | |
277 self.NavigateToURL('about:crash') | |
Nirnimesh
2010/11/24 23:07:57
This will create a .dmp file, and there're checks
| |
278 self.NavigateToURL(self.TEST_PAGE_URL) | |
279 self.assertEqual(['1'], self._GetRecords()) | |
280 | |
281 def testIncognitoDBPersistentAcrossTabs(self): | |
282 """Test to check if database modifications are persistent across tabs | |
283 in incognito window. | |
284 """ | |
285 self.RunCommand(pyauto.IDC_NEW_INCOGNITO_WINDOW) | |
286 self.NavigateToURL(self.TEST_PAGE_URL, 1, 0) | |
287 self._CreateTable(windex=1) | |
288 self._InsertRecord('text', windex=1) | |
289 self.AppendTab(pyauto.GURL(self.TEST_PAGE_URL), 1) | |
290 self.assertEquals(['text'], self._GetRecords(1, 1)) | |
291 | |
265 | 292 |
266 if __name__ == '__main__': | 293 if __name__ == '__main__': |
267 pyauto_functional.Main() | 294 pyauto_functional.Main() |
OLD | NEW |