Chromium Code Reviews| Index: tools/perf/profile_creators/cookie_profile_extender_unittest.py |
| diff --git a/tools/perf/profile_creators/cookie_profile_extender_unittest.py b/tools/perf/profile_creators/cookie_profile_extender_unittest.py |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..3bec888ea8ddaaf84e14bd84f3ca20bc13e9c410 |
| --- /dev/null |
| +++ b/tools/perf/profile_creators/cookie_profile_extender_unittest.py |
| @@ -0,0 +1,41 @@ |
| +# Copyright 2015 The Chromium Authors. All rights reserved. |
| +# Use of this source code is governed by a BSD-style license that can be |
| +# found in the LICENSE file. |
| +import os |
| +import sqlite3 |
| +import tempfile |
| +import unittest |
| + |
| +from profile_creators.cookie_profile_extender import CookieProfileExtender |
| + |
| + |
| +# Testing private method. |
| +# pylint: disable=protected-access |
| +class CookieProfileExtenderTest(unittest.TestCase): |
| + def _CreateCookieTable(self, path): |
| + connection = sqlite3.connect(path) |
| + cursor = connection.cursor() |
| + cursor.execute("CREATE TABLE cookies (url text)") |
| + connection.commit() |
| + connection.close() |
| + |
| + def _AddCookiesToTable(self, path, count): |
| + connection = sqlite3.connect(path) |
| + cursor = connection.cursor() |
| + for i in range(count): |
| + cursor.execute("INSERT INTO cookies VALUES ('%s')" % i) |
| + connection.commit() |
| + connection.close() |
| + |
| + def testCookieCount(self): |
| + 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
|
| + try: |
| + os.close(handle) |
| + |
| + self._CreateCookieTable(path) |
| + self.assertEquals(CookieProfileExtender._CookieCountInDB(path), 0) |
| + |
| + self._AddCookiesToTable(path, 100) |
| + self.assertEquals(CookieProfileExtender._CookieCountInDB(path), 100) |
| + finally: |
| + os.remove(path) |