[Android WebViewShell] Add inclusion test for webview exposed stable interfaces.
[chromium-blink-merge.git] / tools / perf / fetch_benchmark_deps_unittest.py
blobcbe75c1b9c6f1749adebbcf13b7495d1929bc411
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.
5 import os
6 import sys
7 import unittest
8 import StringIO
10 sys.path.append(os.path.join(os.path.dirname(__file__), os.pardir, 'telemetry'))
11 from telemetry.core import util
13 util.AddDirToPythonPath(util.GetTelemetryDir(), 'third_party', 'mock')
14 import mock # pylint: disable=F0401
16 import fetch_benchmark_deps
19 def NormPaths(paths):
20 return sorted([os.path.normcase(p) for p in paths.splitlines()])
23 class FetchBenchmarkDepsUnittest(unittest.TestCase):
24 """The test guards fetch_benchmark_deps.
26 It assumes the following telemetry APIs always success:
27 telemetry.wpr.archive_info.WprArchiveInfo.DownloadArchivesIfNeeded
28 catapult_base.cloud_storage.GetFilesInDirectoryIfChanged
29 """
31 def setUp(self):
32 """Override sys.argv as if it is called from commnad line."""
33 self._argv = sys.argv
34 sys.argv = ['./fetch_benchmark_deps', '']
36 def _RunFetchBenchmarkDepsTest(self, benchmark_name,
37 expected_fetched_file_paths = None):
38 """Simulates './fetch_benchmark_deps [benchmark_name]'
40 It checks if the paths returned are expected and have corresponding sha1
41 checksums. The expected result can be omitted if the dependencies of
42 specified benchmarks are subject to changes.
44 Args:
45 benchmark_name: benchmark name
46 expected_fetched_file_paths: the expected result.
47 """
48 sys.argv[1] = benchmark_name
49 output = StringIO.StringIO()
50 with mock.patch('telemetry.wpr.archive_info.WprArchiveInfo'
51 '.DownloadArchivesIfNeeded') as mock_download:
52 with mock.patch('catapult_base.cloud_storage'
53 '.GetFilesInDirectoryIfChanged') as mock_get:
54 mock_download.return_value = True
55 mock_get.GetFilesInDirectoryIfChanged.return_value = True
56 fetch_benchmark_deps.main(output)
57 for f in output.getvalue().splitlines():
58 fullpath = os.path.join(fetch_benchmark_deps.GetChromiumDir(), f)
59 sha1path = fullpath + '.sha1'
60 self.assertTrue(os.path.isfile(sha1path))
61 if expected_fetched_file_paths:
62 self.assertEquals(expected_fetched_file_paths,
63 NormPaths(output.getvalue()))
65 def testFetchWPRs(self):
66 self._RunFetchBenchmarkDepsTest('smoothness.top_25_smooth')
68 def testFetchServingDirs(self):
69 self._RunFetchBenchmarkDepsTest('media.tough_video_cases')
71 def testFetchOctane(self):
72 expected = 'src/tools/perf/page_sets/data/octane_001.wpr'
73 self._RunFetchBenchmarkDepsTest('octane', NormPaths(expected))