[Android WebViewShell] Add inclusion test for webview exposed stable interfaces.
[chromium-blink-merge.git] / tools / perf / profile_creators / cookie_profile_extender_unittest.py
bloba52f9561c2ed21ebc0a2e60a57ecb7284328182a
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 tempfile
6 import unittest
8 try:
9 import sqlite3 # Not present on ChromeOS.
10 except ImportError:
11 pass
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)")
25 connection.commit()
26 connection.close()
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)
33 connection.commit()
34 connection.close()
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
44 # tempfile.mkstemp().
45 handle, path = tempfile.mkstemp()
46 try:
47 os.close(handle)
49 self._CreateCookieTable(path)
50 self.assertEquals(CookieProfileExtender._CookieCountInDB(path), 0)
52 self._AddCookiesToTable(path, 100)
53 self.assertEquals(CookieProfileExtender._CookieCountInDB(path), 100)
54 finally:
55 os.remove(path)