summaryrefslogtreecommitdiffstats
path: root/third_party/libwebrtc/tools/grit/minimize_css_unittest.py
blob: cddc3130788108ff7ba21f3439ad76babe8c6003 (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
#!/usr/bin/env python
# Copyright 2016 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 minimize_css


class CSSMinimizerTest(unittest.TestCase):

    def test_simple(self):
        source = """
            div {
                color: blue;
            }
        """
        minimized = minimize_css.CSSMinimizer.minimize_css(source)
        self.assertEquals(minimized, "div{color: blue}")

    def test_attribute_selectors(self):
        source = """
            input[type="search" i]::-webkit-textfield-decoration-container {
                direction: ltr;
            }
        """
        minimized = minimize_css.CSSMinimizer.minimize_css(source)
        self.assertEquals(
            minimized,
            # pylint: disable=line-too-long
            """input[type="search" i]::-webkit-textfield-decoration-container{direction: ltr}""")

    def test_strip_comment(self):
        source = """
        /* header */
        html {
            /* inside block */
            display: block;
        }
        /* footer */
        """
        minimized = minimize_css.CSSMinimizer.minimize_css(source)
        self.assertEquals(minimized, "html{ display: block}")

    def test_no_strip_inside_quotes(self):
        source = """div[foo=' bar ']"""
        minimized = minimize_css.CSSMinimizer.minimize_css(source)
        self.assertEquals(minimized, source)

        source = """div[foo=" bar "]"""
        minimized = minimize_css.CSSMinimizer.minimize_css(source)
        self.assertEquals(minimized, source)

    def test_escape_string(self):
        source = """content: " <a onclick=\\\"javascript:  alert  ( 'foobar' ); \\\">";"""
        minimized = minimize_css.CSSMinimizer.minimize_css(source)
        self.assertEquals(minimized, source)