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.
9 from profile_creators
.cookie_profile_extender
import CookieProfileExtender
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)")
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
)
30 def testCookieCount(self
):
31 # Neither tempfile.TemporaryFile() nor tempfile.NamedTemporaryFile() work
32 # well here. The former doesn't work at all, since it doesn't gaurantee a
33 # file-system visible path. The latter doesn't work well, since the
34 # returned file cannot be opened a second time on Windows. The returned
35 # file would have to be closed, and the method would need to be called with
36 # Delete=False, which makes its functionality no simpler than
38 handle
, path
= tempfile
.mkstemp()
42 self
._CreateCookieTable
(path
)
43 self
.assertEquals(CookieProfileExtender
._CookieCountInDB
(path
), 0)
45 self
._AddCookiesToTable
(path
, 100)
46 self
.assertEquals(CookieProfileExtender
._CookieCountInDB
(path
), 100)