0cf5faacd0bc3157437ae86d3c83694ee2427db1
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / core / css / parser / SizesAttributeParserTest.cpp
1 // Copyright 2014 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.
4
5 #include "config.h"
6 #include "core/css/parser/SizesAttributeParser.h"
7
8 #include "core/MediaTypeNames.h"
9 #include "core/css/MediaValuesCached.h"
10
11 #include <gtest/gtest.h>
12
13 namespace blink {
14
15 typedef struct {
16     const char* input;
17     const float effectiveSize;
18 } TestCase;
19
20 TEST(SizesAttributeParserTest, Basic)
21 {
22     TestCase testCases[] = {
23         {"screen", 500},
24         {"(min-width:500px)", 500},
25         {"(min-width:500px) 200px", 200},
26         {"(min-width:500px) 50vw", 250},
27         {"(min-width:500px) 200px, 400px", 200},
28         {"400px, (min-width:500px) 200px", 400},
29         {"40vw, (min-width:500px) 201px", 200},
30         {"(min-width:500px) 201px, 40vw", 201},
31         {"(min-width:5000px) 40vw, 201px", 201},
32         {"(min-width:500px) calc(201px), calc(40vw)", 201},
33         {"(min-width:5000px) calc(40vw), calc(201px)", 201},
34         {"(min-width:5000px) 200px, 400px", 400},
35         {"(blalbadfsdf) 200px, 400px", 400},
36         {"0", 0},
37         {"-0", 0},
38         {"1", 500},
39         {"300px, 400px", 300},
40         {"(min-width:5000px) 200px, (min-width:500px) 400px", 400},
41         {"", 500},
42         {"  ", 500},
43         {" /**/ ", 500},
44         {" /**/ 300px", 300},
45         {"300px /**/ ", 300},
46         {" /**/ (min-width:500px) /**/ 300px", 300},
47         {"-100px, 200px", 200},
48         {"-50vw, 20vw", 100},
49         {"50asdf, 200px", 200},
50         {"asdf, 200px", 200},
51         {"(max-width: 3000px) 200w, 400w", 500},
52         {",, , /**/ ,200px", 200},
53         {"50vw", 250},
54         {"50vh", 300},
55         {"50vmin", 250},
56         {"50vmax", 300},
57         {"5em", 80},
58         {"5rem", 80},
59         {"calc(40vw*2)", 400},
60         {"(min-width:5000px) calc(5000px/10), (min-width:500px) calc(1200px/3)", 400},
61         {"(min-width:500px) calc(1200/3)", 500},
62         {"(min-width:500px) calc(1200px/(0px*14))", 500},
63         {"(max-width: 3000px) 200px, 400px", 200},
64         {"(max-width: 3000px) 20em, 40em", 320},
65         {"(max-width: 3000px) 0, 40em", 0},
66         {"(max-width: 3000px) 0px, 40em", 0},
67         {"(max-width: 3000px) 50vw, 40em", 250},
68         {"(max-width: 3000px) 50px, 40vw", 50},
69         {"((),1px", 500},
70         {"{{},1px", 500},
71         {"[[],1px", 500},
72         {"x(x(),1px", 500},
73         {"(max-width: 3000px) 50.5px, 40vw", 50.5},
74         {"not (blabla) 50px, 40vw", 200},
75         {"not (max-width: 100px) 50px, 40vw", 50},
76         {0, 0} // Do not remove the terminator line.
77     };
78
79     MediaValuesCached::MediaValuesCachedData data;
80     data.viewportWidth = 500;
81     data.viewportHeight = 600;
82     data.deviceWidth = 500;
83     data.deviceHeight = 500;
84     data.devicePixelRatio = 2.0;
85     data.colorBitsPerComponent = 24;
86     data.monochromeBitsPerComponent = 0;
87     data.primaryPointerType = PointerTypeFine;
88     data.defaultFontSize = 16;
89     data.threeDEnabled = true;
90     data.mediaType = MediaTypeNames::screen;
91     data.strictMode = true;
92     RefPtr<MediaValues> mediaValues = MediaValuesCached::create(data);
93
94     for (unsigned i = 0; testCases[i].input; ++i) {
95         SizesAttributeParser parser(mediaValues, testCases[i].input);
96         ASSERT_EQ(testCases[i].effectiveSize, parser.length());
97     }
98 }
99
100 } // namespace