Upstream version 5.34.92.0
[platform/framework/web/crosswalk.git] / src / third_party / trace-viewer / third_party / tvcm / tvcm / resource_finder_unittest.py
1 #!/usr/bin/env python
2 # Copyright 2013 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file.
5 """Tests for resource_finder."""
6
7 import os
8 import unittest
9
10 import module
11 import resource_finder
12
13 SRC_DIR = os.path.join(os.path.dirname(__file__), '../../../src')
14
15
16 class ResourceFinderTest(unittest.TestCase):
17
18   def test_basic(self):
19     finder = resource_finder.ResourceFinder([SRC_DIR])
20     guid_module = module.Module('guid')
21     guid_module.load_and_parse(os.path.join(SRC_DIR, 'base', 'guid.js'))
22     filename, contents = finder.find_and_load_module(guid_module, 'base')
23
24     self.assertTrue(os.path.samefile(filename,
25                                      os.path.join(SRC_DIR, 'base.js')))
26     expected_contents = ''
27     with open(os.path.join(SRC_DIR, 'base.js')) as f:
28       expected_contents = f.read()
29     self.assertEquals(contents, expected_contents)
30
31   def test_dependency_in_subdir(self):
32     finder = resource_finder.ResourceFinder([SRC_DIR])
33     guid_module = module.Module('base.guid')
34     guid_module.load_and_parse(os.path.join(SRC_DIR, 'base', 'guid.js'))
35     filename, contents = finder.find_and_load_module(
36         guid_module, 'tracing.tracks.track')
37
38     assert filename
39
40     self.assertTrue(os.path.samefile(filename, os.path.join(
41       SRC_DIR, 'tracing', 'tracks', 'track.js')))
42     expected_contents = ''
43     with open(os.path.join(SRC_DIR, 'tracing', 'tracks', 'track.js')) as f:
44       expected_contents = f.read()
45     self.assertEquals(contents, expected_contents)
46
47
48 if __name__ == '__main__':
49   unittest.main()