Example #1
0
 def setUp(self):
     self._branch_util = BranchUtility(
         os.path.join('branch_utility', 'first.json'), {
             'extensions': 'stable',
             'apps': 'trunk'
         }, FakeUrlFetcher(os.path.join(sys.path[0], 'test_data')),
         InMemoryObjectStore(''))
    def setUp(self):
        self._branch_utility = BranchUtility(
            os.path.join('branch_utility', 'first.json'),
            os.path.join('branch_utility', 'second.json'),
            FakeUrlFetcher(Server2Path('test_data')),
            ObjectStoreCreator.ForTest())
        self._api_fs_creator = FakeHostFileSystemProvider(
            CANNED_API_FILE_SYSTEM_DATA)
        self._node_fs_creator = FakeHostFileSystemProvider(
            TABS_SCHEMA_BRANCHES)
        self._api_fs_iterator = HostFileSystemIterator(self._api_fs_creator,
                                                       self._branch_utility)
        self._node_fs_iterator = HostFileSystemIterator(
            self._node_fs_creator, self._branch_utility)

        # Imitate the actual SVN file system by incrementing the stats for paths
        # where an API schema has changed.
        last_stat = type('last_stat', (object, ), {'val': 0})

        def stat_paths(file_system, channel_info):
            if channel_info.version not in TABS_UNMODIFIED_VERSIONS:
                last_stat.val += 1
            # HACK: |file_system| is a MockFileSystem backed by a TestFileSystem.
            # Increment the TestFileSystem stat count.
            file_system._file_system.IncrementStat(by=last_stat.val)
            # Continue looping. The iterator will stop after 'trunk' automatically.
            return True

        # Use the HostFileSystemIterator created above to change global stat values
        # for the TestFileSystems that it creates.
        self._node_fs_iterator.Ascending(
            # The earliest version represented with the tabs' test data is 13.
            self._branch_utility.GetStableChannelInfo(13),
            stat_paths)
Example #3
0
    def get(self):
        path = self.request.path.replace('/chrome/extensions/', '')

        parts = path.split('/')
        if len(parts) > 1:
            filename = parts[1]
        else:
            filename = parts[0]

        if len(path) > 0 and path[0] == '/':
            path = path.strip('/')

        fetcher = SubversionFetcher(urlfetch)
        b_util = BranchUtility(urlfetch)
        channel_name = b_util.GetChannelNameFromPath(path)
        branch = b_util.GetBranchNumberForChannelName(channel_name)

        logging.info(channel_name + ' ' + branch)
        try:
            result = fetcher.FetchResource(branch, EXTENSIONS_PATH + filename)
            content = result.content
            for key in result.headers:
                self.response.headers[key] = result.headers[key]
        except:
            content = 'File not found.'

        self.response.out.write(content)
Example #4
0
 def _CheckChannelAvailabilityForNode(self,
                                      node_name,
                                      file_system,
                                      channel_info,
                                      earliest_channel_info):
   '''Searches through the _features files in a given |file_system| to
   determine whether or not an API node is available on the given channel,
   |channel_info|. |earliest_channel_info| is the earliest channel the node
   was introduced.
   '''
   features_bundle = self._CreateFeaturesBundle(file_system)
   available_channel = None
   # Only API nodes can have their availability overriden on a per-node basis,
   # so we only need to check _api_features.json.
   if channel_info.version >= _API_FEATURES_MIN_VERSION:
     available_channel = _GetChannelFromAPIFeatures(node_name, features_bundle)
   if (available_channel is None and
       channel_info.version >= earliest_channel_info.version):
     # Most API nodes inherit their availabiltity from their parent, so don't
     # explicitly appear in _api_features.json. For example, "tabs.create"
     # isn't listed; it inherits from "tabs". Assume these are available at
     # |channel_info|.
     available_channel = channel_info.channel
   newest = BranchUtility.NewestChannel((available_channel,
                                         channel_info.channel))
   return available_channel is not None and newest == channel_info.channel
Example #5
0
    def _HandleGet(self, path):
        channel_name, real_path = BranchUtility.SplitChannelNameFromPath(path)

        if channel_name == _DEFAULT_CHANNEL:
            self.redirect('/%s' % real_path)
            return

        if channel_name is None:
            channel_name = _DEFAULT_CHANNEL

        # TODO(kalman): Check if |path| is a directory and serve path/index.html
        # rather than special-casing apps/extensions.
        if real_path.strip('/') == 'apps':
            real_path = 'apps/index.html'
        if real_path.strip('/') == 'extensions':
            real_path = 'extensions/index.html'

        server_instance = ServerInstance.GetOrCreate(channel_name)

        canonical_path = server_instance.path_canonicalizer.Canonicalize(
            real_path)
        if real_path != canonical_path:
            self.redirect(canonical_path)
            return

        ServerInstance.GetOrCreate(channel_name).Get(real_path, self.request,
                                                     self.response)
Example #6
0
  def Get(self):
    ''' Render the page for a request.
    '''
    path = self._request.path.lstrip('/')

    # The server used to be partitioned based on Chrome channel, but it isn't
    # anymore. Redirect from the old state.
    channel_name, path = BranchUtility.SplitChannelNameFromPath(path)
    if channel_name is not None:
      return Response.Redirect('/' + path, permanent=True)

    server_instance = self._delegate.CreateServerInstance()

    try:
      return self._GetSuccessResponse(path, server_instance)
    except FileNotFoundError:
      # Find the closest 404.html file and serve that, e.g. if the path is
      # extensions/manifest/typo.html then first look for
      # extensions/manifest/404.html, then extensions/404.html, then 404.html.
      #
      # Failing that just print 'Not Found' but that should preferrably never
      # happen, because it would look really bad.
      path_components = path.split('/')
      for i in xrange(len(path_components) - 1, -1, -1):
        try:
          path_404 = posixpath.join(*(path_components[0:i] + ['404']))
          response = self._GetSuccessResponse(path_404, server_instance)
          if response.status != 200:
            continue
          return Response.NotFound(response.content.ToString(),
                                   headers=response.headers)
        except FileNotFoundError: continue
      logging.warning('No 404.html found in %s' % path)
      return Response.NotFound('Not Found', headers=_MakeHeaders('text/plain'))
  def setUp(self):
    tabs_unmodified_versions = (16, 20, 23, 24)
    self._branch_utility = BranchUtility(
        os.path.join('branch_utility', 'first.json'),
        os.path.join('branch_utility', 'second.json'),
        FakeUrlFetcher(Server2Path('test_data')),
        ObjectStoreCreator.ForTest())
    self._node_fs_creator = FakeHostFileSystemProvider(TABS_SCHEMA_BRANCHES)
    self._node_fs_iterator = HostFileSystemIterator(self._node_fs_creator,
                                                    self._branch_utility)
    test_object_store = ObjectStoreCreator.ForTest()
    self._avail_finder = AvailabilityFinder(
        self._branch_utility,
        CompiledFileSystem.Factory(test_object_store),
        self._node_fs_iterator,
        self._node_fs_creator.GetMaster(),
        test_object_store,
        'extensions',
        SchemaProcessorFactoryForTest())

    server_instance = ServerInstance.ForTest(
        file_system_provider=FakeHostFileSystemProvider(
            TABS_SCHEMA_BRANCHES))
    self._api_models = server_instance.platform_bundle.GetAPIModels(
        'extensions')
    self._json_cache = server_instance.compiled_fs_factory.ForJson(
        server_instance.host_file_system_provider.GetMaster())

    # Imitate the actual SVN file system by incrementing the stats for paths
    # where an API schema has changed.
    last_stat = type('last_stat', (object,), {'val': 0})

    def stat_paths(file_system, channel_info):
      if channel_info.version not in tabs_unmodified_versions:
        last_stat.val += 1
      # HACK: |file_system| is a MockFileSystem backed by a TestFileSystem.
      # Increment the TestFileSystem stat count.
      file_system._file_system.IncrementStat(by=last_stat.val)
      # Continue looping. The iterator will stop after 'master' automatically.
      return True

    # Use the HostFileSystemIterator created above to change global stat values
    # for the TestFileSystems that it creates.
    self._node_fs_iterator.Ascending(
        # The earliest version represented with the tabs' test data is 13.
        self._branch_utility.GetStableChannelInfo(13),
        stat_paths)
Example #8
0
def _MakeChannelDict(channel_name):
  channel_dict = {
    'channels': [{'name': name} for name in BranchUtility.GetAllBranchNames()],
    'current': channel_name
  }
  for channel in channel_dict['channels']:
    if channel['name'] == channel_name:
      channel['isCurrent'] = True
  return channel_dict
 def testGetBranchNumberForChannelName(self):
     b_util = BranchUtility(test_urlfetch)
     b_util.SetURL('branch_utility/first.json')
     self.assertEquals('1132', b_util.GetBranchNumberForChannelName('dev'))
     self.assertEquals('1084', b_util.GetBranchNumberForChannelName('beta'))
     self.assertEquals('1234',
                       b_util.GetBranchNumberForChannelName('stable'))
     self.assertEquals('trunk',
                       b_util.GetBranchNumberForChannelName('trunk'))
Example #10
0
 def ForLocal():
     object_store_creator = ObjectStoreCreator(start_empty=False,
                                               store_type=TestObjectStore)
     host_file_system_provider = HostFileSystemProvider.ForLocal(
         object_store_creator)
     return ServerInstance(
         object_store_creator,
         CompiledFileSystem.Factory(object_store_creator),
         BranchUtility.Create(object_store_creator),
         host_file_system_provider,
         CloudStorageFileSystemProvider(object_store_creator))
Example #11
0
    def setUp(self):
        self._branch_utility = BranchUtility(
            os.path.join('branch_utility', 'first.json'),
            os.path.join('branch_utility', 'second.json'),
            FakeUrlFetcher(os.path.join(sys.path[0], 'test_data')),
            ObjectStoreCreator.ForTest())

        def create_availability_finder(file_system_data):
            fake_host_fs_creator = FakeHostFileSystemProvider(file_system_data)
            test_object_store = ObjectStoreCreator.ForTest()
            return AvailabilityFinder(
                self._branch_utility,
                CompiledFileSystem.Factory(test_object_store),
                HostFileSystemIterator(fake_host_fs_creator,
                                       self._branch_utility),
                fake_host_fs_creator.GetTrunk(), test_object_store)

        self._avail_finder = create_availability_finder(
            CANNED_API_FILE_SYSTEM_DATA)
        self._node_avail_finder = create_availability_finder(
            TABS_SCHEMA_BRANCHES)
Example #12
0
 def setUp(self):
     self._avail_ds_factory = AvailabilityFinder.Factory(
         ObjectStoreCreator.ForTest(),
         CompiledFileSystem.Factory(
             TestFileSystem(CANNED_API_FILE_SYSTEM_DATA['trunk']),
             ObjectStoreCreator.ForTest()),
         BranchUtility(
             os.path.join('branch_utility', 'first.json'),
             os.path.join('branch_utility', 'second.json'),
             FakeUrlFetcher(os.path.join(sys.path[0], 'test_data')),
             ObjectStoreCreator.ForTest()), _CreateCannedFileSystem)
     self._avail_ds = self._avail_ds_factory.Create()
Example #13
0
  def _HandleGet(self, path):
    if os.environ.get('CRXDOCZH_SLAVE_TYPE') is None:
      self._OriginalHandleGet(path)
      return

    channel_name, real_path = BranchUtility.SplitChannelNameFromPath(path)
    if channel_name is None:
      channel_name = _DEFAULT_CHANNEL

    if os.environ.get('CRXDOCZH_SLAVE_TYPE') == 'samples':
      self._HandleSamplesAPI(channel_name, real_path)
    else:
      self._OriginalHandleGet(path)
Example #14
0
 def testGetChannelNameFromPath(self):
     b_util = BranchUtility(test_urlfetch)
     self.assertEquals(
         'dev', b_util.GetChannelNameFromPath('dev/hello/stuff.html'))
     self.assertEquals(
         'beta', b_util.GetChannelNameFromPath('beta/hello/stuff.html'))
     self.assertEquals(
         'trunk', b_util.GetChannelNameFromPath('trunk/hello/stuff.html'))
     self.assertEquals('stable',
                       b_util.GetChannelNameFromPath('hello/stuff.html'))
     self.assertEquals(
         'stable', b_util.GetChannelNameFromPath('hello/dev/stuff.html'))
def _GetChannelFromFeatures(api_name, json_fs, filename):
  '''Finds API channel information from the features |filename| within the the
  given |json_fs|. Returns None if channel information for the API cannot be
  located.
  '''
  feature = json_fs.GetFromFile('%s/%s' % (API, filename)).Get().get(api_name)
  if feature is None:
    return None
  if isinstance(feature, Mapping):
    # The channel information exists as a solitary dict.
    return feature.get('channel')
  # The channel information dict is nested within a list for whitelisting
  # purposes. Take the newest channel out of all of the entries.
  return BranchUtility.NewestChannel(entry.get('channel') for entry in feature)
Example #16
0
def _CreateServerInstance(commit):
    '''Creates a ServerInstance based on origin/master.
  '''
    object_store_creator = ObjectStoreCreator(
        start_empty=False, store_type=PersistentObjectStoreFake)
    branch_utility = BranchUtility.Create(object_store_creator)
    host_file_system_provider = HostFileSystemProvider(object_store_creator,
                                                       pinned_commit=commit)
    gcs_file_system_provider = CloudStorageFileSystemProvider(
        object_store_creator)
    return ServerInstance(object_store_creator,
                          CompiledFileSystem.Factory(object_store_creator),
                          branch_utility, host_file_system_provider,
                          gcs_file_system_provider)
Example #17
0
def _GetChannelFromFeatures(api_name, file_system, path):
  '''Finds API channel information within _features.json files at the given
  |path| for the given |file_system|. Returns None if channel information for
  the API cannot be located.
  '''
  feature = file_system.GetFromFile(path).get(api_name)

  if feature is None:
    return None
  if isinstance(feature, collections.Mapping):
    # The channel information exists as a solitary dict.
    return feature.get('channel')
  # The channel information dict is nested within a list for whitelisting
  # purposes. Take the newest channel out of all of the entries.
  return BranchUtility.NewestChannel(entry.get('channel') for entry in feature)
Example #18
0
  def GetApiAvailability(self, api_name):
    '''Determines the availability for an API by testing several scenarios.
    (i.e. Is the API experimental? Only available on certain development
    channels? If it's stable, when did it first become stable? etc.)
    '''
    availability = self._object_store.Get(api_name).Get()
    if availability is not None:
      return availability

    # Check for a predetermined availability for this API.
    api_info = self._json_cache.GetFromFile(_API_AVAILABILITIES).get(api_name)
    if api_info is not None:
      channel = api_info.get('channel')
      if channel == _STABLE:
        version = api_info.get('version')
      else:
        version = self._branch_utility.GetChannelInfo(channel).version
      # The file data for predetermined availabilities is already cached, so
      # skip caching this result.
      return AvailabilityInfo(channel, version)

    # Check for the API in the development channels.
    availability = None
    for channel_info in self._branch_utility.GetAllChannelInfo():
      available_channel = self._GetAvailableChannelForVersion(
          api_name,
          channel_info.version)
      # If the |available_channel| for the API is the same as, or older than,
      # the channel we're checking, then the API is available on this channel.
      if (available_channel is not None and
          BranchUtility.NewestChannel((available_channel, channel_info.channel))
              == channel_info.channel):
        availability = AvailabilityInfo(channel_info.channel,
                                        channel_info.version)
        break

    # The API should at least be available on trunk. It's a bug otherwise.
    assert availability, 'No availability found for %s' % api_name

    # If the API is in stable, find the chrome version in which it became
    # stable.
    if availability.channel == _STABLE:
      availability.version = self._FindEarliestStableAvailability(
          api_name,
          availability.version)

    self._object_store.Set(api_name, availability)
    return availability
Example #19
0
    def _RedirectOldHosts(self, host, path):
        ''' Redirect paths from the old code.google.com to the new
    developer.chrome.com, retaining elements like the channel and https, if
    used.
    '''
        if urlsplit(host).hostname != 'code.google.com':
            return None

        path = path.split('/')
        if path and path[0] == 'chrome':
            path.pop(0)

        for channel in BranchUtility.GetAllChannelNames():
            if channel in path:
                path.remove(channel)
                path.insert(0, channel)
                break

        return 'https://developer.chrome.com/' + posixpath.join(*path)
Example #20
0
 def _CheckChannelAvailability(self, api_name, file_system, channel_name):
     '''Searches through the _features files in a given |file_system|, falling
 back to checking the file system for API schema existence, to determine
 whether or not an API is available on the given channel, |channel_name|.
 '''
     json_fs = self._compiled_fs_factory.ForJson(file_system)
     schema_fs = self._compiled_fs_factory.ForApiSchema(file_system)
     available_channel = (
         _GetChannelFromApiFeatures(api_name, json_fs)
         or _GetChannelFromPermissionFeatures(api_name, json_fs)
         or _GetChannelFromManifestFeatures(api_name, json_fs))
     if available_channel is None and _HasApiSchema(api_name, schema_fs):
         # If an API is not represented in any of the _features files, but exists
         # in the filesystem, then assume it is available in this version.
         # The windows API is an example of this.
         available_channel = channel_name
     # If the channel we're checking is the same as or newer than the
     # |available_channel| then the API is available at this channel.
     return (available_channel is not None and BranchUtility.NewestChannel(
         (available_channel, channel_name)) == channel_name)
Example #21
0
 def _CheckChannelAvailability(self, api_name, file_system, channel_info):
     '''Searches through the _features files in a given |file_system|, falling
 back to checking the file system for API schema existence, to determine
 whether or not an API is available on the given channel, |channel_info|.
 '''
     features_bundle = self._CreateFeaturesBundle(file_system)
     available_channel = (
         _GetChannelFromAPIFeatures(api_name, features_bundle)
         or _GetChannelFromPermissionFeatures(api_name, features_bundle)
         or _GetChannelFromManifestFeatures(api_name, features_bundle))
     if (available_channel is None and self._HasAPISchema(
             api_name, file_system, channel_info.version)):
         # If an API is not represented in any of the _features files, but exists
         # in the filesystem, then assume it is available in this version.
         # The chrome.windows API is an example of this.
         available_channel = channel_info.channel
     # If the channel we're checking is the same as or newer than the
     # |available_channel| then the API is available at this channel.
     newest = BranchUtility.NewestChannel(
         (available_channel, channel_info.channel))
     return available_channel is not None and newest == channel_info.channel
Example #22
0
    def _RedirectFromCodeDotGoogleDotCom(self):
        host, path = (self._request.host, self._request.path)

        if not host in ('http://code.google.com', 'https://code.google.com'):
            return None

        new_host = 'http://developer.chrome.com'

        # switch to https if necessary
        if host.startswith('https'):
            new_host = new_host.replace('http', 'https', 1)

        new_path = path.split('/')
        if len(new_path) > 0 and new_path[0] == 'chrome':
            new_path.pop(0)
        for channel in BranchUtility.GetAllChannelNames():
            if channel in new_path:
                position = new_path.index(channel)
                new_path.pop(position)
                new_path.insert(0, channel)
        return Response.Redirect('/'.join([new_host] + new_path))
Example #23
0
    def _RedirectFromCodeDotGoogleDotCom(self, path):
        if (not self.request.url.startswith(
            ('http://code.google.com', 'https://code.google.com'))):
            return False

        new_url = 'http://developer.chrome.com/'

        # switch to https if necessary
        if (self.request.url.startswith('https')):
            new_url = new_url.replace('http', 'https', 1)

        path = path.split('/')
        if len(path) > 0 and path[0] == 'chrome':
            path.pop(0)
        for channel in BranchUtility.GetAllBranchNames():
            if channel in path:
                position = path.index(channel)
                path.pop(position)
                path.insert(0, channel)
        new_url += '/'.join(path)
        self.redirect(new_url)
        return True
 def CreateBranchUtility(self, object_store_creator):
     return BranchUtility.Create(object_store_creator)
Example #25
0
 def _GetOrCreateBranchUtility():
     if ServerInstance.branch_utility is None:
         ServerInstance.branch_utility = BranchUtility(
             url_constants.OMAHA_PROXY_URL, AppEngineUrlFetcher())
     return ServerInstance.branch_utility
Example #26
0
 def setUp(self):
     self._branch_util = BranchUtility(
         os.path.join('branch_utility', 'first.json'),
         os.path.join('branch_utility', 'second.json'),
         FakeUrlFetcher(Server2Path('test_data')),
         ObjectStoreCreator.ForTest())
Example #27
0
class BranchUtilityTest(unittest.TestCase):
    def setUp(self):
        self._branch_util = BranchUtility(
            os.path.join('branch_utility', 'first.json'),
            os.path.join('branch_utility', 'second.json'),
            FakeUrlFetcher(Server2Path('test_data')),
            ObjectStoreCreator.ForTest())

    def testSplitChannelNameFromPath(self):
        self.assertEquals(('stable', 'extensions/stuff.html'),
                          self._branch_util.SplitChannelNameFromPath(
                              'stable/extensions/stuff.html'))
        self.assertEquals(('dev', 'extensions/stuff.html'),
                          self._branch_util.SplitChannelNameFromPath(
                              'dev/extensions/stuff.html'))
        self.assertEquals(('beta', 'extensions/stuff.html'),
                          self._branch_util.SplitChannelNameFromPath(
                              'beta/extensions/stuff.html'))
        self.assertEquals(('master', 'extensions/stuff.html'),
                          self._branch_util.SplitChannelNameFromPath(
                              'master/extensions/stuff.html'))
        self.assertEquals((None, 'extensions/stuff.html'),
                          self._branch_util.SplitChannelNameFromPath(
                              'extensions/stuff.html'))
        self.assertEquals(
            (None, 'apps/stuff.html'),
            self._branch_util.SplitChannelNameFromPath('apps/stuff.html'))
        self.assertEquals((None, 'extensions/dev/stuff.html'),
                          self._branch_util.SplitChannelNameFromPath(
                              'extensions/dev/stuff.html'))
        self.assertEquals(
            (None, 'stuff.html'),
            self._branch_util.SplitChannelNameFromPath('stuff.html'))

    def testNewestChannel(self):
        self.assertEquals(
            'master',
            self._branch_util.NewestChannel(
                ('master', 'dev', 'beta', 'stable')))
        self.assertEquals(
            'master',
            self._branch_util.NewestChannel(
                ('stable', 'beta', 'dev', 'master')))
        self.assertEquals(
            'dev', self._branch_util.NewestChannel(('stable', 'beta', 'dev')))
        self.assertEquals(
            'dev', self._branch_util.NewestChannel(('dev', 'beta', 'stable')))
        self.assertEquals('beta',
                          self._branch_util.NewestChannel(('beta', 'stable')))
        self.assertEquals('beta',
                          self._branch_util.NewestChannel(('stable', 'beta')))
        self.assertEquals('stable',
                          self._branch_util.NewestChannel(('stable', )))
        self.assertEquals('beta', self._branch_util.NewestChannel(('beta', )))
        self.assertEquals('dev', self._branch_util.NewestChannel(('dev', )))
        self.assertEquals('master',
                          self._branch_util.NewestChannel(('master', )))

    @unittest.skipIf(os.name == 'nt', "crbug.com/1114884")
    def testNewer(self):
        oldest_stable_info = ChannelInfo('stable', '963', 17)
        older_stable_info = ChannelInfo('stable', '1025', 18)
        old_stable_info = ChannelInfo('stable', '1084', 19)
        sort_of_old_stable_info = ChannelInfo('stable', '1500', 28)
        stable_info = ChannelInfo('stable', '1547', 29)
        beta_info = ChannelInfo('beta', '1599', 30)
        dev_info = ChannelInfo('dev', '1612', 31)
        master_info = ChannelInfo('master', 'master', 'master')

        self.assertEquals(older_stable_info,
                          self._branch_util.Newer(oldest_stable_info))
        self.assertEquals(old_stable_info,
                          self._branch_util.Newer(older_stable_info))
        self.assertEquals(stable_info,
                          self._branch_util.Newer(sort_of_old_stable_info))
        self.assertEquals(beta_info, self._branch_util.Newer(stable_info))
        self.assertEquals(dev_info, self._branch_util.Newer(beta_info))
        self.assertEquals(master_info, self._branch_util.Newer(dev_info))
        # Test the upper limit.
        self.assertEquals(None, self._branch_util.Newer(master_info))

    @unittest.skipIf(os.name == 'nt', "crbug.com/1114884")
    def testOlder(self):
        master_info = ChannelInfo('master', 'master', 'master')
        dev_info = ChannelInfo('dev', '1612', 31)
        beta_info = ChannelInfo('beta', '1599', 30)
        stable_info = ChannelInfo('stable', '1547', 29)
        old_stable_info = ChannelInfo('stable', '1500', 28)
        older_stable_info = ChannelInfo('stable', '1453', 27)
        oldest_stable_info = ChannelInfo('stable', '396', 5)

        self.assertEquals(dev_info, self._branch_util.Older(master_info))
        self.assertEquals(beta_info, self._branch_util.Older(dev_info))
        self.assertEquals(stable_info, self._branch_util.Older(beta_info))
        self.assertEquals(old_stable_info,
                          self._branch_util.Older(stable_info))
        self.assertEquals(older_stable_info,
                          self._branch_util.Older(old_stable_info))
        # Test the lower limit.
        self.assertEquals(None, self._branch_util.Older(oldest_stable_info))

    @unittest.skipIf(os.name == 'nt', "crbug.com/1114884")
    def testGetChannelInfo(self):
        master_info = ChannelInfo('master', 'master', 'master')
        self.assertEquals(master_info,
                          self._branch_util.GetChannelInfo('master'))

        dev_info = ChannelInfo('dev', '1612', 31)
        self.assertEquals(dev_info, self._branch_util.GetChannelInfo('dev'))

        beta_info = ChannelInfo('beta', '1599', 30)
        self.assertEquals(beta_info, self._branch_util.GetChannelInfo('beta'))

        stable_info = ChannelInfo('stable', '1547', 29)
        self.assertEquals(stable_info,
                          self._branch_util.GetChannelInfo('stable'))

    @unittest.skipIf(os.name == 'nt', "crbug.com/1114884")
    def testGetLatestVersionNumber(self):
        self.assertEquals(37, self._branch_util.GetLatestVersionNumber())

    @unittest.skipIf(os.name == 'nt', "crbug.com/1114884")
    def testGetBranchForVersion(self):
        self.assertEquals('1500', self._branch_util.GetBranchForVersion(28))
        self.assertEquals('1453', self._branch_util.GetBranchForVersion(27))
        self.assertEquals('1410', self._branch_util.GetBranchForVersion(26))
        self.assertEquals('1364', self._branch_util.GetBranchForVersion(25))
        self.assertEquals('1312', self._branch_util.GetBranchForVersion(24))
        self.assertEquals('1271', self._branch_util.GetBranchForVersion(23))
        self.assertEquals('1229', self._branch_util.GetBranchForVersion(22))
        self.assertEquals('1180', self._branch_util.GetBranchForVersion(21))
        self.assertEquals('1132', self._branch_util.GetBranchForVersion(20))
        self.assertEquals('1084', self._branch_util.GetBranchForVersion(19))
        self.assertEquals('1025', self._branch_util.GetBranchForVersion(18))
        self.assertEquals('963', self._branch_util.GetBranchForVersion(17))
        self.assertEquals('696', self._branch_util.GetBranchForVersion(11))
        self.assertEquals('396', self._branch_util.GetBranchForVersion(5))

    @unittest.skipIf(os.name == 'nt', "crbug.com/1114884")
    def testGetChannelForVersion(self):
        self.assertEquals('master',
                          self._branch_util.GetChannelForVersion('master'))
        self.assertEquals('dev', self._branch_util.GetChannelForVersion(31))
        self.assertEquals('beta', self._branch_util.GetChannelForVersion(30))
        self.assertEquals('stable', self._branch_util.GetChannelForVersion(26))
        self.assertEquals('stable', self._branch_util.GetChannelForVersion(22))
        self.assertEquals('stable', self._branch_util.GetChannelForVersion(18))
        self.assertEquals('stable', self._branch_util.GetChannelForVersion(14))
        self.assertEquals(None, self._branch_util.GetChannelForVersion(32))
        self.assertEquals(None, self._branch_util.GetChannelForVersion(42))
Example #28
0
class AvailabilityFinderTest(unittest.TestCase):
    def setUp(self):
        self._branch_utility = BranchUtility(
            os.path.join('branch_utility', 'first.json'),
            os.path.join('branch_utility', 'second.json'),
            FakeUrlFetcher(Server2Path('test_data')),
            ObjectStoreCreator.ForTest())
        api_fs_creator = FakeHostFileSystemProvider(
            CANNED_API_FILE_SYSTEM_DATA)
        self._node_fs_creator = FakeHostFileSystemProvider(
            TABS_SCHEMA_BRANCHES)

        def create_availability_finder(host_fs_creator):
            test_object_store = ObjectStoreCreator.ForTest()
            return AvailabilityFinder(
                self._branch_utility,
                CompiledFileSystem.Factory(test_object_store),
                HostFileSystemIterator(host_fs_creator, self._branch_utility),
                host_fs_creator.GetTrunk(), test_object_store)

        self._avail_finder = create_availability_finder(api_fs_creator)
        self._node_avail_finder = create_availability_finder(
            self._node_fs_creator)

        # Imitate the actual SVN file system by incrementing the stats for paths
        # where an API schema has changed.
        last_stat = type('last_stat', (object, ), {'val': 0})

        def stat_paths(file_system, channel_info):
            if channel_info.version not in TABS_UNMODIFIED_VERSIONS:
                last_stat.val += 1
            # HACK: |file_system| is a MockFileSystem backed by a TestFileSystem.
            # Increment the TestFileSystem stat count.
            file_system._file_system.IncrementStat(by=last_stat.val)
            # Continue looping. The iterator will stop after 'trunk' automatically.
            return True

        # Use the HostFileSystemIterator created above to change global stat values
        # for the TestFileSystems that it creates.
        self._node_avail_finder._file_system_iterator.Ascending(
            # The earliest version represented with the tabs' test data is 13.
            self._branch_utility.GetStableChannelInfo(13),
            stat_paths)

    def testGraphOptimization(self):
        # Keep track of how many times the APISchemaGraph constructor is called.
        original_constructor = api_schema_graph.APISchemaGraph
        mock_constructor = MockFunction(original_constructor)
        api_schema_graph.APISchemaGraph = mock_constructor

        try:
            # The test data includes an extra branch where the API does not exist.
            num_versions = len(TABS_SCHEMA_BRANCHES) - 1
            # We expect an APISchemaGraph to be created only when an API schema file
            # has different stat data from the previous version's schema file.
            num_graphs_created = num_versions - len(TABS_UNMODIFIED_VERSIONS)

            # Run the logic for object-level availability for an API.
            self._node_avail_finder.GetAPINodeAvailability('tabs')

            self.assertTrue(*api_schema_graph.APISchemaGraph.CheckAndReset(
                num_graphs_created))
        finally:
            # Ensure that the APISchemaGraph constructor is reset to be the original
            # constructor.
            api_schema_graph.APISchemaGraph = original_constructor

    def testGetAPIAvailability(self):
        # Key: Using 'channel' (i.e. 'beta') to represent an availability listing
        # for an API in a _features.json file, and using |channel| (i.e. |dev|) to
        # represent the development channel, or phase of development, where an API's
        # availability is being checked.

        # Testing APIs with predetermined availability.
        self.assertEqual(
            AvailabilityInfo(ChannelInfo('trunk', 'trunk', 'trunk')),
            self._avail_finder.GetAPIAvailability('jsonTrunkAPI'))
        self.assertEqual(
            AvailabilityInfo(ChannelInfo('dev', CANNED_BRANCHES[28], 28)),
            self._avail_finder.GetAPIAvailability('jsonDevAPI'))
        self.assertEqual(
            AvailabilityInfo(ChannelInfo('beta', CANNED_BRANCHES[27], 27)),
            self._avail_finder.GetAPIAvailability('jsonBetaAPI'))
        self.assertEqual(
            AvailabilityInfo(ChannelInfo('stable', CANNED_BRANCHES[20], 20)),
            self._avail_finder.GetAPIAvailability('jsonStableAPI'))

        # Testing a whitelisted API.
        self.assertEquals(
            AvailabilityInfo(ChannelInfo('beta', CANNED_BRANCHES[27], 27)),
            self._avail_finder.GetAPIAvailability('declarativeWebRequest'))

        # Testing APIs found only by checking file system existence.
        self.assertEquals(
            AvailabilityInfo(ChannelInfo('stable', CANNED_BRANCHES[23], 23)),
            self._avail_finder.GetAPIAvailability('windows'))
        self.assertEquals(
            AvailabilityInfo(ChannelInfo('stable', CANNED_BRANCHES[18], 18)),
            self._avail_finder.GetAPIAvailability('tabs'))
        self.assertEquals(
            AvailabilityInfo(ChannelInfo('stable', CANNED_BRANCHES[18], 18)),
            self._avail_finder.GetAPIAvailability('input.ime'))

        # Testing API channel existence for _api_features.json.
        # Listed as 'dev' on |beta|, 'dev' on |dev|.
        self.assertEquals(
            AvailabilityInfo(ChannelInfo('dev', CANNED_BRANCHES[28], 28)),
            self._avail_finder.GetAPIAvailability('systemInfo.stuff'))
        # Listed as 'stable' on |beta|.
        self.assertEquals(
            AvailabilityInfo(ChannelInfo('beta', CANNED_BRANCHES[27], 27),
                             scheduled=28),
            self._avail_finder.GetAPIAvailability('systemInfo.cpu'))

        # Testing API channel existence for _manifest_features.json.
        # Listed as 'trunk' on all channels.
        self.assertEquals(
            AvailabilityInfo(ChannelInfo('trunk', 'trunk', 'trunk')),
            self._avail_finder.GetAPIAvailability('sync'))
        # No records of API until |trunk|.
        self.assertEquals(
            AvailabilityInfo(ChannelInfo('trunk', 'trunk', 'trunk')),
            self._avail_finder.GetAPIAvailability('history'))
        # Listed as 'dev' on |dev|.
        self.assertEquals(
            AvailabilityInfo(ChannelInfo('dev', CANNED_BRANCHES[28], 28)),
            self._avail_finder.GetAPIAvailability('storage'))
        # Stable in _manifest_features and into pre-18 versions.
        self.assertEquals(
            AvailabilityInfo(ChannelInfo('stable', CANNED_BRANCHES[8], 8)),
            self._avail_finder.GetAPIAvailability('pageAction'))

        # Testing API channel existence for _permission_features.json.
        # Listed as 'beta' on |trunk|.
        self.assertEquals(
            AvailabilityInfo(ChannelInfo('trunk', 'trunk', 'trunk')),
            self._avail_finder.GetAPIAvailability('falseBetaAPI'))
        # Listed as 'trunk' on |trunk|.
        self.assertEquals(
            AvailabilityInfo(ChannelInfo('trunk', 'trunk', 'trunk')),
            self._avail_finder.GetAPIAvailability('trunkAPI'))
        # Listed as 'trunk' on all development channels.
        self.assertEquals(
            AvailabilityInfo(ChannelInfo('trunk', 'trunk', 'trunk')),
            self._avail_finder.GetAPIAvailability('declarativeContent'))
        # Listed as 'dev' on all development channels.
        self.assertEquals(
            AvailabilityInfo(ChannelInfo('dev', CANNED_BRANCHES[28], 28)),
            self._avail_finder.GetAPIAvailability('bluetooth'))
        # Listed as 'dev' on |dev|.
        self.assertEquals(
            AvailabilityInfo(ChannelInfo('dev', CANNED_BRANCHES[28], 28)),
            self._avail_finder.GetAPIAvailability('cookies'))
        # Treated as 'stable' APIs.
        self.assertEquals(
            AvailabilityInfo(ChannelInfo('stable', CANNED_BRANCHES[24], 24)),
            self._avail_finder.GetAPIAvailability('alarms'))
        self.assertEquals(
            AvailabilityInfo(ChannelInfo('stable', CANNED_BRANCHES[21], 21)),
            self._avail_finder.GetAPIAvailability('bookmarks'))

        # Testing older API existence using extension_api.json.
        self.assertEquals(
            AvailabilityInfo(ChannelInfo('stable', CANNED_BRANCHES[6], 6)),
            self._avail_finder.GetAPIAvailability('menus'))
        self.assertEquals(
            AvailabilityInfo(ChannelInfo('stable', CANNED_BRANCHES[5], 5)),
            self._avail_finder.GetAPIAvailability('idle'))

        # Switches between _features.json files across branches.
        # Listed as 'trunk' on all channels, in _api, _permission, or _manifest.
        self.assertEquals(
            AvailabilityInfo(ChannelInfo('trunk', 'trunk', 'trunk')),
            self._avail_finder.GetAPIAvailability('contextMenus'))
        # Moves between _permission and _manifest as file system is traversed.
        self.assertEquals(
            AvailabilityInfo(ChannelInfo('stable', CANNED_BRANCHES[23], 23)),
            self._avail_finder.GetAPIAvailability('systemInfo.display'))
        self.assertEquals(
            AvailabilityInfo(ChannelInfo('stable', CANNED_BRANCHES[17], 17)),
            self._avail_finder.GetAPIAvailability('webRequest'))

        # Mid-upgrade cases:
        # Listed as 'dev' on |beta| and 'beta' on |dev|.
        self.assertEquals(
            AvailabilityInfo(ChannelInfo('dev', CANNED_BRANCHES[28], 28)),
            self._avail_finder.GetAPIAvailability('notifications'))
        # Listed as 'beta' on |stable|, 'dev' on |beta| ... until |stable| on trunk.
        self.assertEquals(
            AvailabilityInfo(ChannelInfo('trunk', 'trunk', 'trunk')),
            self._avail_finder.GetAPIAvailability('events'))

    def testGetAPINodeAvailability(self):
        # Allow the LookupResult constructions below to take just one line.
        lookup_result = api_schema_graph.LookupResult
        availability_graph = self._node_avail_finder.GetAPINodeAvailability(
            'tabs')

        self.assertEquals(
            lookup_result(True, self._branch_utility.GetChannelInfo('trunk')),
            availability_graph.Lookup('tabs', 'properties',
                                      'fakeTabsProperty3'))
        self.assertEquals(
            lookup_result(True, self._branch_utility.GetChannelInfo('dev')),
            availability_graph.Lookup('tabs', 'events', 'onActivated',
                                      'parameters', 'activeInfo', 'properties',
                                      'windowId'))
        self.assertEquals(
            lookup_result(True, self._branch_utility.GetChannelInfo('dev')),
            availability_graph.Lookup('tabs', 'events', 'onUpdated',
                                      'parameters', 'tab'))
        self.assertEquals(
            lookup_result(True, self._branch_utility.GetChannelInfo('beta')),
            availability_graph.Lookup('tabs', 'events', 'onActivated'))
        self.assertEquals(
            lookup_result(True, self._branch_utility.GetChannelInfo('beta')),
            availability_graph.Lookup('tabs', 'functions', 'get', 'parameters',
                                      'tabId'))
        self.assertEquals(
            lookup_result(True, self._branch_utility.GetChannelInfo('stable')),
            availability_graph.Lookup('tabs', 'types', 'InjectDetails',
                                      'properties', 'code'))
        self.assertEquals(
            lookup_result(True, self._branch_utility.GetChannelInfo('stable')),
            availability_graph.Lookup('tabs', 'types', 'InjectDetails',
                                      'properties', 'file'))
        self.assertEquals(
            lookup_result(True, self._branch_utility.GetStableChannelInfo(25)),
            availability_graph.Lookup('tabs', 'types', 'InjectDetails'))

        # Nothing new in version 24 or 23.

        self.assertEquals(
            lookup_result(True, self._branch_utility.GetStableChannelInfo(22)),
            availability_graph.Lookup('tabs', 'types', 'Tab', 'properties',
                                      'windowId'))
        self.assertEquals(
            lookup_result(True, self._branch_utility.GetStableChannelInfo(21)),
            availability_graph.Lookup('tabs', 'types', 'Tab', 'properties',
                                      'selected'))

        # Nothing new in version 20.

        self.assertEquals(
            lookup_result(True, self._branch_utility.GetStableChannelInfo(19)),
            availability_graph.Lookup('tabs', 'functions', 'getCurrent'))
        self.assertEquals(
            lookup_result(True, self._branch_utility.GetStableChannelInfo(18)),
            availability_graph.Lookup('tabs', 'types', 'Tab', 'properties',
                                      'index'))
        self.assertEquals(
            lookup_result(True, self._branch_utility.GetStableChannelInfo(17)),
            availability_graph.Lookup('tabs', 'events', 'onUpdated',
                                      'parameters', 'changeInfo'))

        # Nothing new in version 16.

        self.assertEquals(
            lookup_result(True, self._branch_utility.GetStableChannelInfo(15)),
            availability_graph.Lookup('tabs', 'properties',
                                      'fakeTabsProperty2'))

        # Everything else is available at the API's release, version 14 here.
        self.assertEquals(
            lookup_result(True, self._branch_utility.GetStableChannelInfo(14)),
            availability_graph.Lookup('tabs', 'types', 'Tab'))
        self.assertEquals(
            lookup_result(True, self._branch_utility.GetStableChannelInfo(14)),
            availability_graph.Lookup('tabs', 'types', 'Tab', 'properties',
                                      'url'))
        self.assertEquals(
            lookup_result(True, self._branch_utility.GetStableChannelInfo(14)),
            availability_graph.Lookup('tabs', 'properties',
                                      'fakeTabsProperty1'))
        self.assertEquals(
            lookup_result(True, self._branch_utility.GetStableChannelInfo(14)),
            availability_graph.Lookup('tabs', 'functions', 'get', 'parameters',
                                      'callback'))
        self.assertEquals(
            lookup_result(True, self._branch_utility.GetStableChannelInfo(14)),
            availability_graph.Lookup('tabs', 'events', 'onUpdated'))

        # Test things that aren't available.
        self.assertEqual(
            lookup_result(False, None),
            availability_graph.Lookup('tabs', 'types', 'UpdateInfo'))
        self.assertEqual(
            lookup_result(False, None),
            availability_graph.Lookup('tabs', 'functions', 'get', 'parameters',
                                      'callback', 'parameters', 'tab', 'id'))
        self.assertEqual(lookup_result(False, None),
                         availability_graph.Lookup('functions'))
        self.assertEqual(
            lookup_result(False, None),
            availability_graph.Lookup('events', 'onActivated', 'parameters',
                                      'activeInfo', 'tabId'))
Example #29
0
# The branch that the server will default to when no branch is specified in the
# URL. This is necessary because it is not possible to pass flags to the script
# handler.
# Production settings:
DEFAULT_BRANCHES = {'extensions': 'stable', 'apps': 'trunk'}
# Dev settings:
# DEFAULT_BRANCHES = { 'extensions': 'local', 'apps': 'local' }

# Increment this version to force the server to reload all pages in the first
# cron job that is run.
_VERSION = 0

BRANCH_UTILITY_MEMCACHE = InMemoryObjectStore('branch_utility')
BRANCH_UTILITY = BranchUtility(url_constants.OMAHA_PROXY_URL, DEFAULT_BRANCHES,
                               AppEngineUrlFetcher(None),
                               BRANCH_UTILITY_MEMCACHE)

GITHUB_MEMCACHE = InMemoryObjectStore('github')
GITHUB_FILE_SYSTEM = GithubFileSystem(
    AppEngineUrlFetcher(url_constants.GITHUB_URL), GITHUB_MEMCACHE,
    AppEngineBlobstore())
GITHUB_COMPILED_FILE_SYSTEM = CompiledFileSystem.Factory(
    GITHUB_FILE_SYSTEM, GITHUB_MEMCACHE)

EXTENSIONS_PATH = 'chrome/common/extensions'
DOCS_PATH = 'docs'
API_PATH = 'api'
TEMPLATE_PATH = DOCS_PATH + '/templates'
INTRO_PATH = TEMPLATE_PATH + '/intros'
ARTICLE_PATH = TEMPLATE_PATH + '/articles'
Example #30
0
 def GetAllChannelInfo(self):
     return tuple(
         self.GetChannelInfo(channel)
         for channel in BranchUtility.GetAllChannelNames())