OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 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 '''Unit tests for grit.format.html_inline''' | 6 '''Unit tests for grit.format.html_inline''' |
7 | 7 |
8 | 8 |
9 import os | 9 import os |
10 import re | 10 import re |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
195 for filename in files: | 195 for filename in files: |
196 source_resources.add(tmp_dir.GetPath(filename)) | 196 source_resources.add(tmp_dir.GetPath(filename)) |
197 | 197 |
198 result = html_inline.DoInline(tmp_dir.GetPath('index.html'), None) | 198 result = html_inline.DoInline(tmp_dir.GetPath('index.html'), None) |
199 resources = result.inlined_files | 199 resources = result.inlined_files |
200 resources.add(tmp_dir.GetPath('index.html')) | 200 resources.add(tmp_dir.GetPath('index.html')) |
201 self.failUnlessEqual(resources, source_resources) | 201 self.failUnlessEqual(resources, source_resources) |
202 self.failUnlessEqual(expected_inlined, | 202 self.failUnlessEqual(expected_inlined, |
203 util.FixLineEnd(result.inlined_data, '\n')) | 203 util.FixLineEnd(result.inlined_data, '\n')) |
204 | 204 |
| 205 def testFilenameVariableExpansion(self): |
| 206 '''Tests that variables are expanded in filenames before inlining.''' |
| 207 |
| 208 files = { |
| 209 'index.html': ''' |
| 210 <html> |
| 211 <head> |
| 212 <link rel="stylesheet" href="style[WHICH].css"> |
| 213 <script src="script[WHICH].js"></script> |
| 214 </head> |
| 215 <include src="tmpl[WHICH].html"> |
| 216 <img src="img[WHICH].png"> |
| 217 </html> |
| 218 ''', |
| 219 'style1.css': '''h1 {}''', |
| 220 'tmpl1.html': '''<h1></h1>''', |
| 221 'script1.js': '''console.log('hello');''', |
| 222 'img1.png': '''abc''', |
| 223 } |
| 224 |
| 225 expected_inlined = ''' |
| 226 <html> |
| 227 <head> |
| 228 <style>h1 {}</style> |
| 229 <script>console.log('hello');</script> |
| 230 </head> |
| 231 <h1></h1> |
| 232 <img src="data:image/png;base64,YWJj"> |
| 233 </html> |
| 234 ''' |
| 235 |
| 236 source_resources = set() |
| 237 tmp_dir = util.TempDir(files) |
| 238 for filename in files: |
| 239 source_resources.add(tmp_dir.GetPath(filename)) |
| 240 |
| 241 def replacer(var, repl): |
| 242 return lambda filename: filename.replace('[%s]' % var, repl) |
| 243 |
| 244 # Test normal inlining. |
| 245 result = html_inline.DoInline( |
| 246 tmp_dir.GetPath('index.html'), |
| 247 None, |
| 248 filename_expansion_function=replacer('WHICH', '1')) |
| 249 resources = result.inlined_files |
| 250 resources.add(tmp_dir.GetPath('index.html')) |
| 251 self.failUnlessEqual(resources, source_resources) |
| 252 self.failUnlessEqual(expected_inlined, |
| 253 util.FixLineEnd(result.inlined_data, '\n')) |
| 254 |
| 255 # Test names-only inlining. |
| 256 result = html_inline.DoInline( |
| 257 tmp_dir.GetPath('index.html'), |
| 258 None, |
| 259 names_only=True, |
| 260 filename_expansion_function=replacer('WHICH', '1')) |
| 261 resources = result.inlined_files |
| 262 resources.add(tmp_dir.GetPath('index.html')) |
| 263 self.failUnlessEqual(resources, source_resources) |
| 264 |
205 | 265 |
206 if __name__ == '__main__': | 266 if __name__ == '__main__': |
207 unittest.main() | 267 unittest.main() |
OLD | NEW |