summaryrefslogtreecommitdiffstats
path: root/tools/variations/fieldtrial_util_unittest.py
blob: 1df6383e2201dc6ea91bf56c2910dc4f4479d40e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# Copyright 2015 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

import unittest
import fieldtrial_util
import tempfile


class FieldTrialUtilUnittest(unittest.TestCase):

  def test_GenArgsEmptyPaths(self):
    args = fieldtrial_util.GenerateArgs('', '')
    self.assertEqual([], args)

  def test_GenArgsOneConfig(self):
    with tempfile.NamedTemporaryFile('w') as base_file:
      config = '''{
        "BrowserBlackList": [
          { "group_name": "Enabled" }
        ],
        "c": [
          {
            "group_name": "d.",
            "params": {"url": "http://www.google.com"}
          }
        ],
        "SimpleParams": [
          {
            "group_name": "Default",
            "params": {"id": "abc"}
          }
        ]
      }'''
      base_file.write(config)
      base_file.flush()

      result = fieldtrial_util.GenerateArgs(base_file.name)
      self.assertEqual(['--force-fieldtrials='
          'BrowserBlackList/Enabled/c/d./SimpleParams/Default',
          '--force-fieldtrial-params='
          'c.d%2E:url/http%3A%2F%2Fwww%2Egoogle%2Ecom,'
          'SimpleParams.Default:id/abc'], result)

  def test_GenArgsOverrideConfig(self):
    with tempfile.NamedTemporaryFile('w') as base_file:
      config = '''{
        "a": [
          { "group_name": "b" }
        ],
        "c": [
          { "group_name": "d" }
        ]
      }'''
      base_file.write(config)
      base_file.flush()
      with tempfile.NamedTemporaryFile('w') as platform_file:
        config = '''{
          "a": [
            { "group_name": "1" }
          ],
          "b": [
            { "group_name": "bgroup" }
          ]
        }'''
        platform_file.write(config)
        platform_file.flush()
        result = fieldtrial_util.GenerateArgs(base_file.name,
            platform_file.name)
        self.assertEqual(['--force-fieldtrials='
            'a/1/c/d/b/bgroup'], result)

if __name__ == '__main__':
  unittest.main()