Home | History | Annotate | Download | only in findit
      1 # Copyright (c) 2014 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 
      5 import unittest
      6 
      7 import chromium_deps
      8 from common import utils
      9 
     10 
     11 class ChromiumDEPSTest(unittest.TestCase):
     12   DEPS_TEMPLATE = """
     13 vars = {
     14   "googlecode_url": "http://%%s.googlecode.com/svn",
     15   "webkit_trunk": "http://src.chromium.org/blink/trunk",
     16   "webkit_revision": "%s",
     17   "chromium_git": "https://chromium.googlesource.com",
     18 }
     19 
     20 deps = {
     21   "src/breakpad/src":
     22     (Var("googlecode_url") %% "google-breakpad") + "/trunk/src@%s",
     23 
     24   "src/third_party/WebKit":
     25     Var("webkit_trunk") + "@" + Var("webkit_revision"),
     26 }
     27 
     28 deps_os = {
     29   "unix": {
     30     "src/third_party/liblouis/src":
     31       Var("chromium_git") +
     32       "/external/liblouis.git@%s",
     33   }
     34 }
     35 """
     36 
     37   def __init__(self, *args, **kwargs):
     38     super(ChromiumDEPSTest, self).__init__(*args, **kwargs)
     39 
     40   def testGetChromiumComponents(self):
     41     chromium_revision = '283296'
     42     chromium_revision_git_hash = 'b041fda2e8493dcb26aac08deb493943df240cbb'
     43     webkit_revision = '178200'
     44     breakpad_revision = '1345'
     45     liblouis_commit_hashcode = '3c2daee56250162e5a75830871601d74328d39f5'
     46 
     47     def _GetContentOfDEPS(chromium_revision_tmp):
     48       self.assertEqual(chromium_revision_tmp, chromium_revision_git_hash)
     49       return self.DEPS_TEMPLATE % (webkit_revision, breakpad_revision,
     50                                    liblouis_commit_hashcode)
     51 
     52     expected_results = {
     53         'src/breakpad/src/': {
     54             'path': 'src/breakpad/src/',
     55             'repository_type': 'svn',
     56             'name': 'breakpad',
     57             'repository': 'http://google-breakpad.googlecode.com/svn/trunk/src',
     58             'revision': breakpad_revision
     59         },
     60         'src/third_party/liblouis/src/': {
     61             'path': 'src/third_party/liblouis/src/',
     62             'repository_type': 'git',
     63             'name': 'liblouis',
     64             'repository':
     65                  'https://chromium.googlesource.com/external/liblouis.git',
     66             'revision': liblouis_commit_hashcode
     67         },
     68         'src/': {
     69             'path': 'src/',
     70             'repository_type': 'git',
     71             'name': 'chromium',
     72             'repository': 'https://chromium.googlesource.com/chromium/src/',
     73             'revision': chromium_revision_git_hash
     74         },
     75         'src/third_party/WebKit/': {
     76             'path': 'src/third_party/WebKit/',
     77             'repository_type': 'svn',
     78             'name': 'blink',
     79             'repository': 'http://src.chromium.org/blink/trunk',
     80             'revision': webkit_revision
     81         }
     82     }
     83 
     84     components = chromium_deps.GetChromiumComponents(
     85         chromium_revision, deps_file_downloader=_GetContentOfDEPS)
     86     self.assertEqual(expected_results, components)
     87 
     88   def testGetChromiumComponentRange(self):
     89     chromium_revision1 = '283200'
     90     chromium_revision_git_hash1 = 'c53c387f46a2ff0cf7c072222b826cff0817a80f'
     91     webkit_revision1 = '178084'
     92     breakpad_revision1 = '1345'
     93     liblouis_commit_hashcode1 = '3c2daee56250162e5a75830871601d74328d39f5'
     94 
     95     chromium_revision2 = '283296'
     96     chromium_revision_git_hash2 = 'b041fda2e8493dcb26aac08deb493943df240cbb'
     97     webkit_revision2 = '178200'
     98     breakpad_revision2 = '1345'
     99     liblouis_commit_hashcode2 = '3c2daee56250162e5a75830871601d74328d39f5'
    100 
    101     def _GetContentOfDEPS(chromium_revision):
    102       chromium_revision = str(chromium_revision)
    103       if chromium_revision == chromium_revision_git_hash1:
    104         return self.DEPS_TEMPLATE % (webkit_revision1, breakpad_revision1,
    105                                      liblouis_commit_hashcode1)
    106       else:
    107         self.assertEqual(chromium_revision, chromium_revision_git_hash2)
    108         return self.DEPS_TEMPLATE % (webkit_revision2, breakpad_revision2,
    109                                      liblouis_commit_hashcode2)
    110 
    111     expected_results = {
    112         'src/breakpad/src/': {
    113             'old_revision': breakpad_revision1,
    114             'name': 'breakpad',
    115             'repository': 'http://google-breakpad.googlecode.com/svn/trunk/src',
    116             'rolled': False,
    117             'new_revision': breakpad_revision2,
    118             'path': 'src/breakpad/src/',
    119             'repository_type': 'svn'
    120         },
    121         'src/third_party/liblouis/src/': {
    122             'old_revision': liblouis_commit_hashcode1,
    123             'name': 'liblouis',
    124             'repository':
    125                 'https://chromium.googlesource.com/external/liblouis.git',
    126             'rolled': False,
    127             'new_revision': liblouis_commit_hashcode2,
    128             'path': 'src/third_party/liblouis/src/',
    129             'repository_type': 'git'
    130         },
    131         'src/': {
    132             'old_revision': chromium_revision_git_hash1,
    133             'name': 'chromium',
    134             'repository': 'https://chromium.googlesource.com/chromium/src/',
    135             'rolled': True,
    136             'new_revision': chromium_revision_git_hash2,
    137             'path': 'src/',
    138             'repository_type': 'git'
    139         },
    140         'src/third_party/WebKit/': {
    141             'old_revision': webkit_revision1,
    142             'name': 'blink',
    143             'repository': 'http://src.chromium.org/blink/trunk',
    144             'rolled': True,
    145             'new_revision': webkit_revision2,
    146             'path': 'src/third_party/WebKit/',
    147             'repository_type': 'svn'
    148         }
    149     }
    150 
    151     components = chromium_deps.GetChromiumComponentRange(
    152         chromium_revision1, chromium_revision2,
    153         deps_file_downloader=_GetContentOfDEPS)
    154     self.assertEqual(expected_results, components)
    155 
    156   def _VerifyGitHashForAllComponents(self, deps):
    157     self.assertTrue(deps)
    158     self.assertTrue(isinstance(deps, dict))
    159     for component in deps.values():
    160       for key in ['revision', 'old_revision', 'new_revision']:
    161         if key in component:
    162           self.assertTrue(utils.IsGitHash(component[key]))
    163 
    164   def testComponentRangeCrossGitMigrationPoint(self):
    165     # The old revision is from svn.
    166     # The new revision is from git.
    167     deps = chromium_deps.GetChromiumComponentRange(
    168         '291440',
    169         '744746cc51ef81c8f8d727fafa46b14d1c03fe44')
    170     self._VerifyGitHashForAllComponents(deps)
    171 
    172   def testGetSvnRevision(self):
    173     # For this case, svn revision needs converting to git hash and there will be
    174     # .DEPS.git and DEPS.
    175     deps = chromium_deps.GetChromiumComponents(284750)
    176     self._VerifyGitHashForAllComponents(deps)
    177 
    178   def testGetGitRevisionWithoutDEPS_dot_GIT(self):
    179     # For this case, there is only DEPS, not .DEPS.git.
    180     deps = chromium_deps.GetChromiumComponents(
    181         'f8b3fe9660d8dda318800f55d5e29799bbfd43f7')
    182     self._VerifyGitHashForAllComponents(deps)
    183 
    184 
    185   def testGetGitRevisionWithDEPS_dot_GIT(self):
    186     # For this case, there will be .DEPS.git.
    187     deps = chromium_deps.GetChromiumComponents(
    188         '8ae88241aa9f224e8ce97250f32469d616e437aa')
    189     self._VerifyGitHashForAllComponents(deps)
    190