Chromium Code Reviews| 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 json | 11 import json |
| 12 import optparse | 12 import optparse |
| 13 import os | 13 import os |
| 14 import posixpath | 14 import posixpath |
| 15 import sys | 15 import sys |
| 16 import time | 16 import time |
| 17 import unittest | 17 import unittest |
| 18 | 18 |
| 19 from branch_utility import BranchUtility | 19 from branch_utility import BranchUtility |
| 20 from chroot_file_system import ChrootFileSystem | 20 from chroot_file_system import ChrootFileSystem |
| 21 from extensions_paths import EXTENSIONS, PUBLIC_TEMPLATES | 21 from extensions_paths import CONTENT_PROVIDERS, EXTENSIONS, PUBLIC_TEMPLATES |
| 22 from fake_fetchers import ConfigureFakeFetchers | 22 from fake_fetchers import ConfigureFakeFetchers |
| 23 from third_party.json_schema_compiler import json_parse | |
| 23 from handler import Handler | 24 from handler import Handler |
| 24 from link_error_detector import LinkErrorDetector, StringifyBrokenLinks | 25 from link_error_detector import LinkErrorDetector, StringifyBrokenLinks |
| 25 from local_file_system import LocalFileSystem | 26 from local_file_system import LocalFileSystem |
| 26 from local_renderer import LocalRenderer | 27 from local_renderer import LocalRenderer |
| 27 from servlet import Request | 28 from servlet import Request |
| 28 from test_util import EnableLogging, DisableLogging, ChromiumPath | 29 from test_util import ChromiumPath, DisableLogging, EnableLogging, ReadFile |
| 30 | |
| 29 | 31 |
| 30 # Arguments set up if __main__ specifies them. | 32 # Arguments set up if __main__ specifies them. |
| 31 _EXPLICIT_TEST_FILES = None | 33 _EXPLICIT_TEST_FILES = None |
| 32 _REBASE = False | 34 _REBASE = False |
| 33 _VERBOSE = False | 35 _VERBOSE = False |
| 34 | 36 |
| 35 | 37 |
| 36 def _ToPosixPath(os_path): | 38 def _ToPosixPath(os_path): |
| 37 return os_path.replace(os.sep, '/') | 39 return os_path.replace(os.sep, '/') |
| 38 | 40 |
| 41 | |
| 39 def _GetPublicFiles(): | 42 def _GetPublicFiles(): |
| 40 '''Gets all public files mapped to their contents. | 43 '''Gets all public file paths mapped to their contents. |
| 41 ''' | 44 ''' |
| 42 public_path = ChromiumPath(PUBLIC_TEMPLATES) | 45 def walk(path, prefix=''): |
| 46 path = ChromiumPath(path) | |
| 47 public_files = {} | |
| 48 for root, dirs, files in os.walk(path, topdown=True): | |
| 49 relative_root = root[len(path):].lstrip(os.path.sep) | |
| 50 dirs[:] = [d for d in dirs if not d.startswith('.')] | |
|
Yoyo Zhou
2014/02/04 00:48:42
Do you need to check if any of the path components
not at google - send to devlin
2014/02/04 21:29:49
These . checks are actually for hidden files. I'll
| |
| 51 files[:] = [f for f in files if not f.startswith('.')] | |
| 52 for filename in files: | |
| 53 with open(os.path.join(root, filename), 'r') as f: | |
| 54 request_path = posixpath.join(prefix, relative_root, filename) | |
| 55 public_files[request_path] = f.read() | |
| 56 return public_files | |
| 57 | |
| 58 # Public file locations are defined in content_providers.json, sort of. Epic | |
| 59 # hack to pull them out; list all the files from the directories that | |
| 60 # Chromium content providers ask for. | |
| 43 public_files = {} | 61 public_files = {} |
| 44 for path, dirs, files in os.walk(public_path, topdown=True): | 62 content_providers = json_parse.Parse(ReadFile(CONTENT_PROVIDERS)) |
| 45 dirs[:] = [d for d in dirs if d != '.svn'] | 63 for content_provider in content_providers.itervalues(): |
| 46 relative_posix_path = _ToPosixPath(path[len(public_path):]) | 64 if 'chromium' in content_provider: |
| 47 for filename in files: | 65 public_files.update(walk(content_provider['chromium']['dir'], |
| 48 with open(os.path.join(path, filename), 'r') as f: | 66 prefix=content_provider['serveFrom'])) |
| 49 public_files['/'.join((relative_posix_path, filename))] = f.read() | |
| 50 return public_files | 67 return public_files |
| 51 | 68 |
| 69 | |
| 52 class IntegrationTest(unittest.TestCase): | 70 class IntegrationTest(unittest.TestCase): |
| 53 def setUp(self): | 71 def setUp(self): |
| 54 ConfigureFakeFetchers() | 72 ConfigureFakeFetchers() |
| 55 | 73 |
| 56 @EnableLogging('info') | 74 @EnableLogging('info') |
| 57 def testCronAndPublicFiles(self): | 75 def testCronAndPublicFiles(self): |
| 58 '''Runs cron then requests every public file. Cron needs to be run first | 76 '''Runs cron then requests every public file. Cron needs to be run first |
| 59 because the public file requests are offline. | 77 because the public file requests are offline. |
| 60 ''' | 78 ''' |
| 61 if _EXPLICIT_TEST_FILES is not None: | 79 if _EXPLICIT_TEST_FILES is not None: |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 116 # for page in orphaned_pages: | 134 # for page in orphaned_pages: |
| 117 # print(page) | 135 # print(page) |
| 118 #print('Took %s seconds.' % (time.time() - start_time)) | 136 #print('Took %s seconds.' % (time.time() - start_time)) |
| 119 | 137 |
| 120 public_files = _GetPublicFiles() | 138 public_files = _GetPublicFiles() |
| 121 | 139 |
| 122 print('Rendering %s public files...' % len(public_files.keys())) | 140 print('Rendering %s public files...' % len(public_files.keys())) |
| 123 start_time = time.time() | 141 start_time = time.time() |
| 124 try: | 142 try: |
| 125 for path, content in public_files.iteritems(): | 143 for path, content in public_files.iteritems(): |
| 126 assert path.startswith('/') | 144 assert not path.startswith('/') |
| 127 if path.endswith('redirects.json'): | 145 if path.endswith('redirects.json'): |
| 128 continue | 146 continue |
| 129 | 147 |
| 130 def check_result(response): | 148 def check_result(response): |
| 131 self.assertEqual(200, response.status, | 149 self.assertEqual(200, response.status, |
| 132 'Got %s when rendering %s' % (response.status, path)) | 150 'Got %s when rendering %s' % (response.status, path)) |
| 133 # This is reaaaaally rough since usually these will be tiny templates | 151 # This is reaaaaally rough since usually these will be tiny templates |
| 134 # that render large files. At least it'll catch zero-length responses. | 152 # that render large files. At least it'll catch zero-length responses. |
| 135 self.assertTrue(len(response.content) >= len(content), | 153 self.assertTrue(len(response.content) >= len(content), |
| 136 'Content was "%s" when rendering %s' % (response.content, path)) | 154 'Rendered content length was %s vs template content length %s ' |
| 155 'when rendering %s' % (len(response.content), len(content), path)) | |
| 137 | 156 |
| 138 check_result(Handler(Request.ForTest(path)).Get()) | 157 check_result(Handler(Request.ForTest(path)).Get()) |
| 139 | 158 |
| 140 # Make sure that leaving out the .html will temporarily redirect to the | 159 if path.startswith(('apps/', 'extensions/')): |
| 141 # path with the .html. | 160 # Make sure that leaving out the .html will temporarily redirect to |
| 142 if path.startswith(('/apps/', '/extensions/')): | 161 # the path with the .html for APIs and articles. |
| 143 redirect_result = Handler( | 162 if '/examples/' not in path: |
| 144 Request.ForTest(posixpath.splitext(path)[0])).Get() | 163 base, _ = posixpath.splitext(path) |
| 145 self.assertEqual((path, False), redirect_result.GetRedirect()) | 164 self.assertEqual(('/' + path, False), |
| 165 Handler(Request.ForTest(base)).Get().GetRedirect(), | |
| 166 path) | |
|
Yoyo Zhou
2014/02/04 00:48:42
If path is a message, it should have some ... mess
not at google - send to devlin
2014/02/04 21:29:49
Done.
| |
| 146 | 167 |
| 147 # Make sure including a channel will permanently redirect to the same | 168 # Make sure including a channel will permanently redirect to the same |
| 148 # path without a channel. | 169 # path without a channel. |
| 149 for channel in BranchUtility.GetAllChannelNames(): | 170 for channel in BranchUtility.GetAllChannelNames(): |
| 150 redirect_result = Handler( | 171 redirect_result = Handler( |
| 151 Request.ForTest('%s%s' % (channel, path))).Get() | 172 Request.ForTest(posixpath.join(channel, path))).Get() |
| 152 self.assertEqual((path, True), redirect_result.GetRedirect()) | 173 self.assertEqual(('/' + path, True), redirect_result.GetRedirect()) |
| 153 | 174 |
| 154 # Samples are internationalized, test some locales. | 175 # Samples are internationalized, test some locales. |
| 155 if path.endswith('/samples.html'): | 176 if path.endswith('/samples.html'): |
| 156 for lang in ['en-US', 'es', 'ar']: | 177 for lang in ('en-US', 'es', 'ar'): |
| 157 check_result(Handler(Request.ForTest( | 178 check_result(Handler(Request.ForTest( |
| 158 path, | 179 path, |
| 159 headers={'Accept-Language': '%s;q=0.8' % lang})).Get()) | 180 headers={'Accept-Language': '%s;q=0.8' % lang})).Get()) |
| 160 finally: | 181 finally: |
| 161 print('Took %s seconds' % (time.time() - start_time)) | 182 print('Took %s seconds' % (time.time() - start_time)) |
| 162 | 183 |
| 163 #if _REBASE: | 184 #if _REBASE: |
| 164 # print('Rebasing broken links with %s newly broken and %s fixed links.' % | 185 # print('Rebasing broken links with %s newly broken and %s fixed links.' % |
| 165 # (len(newly_broken_links), len(fixed_links))) | 186 # (len(newly_broken_links), len(fixed_links))) |
| 166 # with open(known_broken_links_path, 'w') as f: | 187 # with open(known_broken_links_path, 'w') as f: |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 219 parser.add_option('-v', '--verbose', action='store_true', default=False, | 240 parser.add_option('-v', '--verbose', action='store_true', default=False, |
| 220 help='Show verbose output like currently broken links') | 241 help='Show verbose output like currently broken links') |
| 221 (opts, args) = parser.parse_args() | 242 (opts, args) = parser.parse_args() |
| 222 if not opts.all: | 243 if not opts.all: |
| 223 _EXPLICIT_TEST_FILES = args | 244 _EXPLICIT_TEST_FILES = args |
| 224 _REBASE = opts.rebase | 245 _REBASE = opts.rebase |
| 225 _VERBOSE = opts.verbose | 246 _VERBOSE = opts.verbose |
| 226 # Kill sys.argv because we have our own flags. | 247 # Kill sys.argv because we have our own flags. |
| 227 sys.argv = [sys.argv[0]] | 248 sys.argv = [sys.argv[0]] |
| 228 unittest.main() | 249 unittest.main() |
| OLD | NEW |