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 |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
59 public_files = {} | 59 public_files = {} |
60 for root, dirs, files in os.walk(path, topdown=True): | 60 for root, dirs, files in os.walk(path, topdown=True): |
61 relative_root = root[len(path):].lstrip(os.path.sep) | 61 relative_root = root[len(path):].lstrip(os.path.sep) |
62 dirs[:] = _FilterHidden(dirs) | 62 dirs[:] = _FilterHidden(dirs) |
63 for filename in _FilterHidden(files): | 63 for filename in _FilterHidden(files): |
64 with open(os.path.join(root, filename), 'r') as f: | 64 with open(os.path.join(root, filename), 'r') as f: |
65 request_path = posixpath.join(prefix, relative_root, filename) | 65 request_path = posixpath.join(prefix, relative_root, filename) |
66 public_files[request_path] = f.read() | 66 public_files[request_path] = f.read() |
67 return public_files | 67 return public_files |
68 | 68 |
69 # Public file locations are defined in content_providers.json, sort of. Epic | 69 # Public file locations are defined in content_providers.json, sort of. Epic |
70 # hack to pull them out; list all the files from the directories that | 70 # hack to pull them out; list all the files from the directories that |
71 # Chromium content providers ask for. | 71 # Chromium content providers ask for. |
72 public_files = {} | 72 public_files = {} |
73 content_providers = json_parse.Parse(ReadFile(CONTENT_PROVIDERS)) | 73 content_providers = json_parse.Parse(ReadFile(CONTENT_PROVIDERS)) |
74 for content_provider in content_providers.itervalues(): | 74 for content_provider in content_providers.itervalues(): |
75 if 'chromium' in content_provider: | 75 if 'chromium' in content_provider: |
76 public_files.update(walk(content_provider['chromium']['dir'], | 76 public_files.update(walk(content_provider['chromium']['dir'], |
77 prefix=content_provider['serveFrom'])) | 77 prefix=content_provider['serveFrom'])) |
78 return public_files | 78 return public_files |
79 | 79 |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
147 # print('Found %d orphaned pages:' % len(orphaned_pages)) | 147 # print('Found %d orphaned pages:' % len(orphaned_pages)) |
148 # for page in orphaned_pages: | 148 # for page in orphaned_pages: |
149 # print(page) | 149 # print(page) |
150 #print('Took %s seconds.' % (time.time() - start_time)) | 150 #print('Took %s seconds.' % (time.time() - start_time)) |
151 | 151 |
152 public_files = _GetPublicFiles() | 152 public_files = _GetPublicFiles() |
153 | 153 |
154 print('Rendering %s public files...' % len(public_files.keys())) | 154 print('Rendering %s public files...' % len(public_files.keys())) |
155 start_time = time.time() | 155 start_time = time.time() |
156 try: | 156 try: |
157 for path, content in public_files.iteritems(): | 157 for fs_path, content in public_files.iteritems(): |
158 AssertIsValid(path) | 158 AssertIsValid(fs_path) |
159 if path.endswith('redirects.json'): | 159 if fs_path.endswith('redirects.json'): |
160 continue | 160 continue |
161 | 161 |
| 162 path, ext = posixpath.splitext(fs_path) |
| 163 # Manually exclude examples because we still serve those with .html. |
| 164 if '/examples/' in path or ext not in ('.html', '.md'): |
| 165 path = fs_path |
| 166 |
162 def check_result(response): | 167 def check_result(response): |
163 self.assertEqual(200, response.status, | 168 self.assertEqual(200, response.status, |
164 'Got %s when rendering %s' % (response.status, path)) | 169 'Got %s when rendering %s' % (response.status, path)) |
165 # This is reaaaaally rough since usually these will be tiny templates | 170 # This is reaaaaally rough since usually these will be tiny templates |
166 # that render large files. At least it'll catch zero-length responses. | 171 # that render large files. At least it'll catch zero-length responses. |
167 self.assertTrue(len(response.content) >= len(content), | 172 self.assertTrue(len(response.content) >= len(content), |
168 'Rendered content length was %s vs template content length %s ' | 173 'Rendered content length was %s vs template content length %s ' |
169 'when rendering %s' % (len(response.content), len(content), path)) | 174 'when rendering %s' % (len(response.content), len(content), path)) |
170 | 175 |
171 check_result(Handler(Request.ForTest(path)).Get()) | 176 check_result(Handler(Request.ForTest(path)).Get()) |
172 | 177 |
173 if path.startswith(('apps/', 'extensions/')): | 178 if path.startswith(('apps/', 'extensions/')): |
174 # Make sure that leaving out the .html will temporarily redirect to | 179 # Make sure that adding the .html will temporarily redirect to |
175 # the path with the .html for APIs and articles. | 180 # the path without the .html for APIs and articles. |
176 if '/examples/' not in path: | 181 if '/examples/' not in path: |
177 base, _ = posixpath.splitext(path) | 182 redirect_response = Handler(Request.ForTest(path + '.html')).Get() |
178 self.assertEqual( | 183 self.assertEqual( |
179 ('/' + path, False), | 184 ('/' + path, False), redirect_response.GetRedirect(), |
180 Handler(Request.ForTest(base)).Get().GetRedirect(), | 185 '%s.html did not (temporarily) redirect to %s (status %s)' % |
181 '%s did not (temporarily) redirect to %s.html' % (path, path)) | 186 (path, path, redirect_response.status)) |
182 | 187 |
183 # Make sure including a channel will permanently redirect to the same | 188 # Make sure including a channel will permanently redirect to the same |
184 # path without a channel. | 189 # path without a channel. |
185 for channel in BranchUtility.GetAllChannelNames(): | 190 for channel in BranchUtility.GetAllChannelNames(): |
186 redirect_result = Handler( | 191 redirect_response = Handler( |
187 Request.ForTest(posixpath.join(channel, path))).Get() | 192 Request.ForTest(posixpath.join(channel, path))).Get() |
188 self.assertEqual( | 193 self.assertEqual( |
189 ('/' + path, True), | 194 ('/' + path, True), |
190 redirect_result.GetRedirect(), | 195 redirect_response.GetRedirect(), |
191 '%s did not redirect to strip channel %s' % (path, channel)) | 196 '%s/%s did not (permanently) redirect to %s (status %s)' % |
| 197 (channel, path, path, redirect_response.status)) |
192 | 198 |
193 # Samples are internationalized, test some locales. | 199 # Samples are internationalized, test some locales. |
194 if path.endswith('/samples.html'): | 200 if path.endswith('/samples'): |
195 for lang in ('en-US', 'es', 'ar'): | 201 for lang in ('en-US', 'es', 'ar'): |
196 check_result(Handler(Request.ForTest( | 202 check_result(Handler(Request.ForTest( |
197 path, | 203 path, |
198 headers={'Accept-Language': '%s;q=0.8' % lang})).Get()) | 204 headers={'Accept-Language': '%s;q=0.8' % lang})).Get()) |
199 finally: | 205 finally: |
200 print('Took %s seconds' % (time.time() - start_time)) | 206 print('Took %s seconds' % (time.time() - start_time)) |
201 | 207 |
202 #if _REBASE: | 208 #if _REBASE: |
203 # print('Rebasing broken links with %s newly broken and %s fixed links.' % | 209 # print('Rebasing broken links with %s newly broken and %s fixed links.' % |
204 # (len(newly_broken_links), len(fixed_links))) | 210 # (len(newly_broken_links), len(fixed_links))) |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
238 self.assertEqual(200, response.status) | 244 self.assertEqual(200, response.status) |
239 self.assertTrue(response.content != '') | 245 self.assertTrue(response.content != '') |
240 finally: | 246 finally: |
241 print('Took %s seconds' % (time.time() - start_time)) | 247 print('Took %s seconds' % (time.time() - start_time)) |
242 | 248 |
243 # TODO(jshumway): Check page for broken links (currently prohibited by the | 249 # TODO(jshumway): Check page for broken links (currently prohibited by the |
244 # time it takes to render the pages). | 250 # time it takes to render the pages). |
245 | 251 |
246 @DisableLogging('warning') | 252 @DisableLogging('warning') |
247 def testFileNotFound(self): | 253 def testFileNotFound(self): |
248 response = Handler(Request.ForTest('/extensions/notfound.html')).Get() | 254 response = Handler(Request.ForTest('/extensions/notfound')).Get() |
249 self.assertEqual(404, response.status) | 255 self.assertEqual(404, response.status) |
250 | 256 |
251 if __name__ == '__main__': | 257 if __name__ == '__main__': |
252 parser = optparse.OptionParser() | 258 parser = optparse.OptionParser() |
253 parser.add_option('-a', '--all', action='store_true', default=False, | 259 parser.add_option('-a', '--all', action='store_true', default=False, |
254 help='Render all pages, not just the one specified') | 260 help='Render all pages, not just the one specified') |
255 parser.add_option('-r', '--rebase', action='store_true', default=False, | 261 parser.add_option('-r', '--rebase', action='store_true', default=False, |
256 help='Rewrites the known_broken_links.json file with ' | 262 help='Rewrites the known_broken_links.json file with ' |
257 'the current set of broken links') | 263 'the current set of broken links') |
258 parser.add_option('-v', '--verbose', action='store_true', default=False, | 264 parser.add_option('-v', '--verbose', action='store_true', default=False, |
259 help='Show verbose output like currently broken links') | 265 help='Show verbose output like currently broken links') |
260 (opts, args) = parser.parse_args() | 266 (opts, args) = parser.parse_args() |
261 if not opts.all: | 267 if not opts.all: |
262 _EXPLICIT_TEST_FILES = args | 268 _EXPLICIT_TEST_FILES = args |
263 _REBASE = opts.rebase | 269 _REBASE = opts.rebase |
264 _VERBOSE = opts.verbose | 270 _VERBOSE = opts.verbose |
265 # Kill sys.argv because we have our own flags. | 271 # Kill sys.argv because we have our own flags. |
266 sys.argv = [sys.argv[0]] | 272 sys.argv = [sys.argv[0]] |
267 unittest.main() | 273 unittest.main() |
OLD | NEW |