| Index: chrome/common/extensions/docs/server2/availability_data_source_test.py
|
| diff --git a/chrome/common/extensions/docs/server2/availability_data_source_test.py b/chrome/common/extensions/docs/server2/availability_data_source_test.py
|
| new file mode 100755
|
| index 0000000000000000000000000000000000000000..621e5317642d7216a434a520048915b2082041d1
|
| --- /dev/null
|
| +++ b/chrome/common/extensions/docs/server2/availability_data_source_test.py
|
| @@ -0,0 +1,107 @@
|
| +#!/usr/bin/env python
|
| +# Copyright (c) 2013 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 json
|
| +import os
|
| +import unittest
|
| +
|
| +from availability_data_source import AvailabilityDataSource
|
| +from caching_file_system import CachingFileSystem
|
| +from object_store_creator import ObjectStoreCreator
|
| +from test_file_system import TestFileSystem
|
| +
|
| +_TEST_DIR = 'test_data/availability_data_source/'
|
| +
|
| +def _LoadJson(name, mode='rb'):
|
| + with open(os.path.join(_TEST_DIR, name), mode) as f:
|
| + return json.load(f)
|
| +
|
| +def _CreateSvnFileSystemForBranch(branch):
|
| + file_system_json = _LoadJson('test_avail_file_system.json')
|
| + test_file_system = TestFileSystem(file_system_json[branch])
|
| + return test_file_system
|
| +
|
| +class _FakeChromeVersionUtility(object):
|
| + def GetLatestVersionNumber(self):
|
| + return '27'
|
| +
|
| + def GetBranchNumberForVersion(self, version_number):
|
| + branch_dict_json = _LoadJson('test_avail_branch_list.json')
|
| + branch_number = branch_dict_json[version_number]
|
| + return branch_number
|
| +
|
| +class AvailabilityDataSourceTest(unittest.TestCase):
|
| + def setUp(self):
|
| + file_system_json = _LoadJson('test_avail_file_system.json')
|
| + test_file_system = TestFileSystem(file_system_json)
|
| + self._avail_ds_factory = AvailabilityDataSource.Factory(
|
| + _FakeChromeVersionUtility(),
|
| + ObjectStoreCreator.TestFactory(),
|
| + test_file_system)
|
| + self._avail_ds_factory._existing_availabilities = {'earlyAPI' : '10'}
|
| + self._avail_ds = self._avail_ds_factory.Create()
|
| + self._avail_ds._CreateSvnFileSystemForBranch = _CreateSvnFileSystemForBranch
|
| + self._avail_ds._permission_apis = ['alarms', 'bookmarks', 'cookies']
|
| + self._avail_ds._manifest_apis = ['storage', 'runtime']
|
| + self._avail_ds._orphan_apis = ['tabs', 'windows']
|
| +
|
| + def testCheckFileSystemExistence(self):
|
| + self.assertEquals(True,
|
| + self._avail_ds._CheckFileSystemExistence('tabs', '20'))
|
| + self.assertEquals(False,
|
| + self._avail_ds._CheckFileSystemExistence('tabs', '19'))
|
| + self.assertEquals(False,
|
| + self._avail_ds._CheckFileSystemExistence('windows', '22'))
|
| + self.assertEquals(True,
|
| + self._avail_ds._CheckFileSystemExistence('windows', '24'))
|
| +
|
| + def testCheckManifestExistence(self):
|
| + self.assertEquals(True,
|
| + self._avail_ds._CheckManifestExistence('storage', '27'))
|
| + self.assertEquals(False,
|
| + self._avail_ds._CheckManifestExistence('storage', '26'))
|
| + self.assertEquals(True,
|
| + self._avail_ds._CheckManifestExistence('runtime', '21'))
|
| + self.assertEquals(False,
|
| + self._avail_ds._CheckManifestExistence('runtime', '20'))
|
| +
|
| + def testCheckPermissionExistence(self):
|
| + self.assertEquals(False,
|
| + self._avail_ds._CheckStablePermissionExistence('cookies', '27'))
|
| + self.assertEquals(True,
|
| + self._avail_ds._CheckStablePermissionExistence('alarms', '24'))
|
| + self.assertEquals(False,
|
| + self._avail_ds._CheckStablePermissionExistence('alarms', '23'))
|
| + self.assertEquals(True,
|
| + self._avail_ds._CheckStablePermissionExistence('bookmarks', '21'))
|
| + self.assertEquals(False,
|
| + self._avail_ds._CheckStablePermissionExistence('bookmarks', '20'))
|
| +
|
| + def testFindEarliestStableAvailability(self):
|
| + self.assertEquals('20',
|
| + self._avail_ds._FindEarliestStableAvailability('tabs', 27))
|
| + self.assertEquals('24',
|
| + self._avail_ds._FindEarliestStableAvailability('alarms', 27))
|
| + self.assertEquals('23',
|
| + self._avail_ds._FindEarliestStableAvailability('windows', 27))
|
| + self.assertEquals('27',
|
| + self._avail_ds._FindEarliestStableAvailability('storage', 27))
|
| +
|
| + def testGetAvailability(self):
|
| + self.assertEquals('10',
|
| + self._avail_ds.GetAvailability('earlyAPI'))
|
| + self.assertEquals('20',
|
| + self._avail_ds.GetAvailability('tabs'))
|
| + self.assertEquals('21',
|
| + self._avail_ds.GetAvailability('bookmarks'))
|
| + self.assertEquals('23',
|
| + self._avail_ds.GetAvailability('windows'))
|
| + self.assertEquals('27',
|
| + self._avail_ds.GetAvailability('storage'))
|
| + self.assertEquals('24',
|
| + self._avail_ds.GetAvailability('alarms'))
|
| +
|
| +if __name__ == '__main__':
|
| + unittest.main()
|
|
|