Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(123)

Side by Side Diff: Source/core/css/MediaQuerySetTest.cpp

Issue 186603002: Length MQs invalidate non zero numbers (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Fixed build issue Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Source/core/css/MediaQueryExp.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 #include "wtf/text/StringBuilder.h"
11
12 #include <gtest/gtest.h>
13
14 const unsigned outputCharArrayLen = 256;
15
16 namespace WebCore {
17
18 typedef struct {
19 const char* input;
20 const char* output;
21 } TestCase;
22
23 int getCharArray(String str, char* output)
24 {
25 if (str.isNull())
26 return 0;
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 // The first string represents the input string.
43 // The second string represents the output string, if present.
44 // Otherwise, the output string is identical to the first string.
45 TestCase testCases[] = {
46 {"screen", 0},
47 {"screen and (color)", 0},
48 {"all and (min-width:500px)", "(min-width: 500px)"},
49 {"(min-width:500px)", "(min-width: 500px)"},
50 {"screen and (color), projection and (color)", 0},
51 {"not screen and (color)", 0},
52 {"only screen and (color)", 0},
53 {"screen and (color), projection and (color)", 0},
54 {"aural and (device-aspect-ratio: 16/9)", 0},
55 {"speech and (min-device-width: 800px)", 0},
56 {"example", 0},
57 {"screen and (max-weight: 3kg) and (color), (monochrome)", "not all, (mo nochrome)"},
58 {"(min-width: -100px)", "not all"},
59 {"(example, all,), speech", "not all, speech"},
60 {"&test, screen", "not all, screen"},
61 {"print and (min-width: 25cm)", 0},
62 {"screen and (min-width: 400px) and (max-width: 700px)", "screen and (ma x-width: 700px) and (min-width: 400px)"},
63 {"screen and (device-width: 800px)", 0},
64 {"screen and (device-height: 60em)", 0},
65 {"screen and (device-aspect-ratio: 16/9)", 0},
66 {"(device-aspect-ratio: 16.0/9.0)", "not all"},
67 {"(device-aspect-ratio: 16/ 9)", "(device-aspect-ratio: 16/9)"},
68 {"(device-aspect-ratio: 16/\r9)", "(device-aspect-ratio: 16/9)"},
69 {"all and (color)", "(color)"},
70 {"all and (min-color: 1)", "(min-color: 1)"},
71 {"all and (min-color: 1.0)", "not all"},
72 {"all and (min-color: 2)", "(min-color: 2)"},
73 {"all and (color-index)", "(color-index)"},
74 {"all and (min-color-index: 1)", "(min-color-index: 1)"},
75 {"all and (monochrome)", "(monochrome)"},
76 {"all and (min-monochrome: 1)", "(min-monochrome: 1)"},
77 {"all and (min-monochrome: 2)", "(min-monochrome: 2)"},
78 {"print and (monochrome)", 0},
79 {"handheld and (grid) and (max-width: 15em)", 0},
80 {"handheld and (grid) and (max-device-height: 7em)", 0},
81 {"screen and (max-width: 50%)", "not all"},
82 {"screen and (max-WIDTH: 500px)", "screen and (max-width: 500px)"},
83 {"screen and (max-width: 24.4em)", 0},
84 {"screen and (max-width: 24.4EM)", "screen and (max-width: 24.4em)"},
85 {"screen and (max-width: blabla)", "not all"},
86 {"screen and (max-width: 1)", "not all"},
87 {"screen and (max-width: 0)", 0},
88 {"screen and (max-width: 1deg)", "not all"},
89 {"handheld and (min-width: 20em), \nscreen and (min-width: 20em)", "hand held and (min-width: 20em), screen and (min-width: 20em)"},
90 {"print and (min-resolution: 300dpi)", 0},
91 {"print and (min-resolution: 118dpcm)", 0},
92 {"(resolution: 0.83333333333333333333dppx)", "(resolution: 0.83333333333 33334dppx)"},
93 {"(resolution: 2.4dppx)", 0},
94 {"all and(color)", "not all"},
95 {"all and (", "not all"},
96 {"test;,all", "not all, all"},
97 // {"(color:20example)", "not all"}, // BisonCSSParser fails to parse th at MQ, producing an infinitesimal float.
98 {"not braille", 0},
99 {",screen", "not all, screen"},
100 {",all", "not all, all"},
101 {",,all,,", "not all, not all, all, not all, not all"},
102 {",,all,, ", "not all, not all, all, not all, not all"},
103 {",screen,,&invalid,,", "not all, screen, not all, not all, not all, not all"},
104 {",screen,,(invalid,),,", "not all, screen, not all, not all, not all, n ot all"},
105 {",(all,),,", "not all, not all, not all, not all"},
106 {",", "not all, not all"},
107 // {" ", ""}, // BisonCSSParser fails to parse that MQ, producing "not all, not all".
108 {"(color", "(color)"},
109 {"(min-color: 2", "(min-color: 2)"},
110 {"(orientation: portrait)", 0},
111 {"tv and (scan: progressive)", 0},
112 {"(pointer: coarse)", 0},
113 {"(min-orientation:portrait)", "not all"},
114 {"all and (orientation:portrait)", "(orientation: portrait)"},
115 {"all and (orientation:landscape)", "(orientation: landscape)"},
116 {"NOT braille, tv AND (max-width: 200px) and (min-WIDTH: 100px) and (ori entation: landscape), (color)",
117 "not braille, tv and (max-width: 200px) and (min-width: 100px) and ( orientation: landscape), (color)"},
118 {0, 0} // Do not remove the terminator line.
119 };
120
121 for (unsigned i = 0; testCases[i].input; ++i) {
122 RefPtr<MediaQuerySet> querySet = MediaQuerySet::create(testCases[i].inpu t);
123 StringBuilder output;
124 char outputCharArray[outputCharArrayLen];
125 size_t j = 0;
126 while (j < querySet->queryVector().size()) {
127 String queryText = querySet->queryVector()[j]->cssText();
128 output.append(queryText);
129 ++j;
130 if (j >= querySet->queryVector().size())
131 break;
132 output.append(", ");
133 }
134 ASSERT(output.length() < outputCharArrayLen);
135 getCharArray(output.toString(), outputCharArray);
136 if (testCases[i].output)
137 ASSERT_STREQ(testCases[i].output, outputCharArray);
138 else
139 ASSERT_STREQ(testCases[i].input, outputCharArray);
140 }
141 }
142
143 } // namespace
OLDNEW
« no previous file with comments | « Source/core/css/MediaQueryExp.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698