Commit 7b6017ff authored by Peter Kasting's avatar Peter Kasting Committed by Commit Bot

Rewrite image URLs for preprocess=true.

We did this by default and for flattenhtml=true, but not when setting
preprocess=true.  This seems like an oversight.

Bug: 564112
Change-Id: Id3d6907e79be51ea2ce905e563f350fd0f882164
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1670353
Auto-Submit: Peter Kasting <pkasting@chromium.org>
Reviewed-by: default avatarRobert Flack <flackr@chromium.org>
Commit-Queue: Peter Kasting <pkasting@chromium.org>
Cr-Commit-Position: refs/heads/master@{#672120}
parent 86b00494
...@@ -502,10 +502,11 @@ def DoInline( ...@@ -502,10 +502,11 @@ def DoInline(
# of the text we just inlined. # of the text we just inlined.
flat_text = CheckConditionalElements(flat_text) flat_text = CheckConditionalElements(flat_text)
# Allow custom modifications before inlining images.
if rewrite_function:
flat_text = rewrite_function(input_filepath, flat_text, distribution)
if not preprocess_only: if not preprocess_only:
# Allow custom modifications before inlining images.
if rewrite_function:
flat_text = rewrite_function(input_filepath, flat_text, distribution)
flat_text = _SRC_RE.sub(SrcReplace, flat_text) flat_text = _SRC_RE.sub(SrcReplace, flat_text)
flat_text = _SRCSET_RE.sub(SrcsetReplace, flat_text) flat_text = _SRCSET_RE.sub(SrcsetReplace, flat_text)
......
...@@ -145,6 +145,36 @@ class ChromeHtmlUnittest(unittest.TestCase): ...@@ -145,6 +145,36 @@ class ChromeHtmlUnittest(unittest.TestCase):
''')) '''))
tmp_dir.CleanUp() tmp_dir.CleanUp()
def testFileResourcesPreprocess(self):
'''Tests preprocessed image file resources with available high DPI
assets.'''
tmp_dir = util.TempDir({
'test.css': '''
.image {
background: url('test.png');
}
''',
'test.png': 'PNG DATA',
'1.4x/test.png': '1.4x PNG DATA',
'1.8x/test.png': '1.8x PNG DATA',
})
html = chrome_html.ChromeHtml(tmp_dir.GetPath('test.css'))
html.SetDefines({'scale_factors': '1.4x,1.8x'})
html.SetAttributes({'flattenhtml': 'false', 'preprocess': 'true'})
html.Parse()
self.failUnlessEqual(StandardizeHtml(html.GetData('en', 'utf-8')),
StandardizeHtml('''
.image {
background: -webkit-image-set(url('test.png') 1x, url('1.4x/test.png') 1.4x, url('1.8x/test.png') 1.8x);
}
'''))
tmp_dir.CleanUp()
def testFileResourcesDoubleQuotes(self): def testFileResourcesDoubleQuotes(self):
'''Tests inlined image file resources if url() filename is double quoted.''' '''Tests inlined image file resources if url() filename is double quoted.'''
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment