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

Side by Side Diff: grit/format/html_inline_unittest.py

Issue 12261055: Correctly resolve relative paths when inlining @import directives in CSS files. (Closed) Base URL: https://grit-i18n.googlecode.com/svn/trunk
Patch Set: Created 7 years, 10 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « grit/format/html_inline.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 tmp_dir.CleanUp() 84 tmp_dir.CleanUp()
85 85
86 def testInlineCSSImports(self): 86 def testInlineCSSImports(self):
87 '''Tests that @import directives in inlined CSS files are inlined too. 87 '''Tests that @import directives in inlined CSS files are inlined too.
88 ''' 88 '''
89 89
90 files = { 90 files = {
91 'index.html': ''' 91 'index.html': '''
92 <html> 92 <html>
93 <head> 93 <head>
94 <link rel="stylesheet" href="test.css"> 94 <link rel="stylesheet" href="css/test.css">
95 </head> 95 </head>
96 </html> 96 </html>
97 ''', 97 ''',
98 98
99 'test.css': ''' 99 'css/test.css': '''
100 @import url('test2.css') 100 @import url('test2.css');
101 blink { 101 blink {
102 display: none; 102 display: none;
103 } 103 }
104 ''', 104 ''',
105 105
106 'test2.css': ''' 106 'css/test2.css': '''
107 .image { 107 .image {
108 background: url('test.png'); 108 background: url('../images/test.png');
109 } 109 }
110 '''.strip(), 110 '''.strip(),
111 111
112 'test.png': 'PNG DATA' 112 'images/test.png': 'PNG DATA'
113 } 113 }
114 114
115 expected_inlined = ''' 115 expected_inlined = '''
116 <html> 116 <html>
117 <head> 117 <head>
118 <style> 118 <style>
119 .image { 119 .image {
120 background: url('data:image/png;base64,UE5HIERBVEE='); 120 background: url('data:image/png;base64,UE5HIERBVEE=');
121 } 121 }
122 blink { 122 blink {
(...skipping 10 matching lines...) Expand all
133 source_resources.add(tmp_dir.GetPath(filename)) 133 source_resources.add(tmp_dir.GetPath(filename))
134 134
135 result = html_inline.DoInline(tmp_dir.GetPath('index.html'), None) 135 result = html_inline.DoInline(tmp_dir.GetPath('index.html'), None)
136 resources = result.inlined_files 136 resources = result.inlined_files
137 resources.add(tmp_dir.GetPath('index.html')) 137 resources.add(tmp_dir.GetPath('index.html'))
138 self.failUnlessEqual(resources, source_resources) 138 self.failUnlessEqual(resources, source_resources)
139 self.failUnlessEqual(expected_inlined, result.inlined_data) 139 self.failUnlessEqual(expected_inlined, result.inlined_data)
140 140
141 tmp_dir.CleanUp() 141 tmp_dir.CleanUp()
142 142
143 def testInlineCSSLinks(self):
144 '''Tests that only CSS files referenced via relative URLs are inlined.'''
145
146 files = {
147 'index.html': '''
148 <html>
149 <head>
150 <link rel="stylesheet" href="foo.css">
151 <link rel="stylesheet" href="chrome://resources/bar.css">
152 </head>
153 </html>
154 ''',
155
156 'foo.css': '''
157 @import url(chrome://resources/blurp.css);
158 blink {
159 display: none;
160 }
161 ''',
162 }
163
164 expected_inlined = '''
165 <html>
166 <head>
167 <style>
168 @import url(chrome://resources/blurp.css);
169 blink {
170 display: none;
171 }
172 </style>
173 <link rel="stylesheet" href="chrome://resources/bar.css">
174 </head>
175 </html>
176 '''
177
178 source_resources = set()
179 tmp_dir = util.TempDir(files)
180 for filename in files:
181 source_resources.add(tmp_dir.GetPath(filename))
182
183 result = html_inline.DoInline(tmp_dir.GetPath('index.html'), None)
184 resources = result.inlined_files
185 resources.add(tmp_dir.GetPath('index.html'))
186 self.failUnlessEqual(resources, source_resources)
187 self.failUnlessEqual(expected_inlined, result.inlined_data)
188
143 189
144 if __name__ == '__main__': 190 if __name__ == '__main__':
145 unittest.main() 191 unittest.main()
OLDNEW
« no previous file with comments | « grit/format/html_inline.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698