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

Unified Diff: grit/format/html_inline_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/format/html_inline.py ('k') | grit/gather/chrome_html.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: grit/format/html_inline_unittest.py
===================================================================
--- grit/format/html_inline_unittest.py (revision 124)
+++ grit/format/html_inline_unittest.py (working copy)
@@ -202,6 +202,66 @@
self.failUnlessEqual(expected_inlined,
util.FixLineEnd(result.inlined_data, '\n'))
+ def testFilenameVariableExpansion(self):
+ '''Tests that variables are expanded in filenames before inlining.'''
+ files = {
+ 'index.html': '''
+ <html>
+ <head>
+ <link rel="stylesheet" href="style[WHICH].css">
+ <script src="script[WHICH].js"></script>
+ </head>
+ <include src="tmpl[WHICH].html">
+ <img src="img[WHICH].png">
+ </html>
+ ''',
+ 'style1.css': '''h1 {}''',
+ 'tmpl1.html': '''<h1></h1>''',
+ 'script1.js': '''console.log('hello');''',
+ 'img1.png': '''abc''',
+ }
+
+ expected_inlined = '''
+ <html>
+ <head>
+ <style>h1 {}</style>
+ <script>console.log('hello');</script>
+ </head>
+ <h1></h1>
+ <img src="data:image/png;base64,YWJj">
+ </html>
+ '''
+
+ source_resources = set()
+ tmp_dir = util.TempDir(files)
+ for filename in files:
+ source_resources.add(tmp_dir.GetPath(filename))
+
+ def replacer(var, repl):
+ return lambda filename: filename.replace('[%s]' % var, repl)
+
+ # Test normal inlining.
+ result = html_inline.DoInline(
+ tmp_dir.GetPath('index.html'),
+ None,
+ filename_expansion_function=replacer('WHICH', '1'))
+ resources = result.inlined_files
+ resources.add(tmp_dir.GetPath('index.html'))
+ self.failUnlessEqual(resources, source_resources)
+ self.failUnlessEqual(expected_inlined,
+ util.FixLineEnd(result.inlined_data, '\n'))
+
+ # Test names-only inlining.
+ result = html_inline.DoInline(
+ tmp_dir.GetPath('index.html'),
+ None,
+ names_only=True,
+ filename_expansion_function=replacer('WHICH', '1'))
+ resources = result.inlined_files
+ resources.add(tmp_dir.GetPath('index.html'))
+ self.failUnlessEqual(resources, source_resources)
+
+
if __name__ == '__main__':
unittest.main()
« no previous file with comments | « grit/format/html_inline.py ('k') | grit/gather/chrome_html.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698