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 import sqlite3
# Not present on ChromeOS.
14 from telemetry
import decorators
15 from profile_creators
.cookie_profile_extender
import CookieProfileExtender
18 # Testing private method.
19 # pylint: disable=protected-access
20 class CookieProfileExtenderTest(unittest
.TestCase
):
21 def _CreateCookieTable(self
, path
):
22 connection
= sqlite3
.connect(path
)
23 cursor
= connection
.cursor()
24 cursor
.execute("CREATE TABLE cookies (url text)")
28 def _AddCookiesToTable(self
, path
, count
):
29 connection
= sqlite3
.connect(path
)
30 cursor
= connection
.cursor()
31 for i
in range(count
):
32 cursor
.execute("INSERT INTO cookies VALUES ('%s')" % i
)
36 @decorators.Disabled('chromeos') # crbug.com/483212
37 def testCookieCount(self
):
38 # Neither tempfile.TemporaryFile() nor tempfile.NamedTemporaryFile() work
39 # well here. The former doesn't work at all, since it doesn't gaurantee a
40 # file-system visible path. The latter doesn't work well, since the
41 # returned file cannot be opened a second time on Windows. The returned
42 # file would have to be closed, and the method would need to be called with
43 # Delete=False, which makes its functionality no simpler than
45 handle
, path
= tempfile
.mkstemp()
49 self
._CreateCookieTable
(path
)
50 self
.assertEquals(CookieProfileExtender
._CookieCountInDB
(path
), 0)
52 self
._AddCookiesToTable
(path
, 100)
53 self
.assertEquals(CookieProfileExtender
._CookieCountInDB
(path
), 100)