Fix breakages in https://codereview.chromium.org/1155713003/
[chromium-blink-merge.git] / tools / variations / fieldtrial_util_unittest.py
blob1df6383e2201dc6ea91bf56c2910dc4f4479d40e
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
3 # found in the LICENSE file.
5 import unittest
6 import fieldtrial_util
7 import tempfile
10 class FieldTrialUtilUnittest(unittest.TestCase):
12 def test_GenArgsEmptyPaths(self):
13 args = fieldtrial_util.GenerateArgs('', '')
14 self.assertEqual([], args)
16 def test_GenArgsOneConfig(self):
17 with tempfile.NamedTemporaryFile('w') as base_file:
18 config = '''{
19 "BrowserBlackList": [
20 { "group_name": "Enabled" }
22 "c": [
24 "group_name": "d.",
25 "params": {"url": "http://www.google.com"}
28 "SimpleParams": [
30 "group_name": "Default",
31 "params": {"id": "abc"}
34 }'''
35 base_file.write(config)
36 base_file.flush()
38 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)
45 def test_GenArgsOverrideConfig(self):
46 with tempfile.NamedTemporaryFile('w') as base_file:
47 config = '''{
48 "a": [
49 { "group_name": "b" }
51 "c": [
52 { "group_name": "d" }
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" }
62 "b": [
63 { "group_name": "bgroup" }
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='
71 'a/1/c/d/b/bgroup'], result)
73 if __name__ == '__main__':
74 unittest.main()