Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / third_party / trace-viewer / third_party / tvcm / tvcm / style_sheet_unittest.py
1 # Copyright 2014 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
4 import base64
5 import unittest
6
7 from tvcm import style_sheet
8 from tvcm import project as project_module
9 from tvcm import resource_loader
10 from tvcm import fake_fs
11 from tvcm import module
12
13 class StyleSheetUnittest(unittest.TestCase):
14   def testImages(self):
15     fs = fake_fs.FakeFS()
16     fs.AddFile('/src/foo/x.css', """
17 .x .y {
18     background-image: url(../images/bar.jpeg);
19 }
20 """)
21     fs.AddFile('/src/images/bar.jpeg', 'hello world')
22     with fs:
23       project = project_module.Project(['/src/'],
24                                        include_tvcm_paths=False)
25       loader = resource_loader.ResourceLoader(project)
26
27       foo_x = loader.load_style_sheet('foo.x')
28       self.assertEquals(1, len(foo_x.images))
29
30       r0 = foo_x.images[0]
31       self.assertEquals('/src/images/bar.jpeg', r0.absolute_path)
32
33       inlined = foo_x.contents_with_inlined_images
34       self.assertEquals("""
35 .x .y {
36     background-image: url(data:image/jpeg;base64,%s);
37 }
38 """ % base64.standard_b64encode('hello world'), inlined)
39
40
41
42   def testURLResolveFails(self):
43     fs = fake_fs.FakeFS()
44     fs.AddFile('/src/foo/x.css', """
45 .x .y {
46     background-image: url(../images/missing.jpeg);
47 }
48 """)
49     with fs:
50       project = project_module.Project(['/src/'],
51                                        include_tvcm_paths=False)
52       loader = resource_loader.ResourceLoader(project)
53
54       self.assertRaises(module.DepsException,
55                         lambda: loader.load_style_sheet('foo.x'))