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

Side by Side Diff: grit/gather/chrome_html_unittest.py

Issue 23591022: Make image set insertion work in more cases (Closed) Base URL: http://grit-i18n.googlecode.com/svn/trunk/
Patch Set: Created 7 years, 3 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/gather/chrome_html.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.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 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
239 } 239 }
240 </style> 240 </style>
241 </head> 241 </head>
242 <body> 242 <body>
243 <!-- Don't need a body. --> 243 <!-- Don't need a body. -->
244 </body> 244 </body>
245 </html> 245 </html>
246 ''')) 246 '''))
247 tmp_dir.CleanUp() 247 tmp_dir.CleanUp()
248 248
249 def testFileResourcesMultipleBackgrounds(self):
250 '''Tests inlined image file resources with two url()s.'''
251
252 tmp_dir = util.TempDir({
253 'test.css': '''
254 .image {
255 background: url(test.png), url(test.png);
256 }
257 ''',
258
259 'test.png': 'PNG DATA',
260
261 '2x/test.png': '2x PNG DATA',
262 })
263
264 html = chrome_html.ChromeHtml(tmp_dir.GetPath('test.css'))
265 html.SetDefines({'scale_factors': '2x'})
266 html.SetAttributes({'flattenhtml': 'true'})
267 html.Parse()
268 self.failUnlessEqual(StandardizeHtml(html.GetData('en', 'utf-8')),
269 StandardizeHtml('''
270 .image {
271 background: -webkit-image-set(url(data:image/png;base64,UE5HIERBVEE=) 1x , url(data:image/png;base64,MnggUE5HIERBVEE=) 2x), -webkit-image-set(url(data:im age/png;base64,UE5HIERBVEE=) 1x, url(data:image/png;base64,MnggUE5HIERBVEE=) 2x) ;
272 }
273 '''))
274 tmp_dir.CleanUp()
275
276 def testFileResourcesMultipleBackgroundsWithNewline1(self):
277 '''Tests inlined image file resources with line break after first url().'''
278
279 tmp_dir = util.TempDir({
280 'test.css': '''
281 .image {
282 background: url(test.png),
283 url(test.png);
284 }
285 ''',
286
287 'test.png': 'PNG DATA',
288
289 '2x/test.png': '2x PNG DATA',
290 })
291
292 html = chrome_html.ChromeHtml(tmp_dir.GetPath('test.css'))
293 html.SetDefines({'scale_factors': '2x'})
294 html.SetAttributes({'flattenhtml': 'true'})
295 html.Parse()
296 self.failUnlessEqual(StandardizeHtml(html.GetData('en', 'utf-8')),
297 StandardizeHtml('''
298 .image {
299 background: -webkit-image-set(url(data:image/png;base64,UE5HIERBVEE=) 1x , url(data:image/png;base64,MnggUE5HIERBVEE=) 2x),
300 -webkit-image-set(url(data:image/png;base64,UE5HIERBVEE=) 1x , url(data:image/png;base64,MnggUE5HIERBVEE=) 2x);
301 }
302 '''))
303 tmp_dir.CleanUp()
304
305 def testFileResourcesMultipleBackgroundsWithNewline2(self):
306 '''Tests inlined image file resources with line break before first url()
307 and before second url().'''
308
309 tmp_dir = util.TempDir({
310 'test.css': '''
311 .image {
312 background:
313 url(test.png),
314 url(test.png);
315 }
316 ''',
317
318 'test.png': 'PNG DATA',
319
320 '2x/test.png': '2x PNG DATA',
321 })
322
323 html = chrome_html.ChromeHtml(tmp_dir.GetPath('test.css'))
324 html.SetDefines({'scale_factors': '2x'})
325 html.SetAttributes({'flattenhtml': 'true'})
326 html.Parse()
327 self.failUnlessEqual(StandardizeHtml(html.GetData('en', 'utf-8')),
328 StandardizeHtml('''
329 .image {
330 background: -webkit-image-set(url(data:image/png;base64,UE5HIERBVEE=) 1x , url(data:image/png;base64,MnggUE5HIERBVEE=) 2x),
331 -webkit-image-set(url(data:image/png;base64,UE5HIERBVEE=) 1x, url(data :image/png;base64,MnggUE5HIERBVEE=) 2x);
332 }
333 '''))
334 tmp_dir.CleanUp()
335
336 def testFileResourcesCRLF(self):
337 '''Tests inlined image file resource when url() is preceded by a Windows
338 style line break.'''
339
340 tmp_dir = util.TempDir({
341 'test.css': '''
342 .image {
343 background:\r\nurl(test.png);
344 }
345 ''',
346
347 'test.png': 'PNG DATA',
348
349 '2x/test.png': '2x PNG DATA',
350 })
351
352 html = chrome_html.ChromeHtml(tmp_dir.GetPath('test.css'))
353 html.SetDefines({'scale_factors': '2x'})
354 html.SetAttributes({'flattenhtml': 'true'})
355 html.Parse()
356 self.failUnlessEqual(StandardizeHtml(html.GetData('en', 'utf-8')),
357 StandardizeHtml('''
358 .image {
359 background: -webkit-image-set(url(data:image/png;base64,UE5HIERBVEE=) 1x , url(data:image/png;base64,MnggUE5HIERBVEE=) 2x);
360 }
361 '''))
362 tmp_dir.CleanUp()
363
249 def testThemeResources(self): 364 def testThemeResources(self):
250 '''Tests inserting high DPI chrome://theme references.''' 365 '''Tests inserting high DPI chrome://theme references.'''
251 366
252 tmp_dir = util.TempDir({ 367 tmp_dir = util.TempDir({
253 'index.html': ''' 368 'index.html': '''
254 <!DOCTYPE HTML> 369 <!DOCTYPE HTML>
255 <html> 370 <html>
256 <head> 371 <head>
257 <link rel="stylesheet" href="test.css"> 372 <link rel="stylesheet" href="test.css">
258 </head> 373 </head>
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
399 <body> 514 <body>
400 <!-- Don't need a body. --> 515 <!-- Don't need a body. -->
401 </body> 516 </body>
402 </html> 517 </html>
403 ''')) 518 '''))
404 tmp_dir.CleanUp() 519 tmp_dir.CleanUp()
405 520
406 521
407 if __name__ == '__main__': 522 if __name__ == '__main__':
408 unittest.main() 523 unittest.main()
OLDNEW
« no previous file with comments | « grit/gather/chrome_html.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698