OLD | NEW |
---|---|
(Empty) | |
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/MediaQuery.h" | |
7 | |
8 #include "core/css/MediaList.h" | |
9 #include "wtf/PassOwnPtr.h" | |
10 | |
11 #include <gtest/gtest.h> | |
12 | |
13 #define OUTPUT_8BIT_LEN 256 | |
14 | |
15 namespace WebCore { | |
16 | |
17 typedef struct { | |
18 const char* input; | |
19 const char* output; | |
20 } TestCase; | |
21 | |
22 int get8BitString(String str, char* output) | |
kenneth.r.christiansen
2014/03/04 15:59:30
you write the same way if it is a 16bit string
| |
23 { | |
24 if (!str.impl()) { | |
25 return 0; | |
26 } | |
27 | |
28 unsigned i; | |
29 if (str.is8Bit()) { | |
30 for (i = 0; i < str.length(); ++i) | |
31 output[i] = str.characters8()[i]; | |
32 } else { | |
33 for (i = 0; i < str.length(); ++i) | |
34 output[i] = str.characters16()[i]; | |
35 } | |
36 output[i++] = 0; | |
37 return i; | |
38 } | |
39 | |
40 TEST(MediaQueryParserTest, Basic) | |
41 { | |
42 TestCase testCases[] = { | |
43 {"screen", ""}, | |
44 {"screen and (color)", ""}, | |
45 {"all and (min-width:500px)", "(min-width: 500px)"}, | |
46 {"(min-width:500px)", "(min-width: 500px)"}, | |
47 {"screen and (color), projection and (color)", ""}, | |
48 {"not screen and (color)", ""}, | |
49 {"only screen and (color)", ""}, | |
50 {"screen and (color), projection and (color)", ""}, | |
51 {"aural and (device-aspect-ratio: 16/9)", ""}, | |
52 {"speech and (min-device-width: 800px)", ""}, | |
53 {"example", ""}, | |
54 {"screen and (max-weight: 3kg) and (color), (monochrome)", "not all, (mo nochrome)"}, | |
55 {"(min-width: -100px)", "not all"}, | |
56 {"(example, all,), speech", "not all, speech"}, | |
57 {"&test, screen", "not all, screen"}, | |
58 {"print and (min-width: 25cm)", ""}, | |
59 {"screen and (min-width: 400px) and (max-width: 700px)", "screen and (ma x-width: 700px) and (min-width: 400px)"}, | |
60 {"screen and (device-width: 800px)", ""}, | |
61 {"screen and (device-height: 60em)", ""}, | |
62 {"screen and (device-aspect-ratio: 16/9)", ""}, | |
63 {"(device-aspect-ratio: 16.0/9.0)", "not all"}, | |
64 {"(device-aspect-ratio: 16/ 9)", "(device-aspect-ratio: 16/9)"}, | |
65 {"(device-aspect-ratio: 16/\r9)", "(device-aspect-ratio: 16/9)"}, | |
66 {"all and (color)", "(color)"}, | |
67 {"all and (min-color: 1)", "(min-color: 1)"}, | |
68 {"all and (min-color: 1.0)", "not all"}, | |
69 {"all and (min-color: 2)", "(min-color: 2)"}, | |
70 {"all and (color-index)", "(color-index)"}, | |
71 {"all and (min-color-index: 1)", "(min-color-index: 1)"}, | |
72 {"all and (monochrome)", "(monochrome)"}, | |
73 {"all and (min-monochrome: 1)", "(min-monochrome: 1)"}, | |
74 {"all and (min-monochrome: 2)", "(min-monochrome: 2)"}, | |
75 {"print and (monochrome)", ""}, | |
76 {"handheld and (grid) and (max-width: 15em)", ""}, | |
77 {"handheld and (grid) and (max-device-height: 7em)", ""}, | |
78 {"screen and (max-width: 50%)", "not all"}, | |
79 {"screen and (max-WIDTH: 500px)", "screen and (max-width: 500px)"}, | |
80 {"screen and (max-width: 24.4em)", ""}, | |
81 {"screen and (max-width: 24.4EM)", "screen and (max-width: 24.4em)"}, | |
82 {"screen and (max-width: blabla)", "not all"}, | |
83 {"screen and (max-width: 1)", "not all"}, | |
84 {"screen and (max-width: 0)", ""}, | |
85 {"screen and (max-width: 1deg)", "not all"}, | |
86 {"handheld and (min-width: 20em), \nscreen and (min-width: 20em)", "hand held and (min-width: 20em), screen and (min-width: 20em)"}, | |
87 {"print and (min-resolution: 300dpi)", ""}, | |
88 {"print and (min-resolution: 118dpcm)", ""}, | |
89 {"(resolution: 0.83333333333333333333dppx)", "(resolution: 0.83333333333 33334dppx)"}, | |
90 {"(resolution: 2.4dppx)", ""}, | |
91 {"all and(color)", "not all"}, | |
92 {"all and (", "not all"}, | |
93 {"test;,all", "not all, all"}, | |
94 {"(color:20example)", "not all"}, | |
95 {"not braille", ""}, | |
96 {",screen", "not all, screen"}, | |
97 {",all", "not all, all"}, | |
98 {",,all,,", "not all, not all, all, not all, not all"}, | |
99 {",,all,, ", "not all, not all, all, not all, not all"}, | |
100 {",screen,,&invalid,,", "not all, screen, not all, not all, not all, not all"}, | |
101 {",screen,,(invalid,),,", "not all, screen, not all, not all, not all, n ot all"}, | |
102 {",(all,),,", "not all, not all, not all, not all"}, | |
103 {",", "not all, not all"}, | |
104 {" ", ""}, | |
105 {"(color", "(color)"}, | |
106 {"(min-color: 2", "(min-color: 2)"}, | |
107 {"(orientation: portrait)", ""}, | |
108 {"tv and (scan: progressive)", ""}, | |
109 {"(pointer: coarse)", ""}, | |
110 {"(min-orientation:portrait)", "not all"}, | |
111 {"all and (orientation:portrait)", "(orientation: portrait)"}, | |
112 {"all and (orientation:landscape)", "(orientation: landscape)"}, | |
113 {"NOT braille, tv AND (max-width: 200px) and (min-WIDTH: 100px) and (ori entation: landscape), (color)", | |
114 "not braille, tv and (max-width: 200px) and (min-width: 100px) and ( orientation: landscape), (color)"}, | |
115 {"", ""} // That's here as a terminator for the loop. Do not remove! | |
kenneth.r.christiansen
2014/03/04 15:59:30
why not 0, 0?
| |
116 }; | |
117 | |
118 unsigned i = 0; | |
119 while (testCases[i].input[0]) { | |
120 RefPtr<MediaQuerySet> querySet = MediaQuerySet::create(testCases[i].inpu t); | |
121 String output; | |
122 char output8bit[OUTPUT_8BIT_LEN]; | |
123 size_t j = 0; | |
124 while (j < querySet->queryVector().size()) { | |
125 String queryText = querySet->queryVector()[j]->cssText(); | |
126 output.append(queryText); | |
127 ++j; | |
128 if (j >= querySet->queryVector().size()) | |
129 break; | |
130 output.append(", "); | |
131 } | |
132 ASSERT(output.length() < OUTPUT_8BIT_LEN); | |
133 get8BitString(output, output8bit); | |
134 if (testCases[i].output[0]) | |
135 ASSERT_STREQ(testCases[i].output, output8bit); | |
136 else if (testCases[i].input[0] != ' ') | |
137 ASSERT_STREQ(testCases[i].input, output8bit); | |
138 else | |
139 ASSERT_EQ((unsigned)0, output.length()); | |
140 | |
141 ++i; | |
142 } | |
143 } | |
144 | |
145 } // namespace | |
OLD | NEW |