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.gather.chrome_html''' | 6 '''Unit tests for grit.gather.chrome_html''' |
7 | 7 |
8 | 8 |
9 import os | 9 import os |
10 import re | 10 import re |
(...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
338 } | 338 } |
339 </style> | 339 </style> |
340 </head> | 340 </head> |
341 <body> | 341 <body> |
342 <!-- Don't need a body. --> | 342 <!-- Don't need a body. --> |
343 </body> | 343 </body> |
344 </html> | 344 </html> |
345 ''')) | 345 ''')) |
346 tmp_dir.CleanUp() | 346 tmp_dir.CleanUp() |
347 | 347 |
| 348 def testExpandVariablesInFilename(self): |
| 349 ''' |
| 350 Tests variable substitution in filenames while flattening images |
| 351 with multiple scale factors. |
| 352 ''' |
| 353 |
| 354 tmp_dir = util.TempDir({ |
| 355 'index.html': ''' |
| 356 <!DOCTYPE HTML> |
| 357 <html> |
| 358 <head> |
| 359 <link rel="stylesheet" href="test.css"> |
| 360 </head> |
| 361 <body> |
| 362 <!-- Don't need a body. --> |
| 363 </body> |
| 364 </html> |
| 365 ''', |
| 366 |
| 367 'test.css': ''' |
| 368 .image { |
| 369 background: url('test[WHICH].png'); |
| 370 } |
| 371 ''', |
| 372 |
| 373 'test1.png': 'PNG DATA', |
| 374 '1.4x/test1.png': '1.4x PNG DATA', |
| 375 '1.8x/test1.png': '1.8x PNG DATA', |
| 376 }) |
| 377 |
| 378 def replacer(var, repl): |
| 379 return lambda filename: filename.replace('[%s]' % var, repl) |
| 380 |
| 381 html = chrome_html.ChromeHtml(tmp_dir.GetPath('index.html')) |
| 382 html.SetDefines({'scale_factors': '1.4x,1.8x'}) |
| 383 html.SetAttributes({'flattenhtml': 'true'}) |
| 384 html.SetFilenameExpansionFunction(replacer('WHICH', '1')); |
| 385 html.Parse() |
| 386 self.failUnlessEqual(StandardizeHtml(html.GetData('en', 'utf-8')), |
| 387 StandardizeHtml(''' |
| 388 <!DOCTYPE HTML> |
| 389 <html> |
| 390 <head> |
| 391 <style> |
| 392 .image { |
| 393 background: -webkit-image-set(url('data:image/png;base64,UE5HIERBVEE=')
1x, url('data:image/png;base64,MS40eCBQTkcgREFUQQ==') 1.4x, url('data:image/png;
base64,MS44eCBQTkcgREFUQQ==') 1.8x); |
| 394 } |
| 395 </style> |
| 396 </head> |
| 397 <body> |
| 398 <!-- Don't need a body. --> |
| 399 </body> |
| 400 </html> |
| 401 ''')) |
| 402 tmp_dir.CleanUp() |
| 403 |
| 404 |
348 if __name__ == '__main__': | 405 if __name__ == '__main__': |
349 unittest.main() | 406 unittest.main() |
OLD | NEW |