OLD | NEW |
---|---|
(Empty) | |
1 #!/usr/bin/env python2 | |
2 # -*- coding: utf-8 -*- | |
3 | |
4 # Copyright 2016 Google Inc. All Rights Reserved. | |
5 # | |
6 # Licensed under the Apache License, Version 2.0 (the "License"); | |
7 # you may not use this file except in compliance with the License. | |
8 # You may obtain a copy of the License at | |
9 # | |
10 # http://www.apache.org/licenses/LICENSE-2.0 | |
11 # | |
12 # Unless required by applicable law or agreed to in writing, software | |
13 # distributed under the License is distributed on an "AS IS" BASIS, | |
14 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
15 # See the License for the specific language governing permissions and | |
16 # limitations under the License. | |
17 | |
18 """Unit-test chrome_app.apis.""" | |
19 | |
20 from __future__ import print_function, division, unicode_literals | |
Matt Giuca
2016/02/11 02:17:12
This test file doesn't belong in a bugfix CL.
Can
| |
21 | |
22 import collections | |
23 import os | |
24 import sys | |
25 import unittest | |
26 | |
27 import mock | |
28 | |
29 import caterpillar_test | |
30 import chrome_app.apis | |
31 | |
32 ROOT_DIR = os.path.dirname(os.path.dirname(os.path.realpath(__file__))) | |
33 | |
34 class TestApiMemberUsed(unittest.TestCase): | |
35 """Tests api_member_used.""" | |
36 | |
37 def test_no_member(self): | |
38 """Tests that if there is no member, None is returned.""" | |
39 line = 'hello world, this is some téśt data!' | |
40 member = chrome_app.apis.api_member_used(line) | |
41 self.assertIsNone(member) | |
42 | |
43 line = 'hello world, this is some téśt data!' | |
44 member = chrome_app.apis.api_member_used(line) | |
45 self.assertIsNone(member) | |
46 | |
47 def test_api_member(self): | |
48 """Tests that a member is picked up in the input string.""" | |
49 line = 'hello world, this test data uses chrome.tts.speak, test test.' | |
50 member = chrome_app.apis.api_member_used(line) | |
51 self.assertEqual(member, 'tts.speak') | |
52 | |
53 line = 'this test data uses chrome.app.runtime.onLaunched, test test.' | |
54 member = chrome_app.apis.api_member_used(line) | |
55 self.assertEqual(member, 'app.runtime.onLaunched') | |
56 | |
57 def test_chrome_url(self): | |
58 """Tests that chrome.google.com is not picked up as an API.""" | |
59 line = 'test test chrome.google.com test test' | |
60 member = chrome_app.apis.api_member_used(line) | |
61 self.assertIsNone(member) | |
62 | |
63 | |
64 class TestAppApis(caterpillar_test.TestCaseWithOutputDir): | |
65 """Tests app_apis.""" | |
66 | |
67 def test_correct_output(self): | |
68 apis = chrome_app.apis.app_apis(self.output_path) | |
69 self.assertEqual(apis, [ | |
70 'app.runtime', | |
71 'app.window', | |
72 'power', | |
73 ]) | |
74 | |
75 | |
76 class TestUsage(caterpillar_test.TestCaseWithOutputDir): | |
77 """Tests usage.""" | |
78 | |
79 def test_no_apis(self): | |
80 """Tests that if no APIs are provided, no usages are found.""" | |
81 usage = chrome_app.apis.usage([], self.output_path) | |
82 self.assertEqual(usage, {}) | |
83 | |
84 def test_correct_output(self): | |
85 self.maxDiff = None | |
86 usage = chrome_app.apis.usage(['app.runtime', 'app.window', 'power'], | |
87 self.output_path) | |
88 self.assertEqual(usage, { | |
89 'app.runtime': collections.defaultdict(list, {'onLaunched.addListener': [( | |
90 'my scrípt.js', 0, | |
91 """chrome.app.runtime.onLaunched.addListener(function() { | |
92 chrome.app.window.create('my índex.html'); | |
93 }); | |
94 """, 0)]}), | |
95 'app.window': collections.defaultdict(list, {'create': [( | |
96 'my scrípt.js', 1, | |
97 """chrome.app.runtime.onLaunched.addListener(function() { | |
98 chrome.app.window.create('my índex.html'); | |
99 }); | |
100 """, 0)]}), | |
101 'power': collections.defaultdict(list, {'requestKeepAwake': [( | |
102 'mý other script.js', 1, | |
103 """// keep awakes | |
104 chrome.power.requestKeepAwake(); | |
105 // the user is now awake | |
106 notAChromeAppCall(); | |
107 """, 0)]}), | |
108 }) | |
109 | |
110 | |
111 if __name__ == '__main__': | |
112 unittest.main() | |
OLD | NEW |