OLD | NEW |
1 # Copyright 2015 The Chromium Authors. All rights reserved. | 1 # Copyright 2015 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 import unittest | 5 import unittest |
| 6 |
6 import fieldtrial_util | 7 import fieldtrial_util |
| 8 import os |
7 import tempfile | 9 import tempfile |
8 | 10 |
9 | 11 |
10 class FieldTrialUtilUnittest(unittest.TestCase): | 12 class FieldTrialUtilUnittest(unittest.TestCase): |
11 | 13 |
12 def test_GenArgsEmptyPaths(self): | 14 def test_GenArgsEmptyPaths(self): |
13 args = fieldtrial_util.GenerateArgs('', '') | 15 args = fieldtrial_util.GenerateArgs('') |
14 self.assertEqual([], args) | 16 self.assertEqual([], args) |
15 | 17 |
16 def test_GenArgsOneConfig(self): | 18 def test_GenArgsOneConfig(self): |
17 with tempfile.NamedTemporaryFile('w') as base_file: | 19 with tempfile.NamedTemporaryFile('w', delete=False) as base_file: |
18 config = '''{ | 20 config = '''{ |
19 "BrowserBlackList": [ | 21 "BrowserBlackList": [ |
20 { "group_name": "Enabled" } | 22 { "group_name": "Enabled" } |
21 ], | 23 ], |
22 "c": [ | 24 "c": [ |
23 { | 25 { |
24 "group_name": "d.", | 26 "group_name": "d.", |
25 "params": {"url": "http://www.google.com"} | 27 "params": {"url": "http://www.google.com"} |
26 } | 28 } |
27 ], | 29 ], |
28 "SimpleParams": [ | 30 "SimpleParams": [ |
29 { | 31 { |
30 "group_name": "Default", | 32 "group_name": "Default", |
31 "params": {"id": "abc"} | 33 "params": {"id": "abc"} |
32 } | 34 } |
33 ] | 35 ] |
34 }''' | 36 }''' |
35 base_file.write(config) | 37 try: |
36 base_file.flush() | 38 base_file.write(config) |
37 | 39 base_file.close() |
38 result = fieldtrial_util.GenerateArgs(base_file.name) | 40 result = fieldtrial_util.GenerateArgs(base_file.name) |
39 self.assertEqual(['--force-fieldtrials=' | |
40 'BrowserBlackList/Enabled/c/d./SimpleParams/Default', | |
41 '--force-fieldtrial-params=' | |
42 'c.d%2E:url/http%3A%2F%2Fwww%2Egoogle%2Ecom,' | |
43 'SimpleParams.Default:id/abc'], result) | |
44 | |
45 def test_GenArgsOverrideConfig(self): | |
46 with tempfile.NamedTemporaryFile('w') as base_file: | |
47 config = '''{ | |
48 "a": [ | |
49 { "group_name": "b" } | |
50 ], | |
51 "c": [ | |
52 { "group_name": "d" } | |
53 ] | |
54 }''' | |
55 base_file.write(config) | |
56 base_file.flush() | |
57 with tempfile.NamedTemporaryFile('w') as platform_file: | |
58 config = '''{ | |
59 "a": [ | |
60 { "group_name": "1" } | |
61 ], | |
62 "b": [ | |
63 { "group_name": "bgroup" } | |
64 ] | |
65 }''' | |
66 platform_file.write(config) | |
67 platform_file.flush() | |
68 result = fieldtrial_util.GenerateArgs(base_file.name, | |
69 platform_file.name) | |
70 self.assertEqual(['--force-fieldtrials=' | 41 self.assertEqual(['--force-fieldtrials=' |
71 'a/1/c/d/b/bgroup'], result) | 42 'BrowserBlackList/Enabled/c/d./SimpleParams/Default', |
| 43 '--force-fieldtrial-params=' |
| 44 'c.d%2E:url/http%3A%2F%2Fwww%2Egoogle%2Ecom,' |
| 45 'SimpleParams.Default:id/abc'], result) |
| 46 finally: |
| 47 os.unlink(base_file.name) |
72 | 48 |
73 if __name__ == '__main__': | 49 if __name__ == '__main__': |
74 unittest.main() | 50 unittest.main() |
OLD | NEW |