Beispiel #1
0
 def testPartials(self):
   template_data_source = self._CreateTemplateDataSource('partials')
   context = json.loads(ReadFile(self._base_path, 'partials', 'input.json'))
   self.assertEqual(
       ReadFile(self._base_path, 'partials', 'test_expected.html'),
       template_data_source.get('test_tmpl').Render(
           context, template_data_source).text)
Beispiel #2
0
 def testSimple(self):
   template_data_source = self._CreateTemplateDataSource('simple')
   template_a1 = Handlebar(ReadFile(self._base_path, 'simple', 'test1.html'))
   context = [{}, {'templates': {}}]
   self.assertEqual(
       template_a1.Render(*context).text,
       template_data_source.get('test1').Render(*context).text)
   template_a2 = Handlebar(ReadFile(self._base_path, 'simple', 'test2.html'))
   self.assertEqual(
       template_a2.Render(*context).text,
       template_data_source.get('test2').Render(*context).text)
 def fetch(self, url):
     if _GITILES_URL_TO_COMMIT_PATTERN.match(url) is not None:
         return json.dumps({'commit': '1' * 40})
     path = _ExtractPathFromGitilesUrl(url)
     chromium_path = ChromiumPath(path)
     if self._IsDir(chromium_path):
         jsn = {}
         dir_stat = self._Stat(chromium_path)
         jsn['id'] = dir_stat
         jsn['entries'] = []
         for f in self._ListDir(chromium_path):
             if f.startswith('.'):
                 continue
             f_path = os.path.join(chromium_path, f)
             jsn['entries'].append({
                 'id':
                 self._Stat(f_path),
                 'name':
                 f,
                 'type':
                 'tree' if self._IsDir(f_path) else 'blob'
             })
         return json.dumps(jsn)
     try:
         return base64.b64encode(ReadFile(path))
     except IOError:
         return None
 def resolve():
     assert '?' in url
     if url == _BASE_URL + '?format=JSON':
         return _Response(json.dumps({'commit': 'a_commit'}))
     path, fmt = url.split('?')
     # Fetch urls are of the form <base_url>/<path>. We only want <path>.
     path = path.split('/', 1)[1]
     if path == _REAL_DATA_DIR:
         return _Response(ReadFile(*_TEST_DATA))
     # ALWAYS skip not found here.
     content = self._fs.Read((path, ),
                             skip_not_found=True).Get().get(path, None)
     if content is None:
         # GitilesFS expects a DownloadError if the file wasn't found.
         raise DownloadError
     # GitilesFS expects directory content as a JSON string.
     if 'JSON' in fmt:
         content = json.dumps({
             'entries': [
                 {
                     # GitilesFS expects directory names to not have a trailing '/'.
                     'name': name.rstrip('/'),
                     'type': 'tree' if IsDirectory(name) else 'blob'
                 } for name in content
             ]
         })
     return _Response(content)
Beispiel #5
0
 def fetch(self, url):
     path = ChromiumPath(_ExtractPathFromSvnUrl(url))
     if self._IsDir(path):
         html = ['<table><tbody><tr>...</tr>']
         # The version of the directory.
         dir_stat = self._Stat(path)
         html.append('<tr>')
         html.append('<td>Directory revision:</td>')
         html.append('<td><a>%s</a><a></a></td>' % dir_stat)
         html.append('</tr>')
         # The version of each file.
         for f in self._ListDir(path):
             if f.startswith('.'):
                 continue
             html.append('<tr>')
             html.append(
                 '  <td><a>%s%s</a></td>' %
                 (f, '/' if self._IsDir(os.path.join(path, f)) else ''))
             html.append('  <td><a><strong>%s</strong></a></td>' %
                         self._Stat(os.path.join(path, f)))
             html.append('<td></td><td></td><td></td>')
             html.append('</tr>')
         html.append('</tbody></table>')
         return '\n'.join(html)
     try:
         return ReadFile(path)
     except IOError:
         return None
def _GetPublicFiles():
    '''Gets all public file paths mapped to their contents.
  '''
    def walk(path, prefix=''):
        path = ChromiumPath(path)
        public_files = {}
        for root, dirs, files in os.walk(path, topdown=True):
            relative_root = root[len(path):].lstrip(os.path.sep)
            dirs[:] = _FilterHidden(dirs)
            for filename in _FilterHidden(files):
                with open(os.path.join(root, filename), 'r') as f:
                    request_path = posixpath.join(prefix, relative_root,
                                                  filename)
                    public_files[request_path] = f.read()
        return public_files

    # Public file locations are defined in content_providers.json, sort of. Epic
    # hack to pull them out; list all the files from the directories that
    # Chromium content providers ask for.
    public_files = {}
    content_providers = json_parse.Parse(ReadFile(CONTENT_PROVIDERS))
    for content_provider in content_providers.itervalues():
        if 'chromium' in content_provider:
            public_files.update(
                walk(content_provider['chromium']['dir'],
                     prefix=content_provider['serveFrom']))
    return public_files
Beispiel #7
0
 def testStaticFile(self):
     static_file = 'css/site.css'
     response = self._Render('static/%s' % static_file)
     self.assertEqual(200, response.status)
     self.assertEqual('text/css', response.headers.get('content-type'))
     self.assertEqual(ReadFile('docs/static/%s' % static_file),
                      response.content.ToString())
Beispiel #8
0
 def testStaticFile(self):
     static_file = 'css/out/site.css'
     response = self._Render('static/%s' % static_file)
     self.assertEqual(200, response.status)
     self.assertEqual('text/css; charset=utf-8',
                      response.headers['Content-Type'])
     self.assertEqual(ReadFile('%s%s' % (STATIC_DOCS, static_file)),
                      response.content.ToString())
 def testStaticFile(self):
     static_file = 'css/site.css'
     request = Request.ForTest('static/%s' % static_file)
     response = RenderServlet(request, _RenderServletDelegate()).Get()
     self.assertEqual(200, response.status)
     self.assertEqual('text/css', response.headers.get('content-type'))
     self.assertEqual(ReadFile('docs/static/%s' % static_file),
                      response.content.ToString())
 def testHtmlTemplate(self):
   html_file = 'extensions/storage'
   response = self._Render(html_file)
   self.assertEqual(200, response.status)
   self.assertEqual('text/html; charset=utf-8',
                    response.headers.get('Content-Type'))
   # Can't really test rendering all that well.
   self.assertTrue(len(response.content) >
                   len(ReadFile('%s%s.html' % (PUBLIC_TEMPLATES, html_file))))
Beispiel #11
0
 def testSampleFile(self):
     sample_file = 'extensions/talking_alarm_clock/background.js'
     response = self._Render('extensions/examples/%s' % sample_file)
     self.assertEqual(200, response.status)
     self.assertTrue(response.headers['Content-Type'] in (
         'application/javascript; charset=utf-8',
         'application/x-javascript; charset=utf-8'))
     self.assertEqual(ReadFile('%s%s' % (EXAMPLES, sample_file)),
                      response.content.ToString())
Beispiel #12
0
 def testHtmlTemplate(self):
     html_file = 'extensions/storage.html'
     response = self._Render(html_file)
     self.assertEqual(200, response.status)
     self.assertEqual('text/html', response.headers.get('content-type'))
     # Can't really test rendering all that well.
     self.assertTrue(
         len(response.content) > len(
             ReadFile('docs/templates/public/%s' % html_file)))
Beispiel #13
0
 def testSampleFile(self):
     sample_file = 'extensions/talking_alarm_clock/background.js'
     response = self._Render('extensions/examples/%s' % sample_file)
     self.assertEqual(200, response.status)
     content_type = response.headers.get('content-type')
     self.assertTrue(content_type == 'application/javascript'
                     or content_type == 'application/x-javascript')
     self.assertEqual(ReadFile('docs/examples/%s' % sample_file),
                      response.content.ToString())
Beispiel #14
0
 def testDirStat(self):
     file_system, fetcher = _CreateSubversionFileSystem(
         _SHARED_FILE_SYSTEM_TEST_DATA)
     stat_info = file_system.Stat('stat/')
     self.assertTrue(*fetcher.CheckAndReset(sync_count=1))
     expected = StatInfo('151113',
                         child_versions=json.loads(
                             ReadFile(SERVER2, 'test_data', 'file_system',
                                      'stat_result.json')))
     self.assertEqual(expected, stat_info)
Beispiel #15
0
 def fetch(self, url):
     path = _ExtractPathFromSvnUrl(url)
     if IsDirectory(path):
         html = ['<html>Revision 000000']
         try:
             for f in self._ListDir(ChromiumPath(path)):
                 if f.startswith('.'):
                     continue
                 if self._IsDir(ChromiumPath(path, f)):
                     html.append('<a>' + f + '/</a>')
                 else:
                     html.append('<a>' + f + '</a>')
             html.append('</html>')
             return '\n'.join(html)
         except OSError as e:
             return None
     try:
         return ReadFile(path)
     except IOError:
         return None
Beispiel #16
0
    def testSafeRevision(self):
        test_data = {
            'api': {
                '_api_features.json': '{}',
                '_manifest_features.json': '{}',
                '_permission_features.json': '{}',
            },
            'docs': {
                'examples': {
                    'examples.txt': 'examples.txt contents'
                },
                'server2': {
                    'app.yaml': AppYamlHelper.GenerateAppYaml('2-0-8')
                },
                'static': {
                    'static.txt': 'static.txt contents'
                },
                'templates': {
                    'public': {
                        'apps': {
                            'storage.html': 'storage.html contents'
                        },
                        'extensions': {
                            'storage.html': 'storage.html contents'
                        },
                    },
                    'json': {
                        'content_providers.json':
                        ReadFile('%s/content_providers.json' % JSON_PATH),
                        'manifest.json':
                        '{}',
                        'permissions.json':
                        '{}',
                        'strings.json':
                        '{}',
                        'apps_sidenav.json':
                        '{}',
                        'extensions_sidenav.json':
                        '{}',
                    },
                }
            }
        }

        updates = []

        def app_yaml_update(version):
            return {
                'docs': {
                    'server2': {
                        'app.yaml': AppYamlHelper.GenerateAppYaml(version)
                    }
                }
            }

        def storage_html_update(update):
            return {
                'docs': {
                    'templates': {
                        'public': {
                            'apps': {
                                'storage.html': update
                            }
                        }
                    }
                }
            }

        def static_txt_update(update):
            return {'docs': {'static': {'static.txt': update}}}

        app_yaml_path = 'docs/server2/app.yaml'
        storage_html_path = 'docs/templates/public/apps/storage.html'
        static_txt_path = 'docs/static/static.txt'

        def create_file_system(revision=None):
            '''Creates a MockFileSystem at |revision| by applying that many |updates|
      to it.
      '''
            mock_file_system = MockFileSystem(TestFileSystem(test_data))
            updates_for_revision = (updates if revision is None else
                                    updates[:int(revision)])
            for update in updates_for_revision:
                mock_file_system.Update(update)
            return mock_file_system

        delegate = _TestDelegate(create_file_system)
        delegate.SetAppVersion('2-0-8')

        file_systems = delegate.file_systems

        # No updates applied yet.
        CronServlet(Request.ForTest('trunk'), delegate_for_test=delegate).Get()
        self.assertEqual(AppYamlHelper.GenerateAppYaml('2-0-8'),
                         file_systems[-1].ReadSingle(app_yaml_path).Get())
        self.assertEqual('storage.html contents',
                         file_systems[-1].ReadSingle(storage_html_path).Get())

        # Apply updates to storage.html.
        updates.append(storage_html_update('interim contents'))
        updates.append(storage_html_update('new contents'))

        CronServlet(Request.ForTest('trunk'), delegate_for_test=delegate).Get()
        self.assertEqual(AppYamlHelper.GenerateAppYaml('2-0-8'),
                         file_systems[-1].ReadSingle(app_yaml_path).Get())
        self.assertEqual('new contents',
                         file_systems[-1].ReadSingle(storage_html_path).Get())

        # Apply several updates to storage.html and app.yaml. The file system
        # should be pinned at the version before app.yaml changed.
        updates.append(storage_html_update('stuck here contents'))

        double_update = storage_html_update('newer contents')
        double_update.update(app_yaml_update('2-0-10'))
        updates.append(double_update)

        updates.append(storage_html_update('never gonna reach here'))

        CronServlet(Request.ForTest('trunk'), delegate_for_test=delegate).Get()
        self.assertEqual(AppYamlHelper.GenerateAppYaml('2-0-8'),
                         file_systems[-1].ReadSingle(app_yaml_path).Get())
        self.assertEqual('stuck here contents',
                         file_systems[-1].ReadSingle(storage_html_path).Get())

        # Further pushes to storage.html will keep it pinned.
        updates.append(storage_html_update('y u not update!'))

        CronServlet(Request.ForTest('trunk'), delegate_for_test=delegate).Get()
        self.assertEqual(AppYamlHelper.GenerateAppYaml('2-0-8'),
                         file_systems[-1].ReadSingle(app_yaml_path).Get())
        self.assertEqual('stuck here contents',
                         file_systems[-1].ReadSingle(storage_html_path).Get())

        # Likewise app.yaml.
        updates.append(app_yaml_update('2-1-0'))

        CronServlet(Request.ForTest('trunk'), delegate_for_test=delegate).Get()
        self.assertEqual(AppYamlHelper.GenerateAppYaml('2-0-8'),
                         file_systems[-1].ReadSingle(app_yaml_path).Get())
        self.assertEqual('stuck here contents',
                         file_systems[-1].ReadSingle(storage_html_path).Get())

        # And updates to other content won't happen either.
        updates.append(static_txt_update('important content!'))

        CronServlet(Request.ForTest('trunk'), delegate_for_test=delegate).Get()
        self.assertEqual(AppYamlHelper.GenerateAppYaml('2-0-8'),
                         file_systems[-1].ReadSingle(app_yaml_path).Get())
        self.assertEqual('stuck here contents',
                         file_systems[-1].ReadSingle(storage_html_path).Get())
        self.assertEqual('static.txt contents',
                         file_systems[-1].ReadSingle(static_txt_path).Get())

        # Lastly - when the app version changes, everything should no longer be
        # pinned.
        delegate.SetAppVersion('2-1-0')
        CronServlet(Request.ForTest('trunk'), delegate_for_test=delegate).Get()
        self.assertEqual(AppYamlHelper.GenerateAppYaml('2-1-0'),
                         file_systems[-1].ReadSingle(app_yaml_path).Get())
        self.assertEqual('y u not update!',
                         file_systems[-1].ReadSingle(storage_html_path).Get())
        self.assertEqual('important content!',
                         file_systems[-1].ReadSingle(static_txt_path).Get())
Beispiel #17
0
def _ReadTestData(*path, **read_args):
    return ReadFile(SERVER2, 'test_data', *path, **read_args)
Beispiel #18
0
from extensions_paths import (API_PATHS, CHROME_API, CHROME_EXTENSIONS,
                              EXTENSIONS_API)
from features_bundle import FeaturesBundle
from file_system import FileNotFoundError
from mock_file_system import MockFileSystem
from object_store_creator import ObjectStoreCreator
from test_file_system import TestFileSystem
from test_util import ReadFile
from future import Future
from schema_processor import SchemaProcessorFactoryForTest

_TEST_DATA = {
    'api': {
        'devtools': {
            'inspected_window.json':
            ReadFile(CHROME_API, 'devtools', 'inspected_window.json'),
        },
        '_api_features.json':
        json.dumps({
            'alarms': {},
            'app': {},
            'app.runtime': {
                'noparent': True
            },
            'app.runtime.foo': {},
            'declarativeWebRequest': {},
            'devtools.inspectedWindow': {},
            'input': {},
            'input.ime': {},
            'storage': {},
        }),
Beispiel #19
0
def _ReadFile(*path):
    return ReadFile(SERVER2, 'test_data', 'template_data_source', *path)
Beispiel #20
0
import unittest

from api_models import APIModels
from compiled_file_system import CompiledFileSystem
from features_bundle import FeaturesBundle
from file_system import FileNotFoundError
from mock_file_system import MockFileSystem
from object_store_creator import ObjectStoreCreator
from test_file_system import TestFileSystem
from test_util import ReadFile

_TEST_DATA = {
    'api': {
        'devtools': {
            'inspected_window.json':
            ReadFile(os.path.join('api', 'devtools', 'inspected_window.json')),
        },
        '_api_features.json':
        json.dumps({
            'alarms': {},
            'app': {},
            'app.runtime': {
                'noparent': True
            },
            'app.runtime.experimental': {},
            'app.runtime.experimental.foo': {},
            'declarativeWebRequest': {},
            'devtools.inspectedWindow': {},
            'experimental.accessibility': {},
            'storage': {},
        }),
Beispiel #21
0
from api_models import APIModels
from compiled_file_system import CompiledFileSystem
from extensions_paths import API_PATHS, CHROME_API, CHROME_EXTENSIONS
from features_bundle import FeaturesBundle
from file_system import FileNotFoundError
from mock_file_system import MockFileSystem
from object_store_creator import ObjectStoreCreator
from test_file_system import TestFileSystem
from test_util import ReadFile

_TEST_DATA = {
    'api': {
        'devtools': {
            'inspected_window.json':
            ReadFile(CHROME_API, 'devtools', 'inspected_window.json'),
        },
        '_api_features.json':
        json.dumps({
            'alarms': {},
            'app': {},
            'app.runtime': {
                'noparent': True
            },
            'app.runtime.experimental': {},
            'app.runtime.experimental.foo': {},
            'declarativeWebRequest': {},
            'devtools.inspectedWindow': {},
            'experimental.accessibility': {},
            'storage': {},
        }),
# found in the LICENSE file.

import json
import unittest

from extensions_paths import CHROME_API, CHROME_EXTENSIONS
from mock_file_system import MockFileSystem
from server_instance import ServerInstance
from test_file_system import TestFileSystem
from test_util import ReadFile

_TEST_DATA = {
    'api': {
        'devtools': {
            'inspected_window.json':
            ReadFile(CHROME_API, 'devtools', 'inspected_window.json'),
        },
        '_api_features.json':
        json.dumps({
            'alarms': {},
            'app': {
                'extension_types': ['platform_app']
            },
            'app.runtime': {
                'noparent': True
            },
            'app.runtime.foo': {
                'extension_types': ['extension']
            },
            'declarativeWebRequest': {
                'extension_types': ['extension']
Beispiel #23
0
  def testSafeRevision(self):
    test_data = {
      'api': {
        '_api_features.json': '{}',
        '_manifest_features.json': '{}',
        '_permission_features.json': '{}',
      },
      'docs': {
        'examples': {
          'examples.txt': 'examples.txt contents'
        },
        'server2': {
          'app.yaml': AppYamlHelper.GenerateAppYaml('2-0-8')
        },
        'static': {
          'static.txt': 'static.txt contents'
        },
        'templates': {
          'articles': {
            'activeTab.html': 'activeTab.html contents'
          },
          'intros': {
            'browserAction.html': 'activeTab.html contents'
          },
          'private': {
            'table_of_contents.html': 'table_of_contents.html contents',
          },
          'public': {
            'apps': {
              'storage.html': '<h1>storage.html</h1> contents'
            },
            'extensions': {
              'storage.html': '<h1>storage.html</h1> contents'
            },
          },
          'json': {
            'chrome_sidenav.json': '{}',
            'content_providers.json': ReadFile(CONTENT_PROVIDERS),
            'manifest.json': '{}',
            'permissions.json': '{}',
            'strings.json': '{}',
            'whats_new.json': '{}',
          },
        }
      }
    }

    updates = []

    def app_yaml_update(version):
      return MoveTo(SERVER2, {
        'app.yaml': AppYamlHelper.GenerateAppYaml(version)
      })
    def storage_html_update(update):
      return MoveTo(PUBLIC_TEMPLATES, {
        'apps': {'storage.html': update}
      })
    def static_txt_update(update):
      return MoveTo(STATIC_DOCS, {
        'static.txt': update
      })

    storage_html_path = PUBLIC_TEMPLATES + 'apps/storage.html'
    static_txt_path = STATIC_DOCS + 'static.txt'

    def create_file_system(revision=None):
      '''Creates a MockFileSystem at |revision| by applying that many |updates|
      to it.
      '''
      mock_file_system = MockFileSystem(
          TestFileSystem(test_data, relative_to=CHROME_EXTENSIONS))
      updates_for_revision = (
          updates if revision is None else updates[:int(revision)])
      for update in updates_for_revision:
        mock_file_system.Update(update)
      return mock_file_system

    delegate = _TestDelegate(create_file_system)
    delegate.SetAppVersion('2-0-8')

    file_systems = delegate.file_systems

    # No updates applied yet.
    CronServlet(Request.ForTest('trunk'), delegate_for_test=delegate).Get()
    self.assertEqual(AppYamlHelper.GenerateAppYaml('2-0-8'),
                     file_systems[-1].ReadSingle(APP_YAML).Get())
    self.assertEqual('<h1>storage.html</h1> contents',
                     file_systems[-1].ReadSingle(storage_html_path).Get())

    # Apply updates to storage.html.
    updates.append(storage_html_update('interim contents'))
    updates.append(storage_html_update('<h1>new</h1> contents'))

    CronServlet(Request.ForTest('trunk'), delegate_for_test=delegate).Get()
    self.assertEqual(AppYamlHelper.GenerateAppYaml('2-0-8'),
                     file_systems[-1].ReadSingle(APP_YAML).Get())
    self.assertEqual('<h1>new</h1> contents',
                     file_systems[-1].ReadSingle(storage_html_path).Get())

    # Apply several updates to storage.html and app.yaml. The file system
    # should be pinned at the version before app.yaml changed.
    updates.append(storage_html_update('<h1>stuck here</h1> contents'))

    double_update = storage_html_update('<h1>newer</h1> contents')
    double_update.update(app_yaml_update('2-0-10'))
    updates.append(double_update)

    updates.append(storage_html_update('never gonna reach here'))

    CronServlet(Request.ForTest('trunk'), delegate_for_test=delegate).Get()
    self.assertEqual(AppYamlHelper.GenerateAppYaml('2-0-8'),
                     file_systems[-1].ReadSingle(APP_YAML).Get())
    self.assertEqual('<h1>stuck here</h1> contents',
                     file_systems[-1].ReadSingle(storage_html_path).Get())

    # Further pushes to storage.html will keep it pinned.
    updates.append(storage_html_update('<h1>y</h1> u not update!'))

    CronServlet(Request.ForTest('trunk'), delegate_for_test=delegate).Get()
    self.assertEqual(AppYamlHelper.GenerateAppYaml('2-0-8'),
                     file_systems[-1].ReadSingle(APP_YAML).Get())
    self.assertEqual('<h1>stuck here</h1> contents',
                     file_systems[-1].ReadSingle(storage_html_path).Get())

    # Likewise app.yaml.
    updates.append(app_yaml_update('2-1-0'))

    CronServlet(Request.ForTest('trunk'), delegate_for_test=delegate).Get()
    self.assertEqual(AppYamlHelper.GenerateAppYaml('2-0-8'),
                     file_systems[-1].ReadSingle(APP_YAML).Get())
    self.assertEqual('<h1>stuck here</h1> contents',
                     file_systems[-1].ReadSingle(storage_html_path).Get())

    # And updates to other content won't happen either.
    updates.append(static_txt_update('important content!'))

    CronServlet(Request.ForTest('trunk'), delegate_for_test=delegate).Get()
    self.assertEqual(AppYamlHelper.GenerateAppYaml('2-0-8'),
                     file_systems[-1].ReadSingle(APP_YAML).Get())
    self.assertEqual('<h1>stuck here</h1> contents',
                     file_systems[-1].ReadSingle(storage_html_path).Get())
    self.assertEqual('static.txt contents',
                     file_systems[-1].ReadSingle(static_txt_path).Get())

    # Lastly - when the app version changes, everything should no longer be
    # pinned.
    delegate.SetAppVersion('2-1-0')
    CronServlet(Request.ForTest('trunk'), delegate_for_test=delegate).Get()
    self.assertEqual(AppYamlHelper.GenerateAppYaml('2-1-0'),
                     file_systems[-1].ReadSingle(APP_YAML).Get())
    self.assertEqual('<h1>y</h1> u not update!',
                     file_systems[-1].ReadSingle(storage_html_path).Get())
    self.assertEqual('important content!',
                     file_systems[-1].ReadSingle(static_txt_path).Get())