summaryrefslogtreecommitdiffstats
path: root/chromium/components/policy/tools/template_writers/writers/android_policy_writer_unittest.py
blob: a282bc5aab8d5869fd956c341a0b8d1e8c2a134d (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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#!/usr/bin/env python3
# Copyright (c) 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.
'''Unit tests for writers.android_policy_writer'''

import os
import sys
if __name__ == '__main__':
  sys.path.append(os.path.join(os.path.dirname(__file__), '../../../..'))

import unittest
from xml.dom import minidom

from writers import writer_unittest_common
from writers import android_policy_writer


class AndroidPolicyWriterUnittest(writer_unittest_common.WriterUnittestCommon):
  '''Unit tests to test assumptions in Android Policy Writer'''

  def testPolicyWithoutItems(self):
    # Test an example policy without items.
    policy = {
        'name': '_policy_name',
        'caption': '_policy_caption',
        'desc': 'This is a long policy caption. More than one sentence '
                'in a single line because it is very important.\n'
                'Second line, also important'
    }
    writer = android_policy_writer.GetWriter({})
    writer.Init()
    writer.BeginTemplate()
    writer.WritePolicy(policy)
    self.assertEquals(
        writer._resources.toxml(), '<resources>'
        '<string name="_policy_nameTitle">_policy_caption</string>'
        '<string name="_policy_nameDesc">This is a long policy caption. More '
        'than one sentence in a single line because it is very '
        'important.\nSecond line, also important'
        '</string>'
        '</resources>')

  def testPolicyWithItems(self):
    # Test an example policy without items.
    policy = {
        'name':
        '_policy_name',
        'caption':
        '_policy_caption',
        'desc':
        '_policy_desc_first.\nadditional line',
        'items': [{
            'caption': '_caption1',
            'value': '_value1',
        }, {
            'caption': '_caption2',
            'value': '_value2',
        },
                  {
                      'caption': '_caption3',
                      'value': '_value3',
                      'supported_on': [{
                          'platform': 'win'
                      }, {
                          'platform': 'win7'
                      }]
                  },
                  {
                      'caption':
                      '_caption4',
                      'value':
                      '_value4',
                      'supported_on': [{
                          'platform': 'android'
                      }, {
                          'platform': 'win7'
                      }]
                  }]
    }
    writer = android_policy_writer.GetWriter({})
    writer.Init()
    writer.BeginTemplate()
    writer.WritePolicy(policy)
    self.assertEquals(
        writer._resources.toxml(), '<resources>'
        '<string name="_policy_nameTitle">_policy_caption</string>'
        '<string name="_policy_nameDesc">_policy_desc_first.\n'
        'additional line</string>'
        '<string-array name="_policy_nameEntries">'
        '<item>_caption1</item>'
        '<item>_caption2</item>'
        '<item>_caption4</item>'
        '</string-array>'
        '<string-array name="_policy_nameValues">'
        '<item>_value1</item>'
        '<item>_value2</item>'
        '<item>_value4</item>'
        '</string-array>'
        '</resources>')


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