| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright 2013 The Chromium Authors. All rights reserved. | 2 # Copyright 2013 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 # Run build_server so that files needed by tests are copied to the local | 6 # Run build_server so that files needed by tests are copied to the local |
| 7 # third_party directory. | 7 # third_party directory. |
| 8 import build_server | 8 import build_server |
| 9 build_server.main() | 9 build_server.main() |
| 10 | 10 |
| 11 import optparse | 11 import optparse |
| 12 import os | 12 import os |
| 13 import posixpath | 13 import posixpath |
| 14 import sys | 14 import sys |
| 15 import time | 15 import time |
| 16 import unittest | 16 import unittest |
| 17 | 17 |
| 18 from branch_utility import BranchUtility | 18 from branch_utility import BranchUtility |
| 19 from chroot_file_system import ChrootFileSystem |
| 20 from extensions_paths import EXTENSIONS, PUBLIC_TEMPLATES |
| 19 from link_error_detector import LinkErrorDetector, StringifyBrokenLinks | 21 from link_error_detector import LinkErrorDetector, StringifyBrokenLinks |
| 20 from local_file_system import LocalFileSystem | 22 from local_file_system import LocalFileSystem |
| 21 from local_renderer import LocalRenderer | 23 from local_renderer import LocalRenderer |
| 22 from fake_fetchers import ConfigureFakeFetchers | 24 from fake_fetchers import ConfigureFakeFetchers |
| 23 from handler import Handler | 25 from handler import Handler |
| 24 from servlet import Request | 26 from servlet import Request |
| 25 from test_util import EnableLogging, DisableLogging | 27 from test_util import EnableLogging, DisableLogging, ChromiumPath |
| 26 | 28 |
| 27 # Arguments set up if __main__ specifies them. | 29 # Arguments set up if __main__ specifies them. |
| 28 _EXPLICIT_TEST_FILES = None | 30 _EXPLICIT_TEST_FILES = None |
| 29 | 31 |
| 30 def _ToPosixPath(os_path): | 32 def _ToPosixPath(os_path): |
| 31 return os_path.replace(os.sep, '/') | 33 return os_path.replace(os.sep, '/') |
| 32 | 34 |
| 33 def _GetPublicFiles(): | 35 def _GetPublicFiles(): |
| 34 '''Gets all public files mapped to their contents. | 36 '''Gets all public files mapped to their contents. |
| 35 ''' | 37 ''' |
| 36 public_path = os.path.join(sys.path[0], os.pardir, 'templates', 'public') | 38 public_path = ChromiumPath(PUBLIC_TEMPLATES) |
| 37 public_files = {} | 39 public_files = {} |
| 38 for path, dirs, files in os.walk(public_path, topdown=True): | 40 for path, dirs, files in os.walk(public_path, topdown=True): |
| 39 dirs[:] = [d for d in dirs if d != '.svn'] | 41 dirs[:] = [d for d in dirs if d != '.svn'] |
| 40 relative_posix_path = _ToPosixPath(path[len(public_path):]) | 42 relative_posix_path = _ToPosixPath(path[len(public_path):]) |
| 41 for filename in files: | 43 for filename in files: |
| 42 with open(os.path.join(path, filename), 'r') as f: | 44 with open(os.path.join(path, filename), 'r') as f: |
| 43 public_files['/'.join((relative_posix_path, filename))] = f.read() | 45 public_files['/'.join((relative_posix_path, filename))] = f.read() |
| 44 return public_files | 46 return public_files |
| 45 | 47 |
| 46 class IntegrationTest(unittest.TestCase): | 48 class IntegrationTest(unittest.TestCase): |
| 47 def setUp(self): | 49 def setUp(self): |
| 48 ConfigureFakeFetchers() | 50 ConfigureFakeFetchers() |
| 49 | 51 |
| 50 @EnableLogging('info') | 52 @EnableLogging('info') |
| 51 def testCronAndPublicFiles(self): | 53 def testCronAndPublicFiles(self): |
| 52 '''Runs cron then requests every public file. Cron needs to be run first | 54 '''Runs cron then requests every public file. Cron needs to be run first |
| 53 because the public file requests are offline. | 55 because the public file requests are offline. |
| 54 ''' | 56 ''' |
| 55 if _EXPLICIT_TEST_FILES is not None: | 57 if _EXPLICIT_TEST_FILES is not None: |
| 56 return | 58 return |
| 57 | 59 |
| 58 print('Running cron...') | 60 print('Running cron...') |
| 59 start_time = time.time() | 61 start_time = time.time() |
| 60 try: | 62 try: |
| 61 response = Handler(Request.ForTest('/_cron/stable')).Get() | 63 response = Handler(Request.ForTest('/_cron')).Get() |
| 62 self.assertEqual(200, response.status) | 64 self.assertEqual(200, response.status) |
| 63 self.assertEqual('Success', response.content.ToString()) | 65 self.assertEqual('Success', response.content.ToString()) |
| 64 finally: | 66 finally: |
| 65 print('Took %s seconds' % (time.time() - start_time)) | 67 print('Took %s seconds' % (time.time() - start_time)) |
| 66 | 68 |
| 67 print("Checking for broken links...") | 69 print("Checking for broken links...") |
| 68 start_time = time.time() | 70 start_time = time.time() |
| 69 link_error_detector = LinkErrorDetector( | 71 link_error_detector = LinkErrorDetector( |
| 70 LocalFileSystem(os.path.join(sys.path[0], os.pardir, os.pardir)), | 72 # TODO(kalman): Use of ChrootFileSystem here indicates a hack. Fix. |
| 73 ChrootFileSystem(LocalFileSystem.Create(), EXTENSIONS), |
| 71 lambda path: Handler(Request.ForTest(path)).Get(), | 74 lambda path: Handler(Request.ForTest(path)).Get(), |
| 72 'templates/public', | 75 'templates/public', |
| 73 ('extensions/index.html', 'apps/about_apps.html')) | 76 ('extensions/index.html', 'apps/about_apps.html')) |
| 74 | 77 |
| 75 broken_links = link_error_detector.GetBrokenLinks() | 78 broken_links = link_error_detector.GetBrokenLinks() |
| 76 if broken_links: | 79 if broken_links: |
| 77 # TODO(jshumway): Test should fail when broken links are detected. | 80 # TODO(jshumway): Test should fail when broken links are detected. |
| 78 print('Warning: Found %d broken links:' % ( | 81 print('Warning: Found %d broken links:' % ( |
| 79 len(broken_links))) | 82 len(broken_links))) |
| 80 print(StringifyBrokenLinks(broken_links)) | 83 print(StringifyBrokenLinks(broken_links)) |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 159 | 162 |
| 160 if __name__ == '__main__': | 163 if __name__ == '__main__': |
| 161 parser = optparse.OptionParser() | 164 parser = optparse.OptionParser() |
| 162 parser.add_option('-a', '--all', action='store_true', default=False) | 165 parser.add_option('-a', '--all', action='store_true', default=False) |
| 163 (opts, args) = parser.parse_args() | 166 (opts, args) = parser.parse_args() |
| 164 if not opts.all: | 167 if not opts.all: |
| 165 _EXPLICIT_TEST_FILES = args | 168 _EXPLICIT_TEST_FILES = args |
| 166 # Kill sys.argv because we have our own flags. | 169 # Kill sys.argv because we have our own flags. |
| 167 sys.argv = [sys.argv[0]] | 170 sys.argv = [sys.argv[0]] |
| 168 unittest.main() | 171 unittest.main() |
| OLD | NEW |