Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(348)

Unified Diff: grit/gather/chrome_html_unittest.py

Issue 16539002: GRIT: Enable variable expansion in filenames during HTML inlining. (Closed) Base URL: https://chromium.googlesource.com/external/grit-i18n.git@master
Patch Set: Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « grit/gather/chrome_html.py ('k') | grit/gather/interface.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: grit/gather/chrome_html_unittest.py
===================================================================
--- grit/gather/chrome_html_unittest.py (revision 124)
+++ grit/gather/chrome_html_unittest.py (working copy)
@@ -345,5 +345,62 @@
'''))
tmp_dir.CleanUp()
+ def testExpandVariablesInFilename(self):
+ '''
+ Tests variable substitution in filenames while flattening images
+ with multiple scale factors.
+ '''
+
+ tmp_dir = util.TempDir({
+ 'index.html': '''
+ <!DOCTYPE HTML>
+ <html>
+ <head>
+ <link rel="stylesheet" href="test.css">
+ </head>
+ <body>
+ <!-- Don't need a body. -->
+ </body>
+ </html>
+ ''',
+
+ 'test.css': '''
+ .image {
+ background: url('test[WHICH].png');
+ }
+ ''',
+
+ 'test1.png': 'PNG DATA',
+ '1.4x/test1.png': '1.4x PNG DATA',
+ '1.8x/test1.png': '1.8x PNG DATA',
+ })
+
+ def replacer(var, repl):
+ return lambda filename: filename.replace('[%s]' % var, repl)
+
+ html = chrome_html.ChromeHtml(tmp_dir.GetPath('index.html'))
+ html.SetDefines({'scale_factors': '1.4x,1.8x'})
+ html.SetAttributes({'flattenhtml': 'true'})
+ html.SetFilenameExpansionFunction(replacer('WHICH', '1'));
+ html.Parse()
+ self.failUnlessEqual(StandardizeHtml(html.GetData('en', 'utf-8')),
+ StandardizeHtml('''
+ <!DOCTYPE HTML>
+ <html>
+ <head>
+ <style>
+ .image {
+ 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);
+ }
+ </style>
+ </head>
+ <body>
+ <!-- Don't need a body. -->
+ </body>
+ </html>
+ '''))
+ tmp_dir.CleanUp()
+
+
if __name__ == '__main__':
unittest.main()
« no previous file with comments | « grit/gather/chrome_html.py ('k') | grit/gather/interface.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698