Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 # Copyright 2015 The Chromium Authors. All rights reserved. | |
| 2 # Use of this source code is governed by a BSD-style license that can be | |
| 3 # found in the LICENSE file. | |
| 4 import os | |
| 5 import sqlite3 | |
| 6 import tempfile | |
| 7 import unittest | |
| 8 | |
| 9 from profile_creators.cookie_profile_extender import CookieProfileExtender | |
| 10 | |
| 11 | |
| 12 # Testing private method. | |
| 13 # pylint: disable=protected-access | |
| 14 class CookieProfileExtenderTest(unittest.TestCase): | |
| 15 def _CreateCookieTable(self, path): | |
| 16 connection = sqlite3.connect(path) | |
| 17 cursor = connection.cursor() | |
| 18 cursor.execute("CREATE TABLE cookies (url text)") | |
| 19 connection.commit() | |
| 20 connection.close() | |
| 21 | |
| 22 def _AddCookiesToTable(self, path, count): | |
| 23 connection = sqlite3.connect(path) | |
| 24 cursor = connection.cursor() | |
| 25 for i in range(count): | |
| 26 cursor.execute("INSERT INTO cookies VALUES ('%s')" % i) | |
| 27 connection.commit() | |
| 28 connection.close() | |
| 29 | |
| 30 def testCookieCount(self): | |
| 31 handle, path = tempfile.mkstemp() | |
|
nednguyen
2015/02/19 00:33:31
Can you try tempfile.TemporaryFile() here also?
w
erikchen
2015/02/19 01:56:03
The behavior of TemporaryFile() is OS dependent, a
nednguyen
2015/02/19 17:07:37
Thanks for clear explanation. :-)
sullivan
2015/02/19 18:24:42
We've had test breakages before due to platform-sp
| |
| 32 try: | |
| 33 os.close(handle) | |
| 34 | |
| 35 self._CreateCookieTable(path) | |
| 36 self.assertEquals(CookieProfileExtender._CookieCountInDB(path), 0) | |
| 37 | |
| 38 self._AddCookiesToTable(path, 100) | |
| 39 self.assertEquals(CookieProfileExtender._CookieCountInDB(path), 100) | |
| 40 finally: | |
| 41 os.remove(path) | |
| OLD | NEW |