[Session restore] Rename group name Enabled to Restore.
[chromium-blink-merge.git] / tools / perf / update_reference_build_unittest.py
blob2eb9fb02b98dba392cb797fb64cbd846311c6d19
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 unittest
6 import update_reference_build as update_ref_build
9 class UpdateReferenceBuildUnittest(unittest.TestCase):
10 def testInit(self):
11 @classmethod
12 def EmptyVersions(_):
13 return {}
14 @classmethod
15 def AllOmahaVersion1(_):
16 return {'mac':'1', 'linux':'1', 'win':'1'}
17 @classmethod
18 def AllCurrentVersion1(_):
19 return {'Mac':'1', 'Linux':'1', 'Linux_x64':'1', 'Win':'1'}
20 @classmethod
21 def MixedOmahaVersion23(_):
22 return {'mac':'2', 'linux':'3', 'win':'2'}
23 @classmethod
24 def MissingOmahaVersion(_):
25 return {'mac':'2', 'win':'1'}
26 old_stable = update_ref_build.BuildUpdater._OmahaVersionsMap
27 old_current = update_ref_build.BuildUpdater._CurrentRefBuildsMap
28 try:
29 update_ref_build.BuildUpdater._CurrentRefBuildsMap = EmptyVersions
30 update_ref_build.BuildUpdater._OmahaVersionsMap = AllOmahaVersion1
31 expected_versions = {'Mac':'1', 'Linux':'1', 'Linux_x64':'1', 'Win':'1'}
32 b = update_ref_build.BuildUpdater()
33 self.assertEqual(expected_versions, b._platform_to_version_map)
35 update_ref_build.BuildUpdater._OmahaVersionsMap = MissingOmahaVersion
36 expected_versions = {'Mac':'2', 'Win':'1'}
37 b = update_ref_build.BuildUpdater()
38 self.assertEqual(expected_versions, b._platform_to_version_map)
40 update_ref_build.BuildUpdater._CurrentRefBuildsMap = AllCurrentVersion1
41 expected_versions = {'Mac':'2'}
42 b = update_ref_build.BuildUpdater()
43 self.assertEqual(expected_versions, b._platform_to_version_map)
45 update_ref_build.BuildUpdater._OmahaVersionsMap = MixedOmahaVersion23
46 expected_versions = {'Mac':'2', 'Linux':'3', 'Linux_x64':'3', 'Win':'2'}
47 b = update_ref_build.BuildUpdater()
48 self.assertEqual(expected_versions, b._platform_to_version_map)
49 finally:
50 update_ref_build.BuildUpdater._OmahaVersionsMap = old_stable
51 update_ref_build.BuildUpdater._CurrentRefBuildsMap = old_current
54 def testOmahaVersions(self):
55 #This is an example of valid output from the _OmahaReport function.
56 #Taken from processing the omaha report on 3/18/15
57 lines = [['os', 'channel', 'current_version', 'previous_version',
58 'current_reldate', 'previous_reldate', 'branch_base_commit',
59 'branch_base_position', 'branch_commit', 'base_webkit_position',
60 'true_branch', 'v8_version\n'],
61 ['win', 'stable', '41.0.2272.89', '41.0.2272.76', '03/10/15',
62 '03/03/15', '827a380cfdb31aa54c8d56e63ce2c3fd8c3ba4d4', '310958',
63 'a4d5695040a99b9b2cb196eb5b898383a274376e', '188177', 'master',
64 '4.1.0.21\n'],
65 ['mac', 'stable', '41.0.2272.89', '41.0.2272.76', '03/10/15',
66 '03/03/15', '827a380cfdb31aa54c8d56e63ce2c3fd8c3ba4d4', '310958',
67 'a4d5695040a99b9b2cb196eb5b898383a274376e', '188177', 'master',
68 '4.1.0.21\n'],
69 ['linux', 'stable', '41.0.2272.89', '41.0.2272.76', '03/10/15',
70 '03/03/15', '827a380cfdb31aa54c8d56e63ce2c3fd8c3ba4d4', '310958',
71 'a4d5695040a99b9b2cb196eb5b898383a274376e', '188177', 'master',
72 '4.1.0.21\n'],
73 ['cros', 'stable', '41.0.2272.89', '41.0.2272.76', '03/10/15',
74 '03/04/15', '827a380cfdb31aa54c8d56e63ce2c3fd8c3ba4d4', '310958',
75 'a4d5695040a99b9b2cb196eb5b898383a274376e', '188177', 'master',
76 '4.1.0.21\n'],
77 ['android', 'stable', '41.0.2272.94', '40.0.2214.109', '03/18/15',
78 '02/04/15', '827a380cfdb31aa54c8d56e63ce2c3fd8c3ba4d4', '310958',
79 '70c994cb9b14e4c6934654aaa7089b4b2e8f7788', '188177', '2272',
80 '4.1.0.21\n'],
81 ['ios', 'stable', '41.0.2272.56', '40.0.2214.73', '03/16/15',
82 '02/18/15', 'N/A', 'N/A', 'N/A', 'N/A', 'N/A', 'N/A\n']]
83 @classmethod
84 def GetLines(_):
85 return lines
86 old_omaha_report = update_ref_build.BuildUpdater._OmahaReport
87 update_ref_build.BuildUpdater._OmahaReport = GetLines
88 expected_versions = {'win':'41.0.2272.89', 'mac':'41.0.2272.89',
89 'linux':'41.0.2272.89'}
90 b = update_ref_build.BuildUpdater()
91 try:
92 versions = b._OmahaVersionsMap()
93 self.assertEqual(expected_versions, versions)
94 lines = [['os', 'channel', 'current_version', 'previous_version',
95 'current_reldate', 'previous_reldate', 'branch_base_commit',
96 'branch_base_position', 'branch_commit', 'base_webkit_position',
97 'true_branch', 'v8_version\n'],
98 ['win', 'stable', '41.0.2272.89', '41.0.2272.76', '03/10/15',
99 '03/03/15', '827a380cfdb31aa54c8d56e63ce2c3fd8c3ba4d4',
100 '310958', 'a4d5695040a99b9b2cb196eb5b898383a274376e', '188177',
101 'master', '4.1.0.21\n']]
102 self.assertRaises(ValueError, b._OmahaVersionsMap)
103 lines = ['random', 'list', 'of', 'strings']
104 self.assertRaises(ValueError, b._OmahaVersionsMap)
105 lines = []
106 self.assertRaises(ValueError, b._OmahaVersionsMap)
107 finally:
108 update_ref_build.BuildUpdater._OmahaReport = old_omaha_report