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/parser/MediaQueryParser.h" | |
7 | |
8 #include "core/css/MediaList.h" | |
9 #include "core/css/MediaQuery.h" | |
10 #include "core/css/parser/CSSToken.h" | |
11 #include "wtf/PassOwnPtr.h" | |
12 | |
13 #include <gtest/gtest.h> | |
14 | |
15 namespace WebCore { | |
16 | |
17 TEST(MediaQueryParserTest, Basic) | |
18 { | |
19 Vector<pair<String, String> > testCases; | |
20 testCases.append(std::make_pair("screen", "")); | |
eseidel
2014/02/18 23:24:01
I might use a static helper method for this sort o
| |
21 testCases.append(std::make_pair("screen and (color)", "")); | |
22 testCases.append(std::make_pair("all and (min-width:500px)", "(min-width: 50 0px)")); | |
23 testCases.append(std::make_pair("(min-width:500px)", "(min-width: 500px)")); | |
24 testCases.append(std::make_pair("screen and (color), projection and (color)" , "")); | |
25 testCases.append(std::make_pair("not screen and (color)", "")); | |
26 testCases.append(std::make_pair("only screen and (color)", "")); | |
27 testCases.append(std::make_pair("screen and (color), projection and (color)" , "")); | |
28 testCases.append(std::make_pair("aural and (device-aspect-ratio: 16/9)", "") ); | |
29 testCases.append(std::make_pair("speech and (min-device-width: 800px)", "")) ; | |
30 testCases.append(std::make_pair("example", "")); | |
31 testCases.append(std::make_pair("screen and (max-weight: 3kg) and (color), ( monochrome)", "not all, (monochrome)")); | |
32 testCases.append(std::make_pair("(min-width: -100px)", "not all")); | |
33 testCases.append(std::make_pair("(example, all,), speech", "not all, speech" )); | |
34 testCases.append(std::make_pair("&test, screen", "not all, screen")); | |
35 testCases.append(std::make_pair("print and (min-width: 25cm)", "")); | |
36 testCases.append(std::make_pair("screen and (min-width: 400px) and (max-widt h: 700px)", "screen and (max-width: 700px) and (min-width: 400px)")); | |
37 testCases.append(std::make_pair("screen and (device-width: 800px)", "")); | |
38 testCases.append(std::make_pair("screen and (device-height: 60em)", "")); | |
39 testCases.append(std::make_pair("screen and (device-aspect-ratio: 16/9)", "" )); | |
40 testCases.append(std::make_pair("all and (color)", "(color)")); | |
41 testCases.append(std::make_pair("all and (min-color: 1)", "(min-color: 1)")) ; | |
42 testCases.append(std::make_pair("all and (min-color: 2)", "(min-color: 2)")) ; | |
43 testCases.append(std::make_pair("all and (color-index)", "(color-index)")); | |
44 testCases.append(std::make_pair("all and (min-color-index: 1)", "(min-color- index: 1)")); | |
45 testCases.append(std::make_pair("all and (monochrome)", "(monochrome)")); | |
46 testCases.append(std::make_pair("all and (min-monochrome: 1)", "(min-monochr ome: 1)")); | |
47 testCases.append(std::make_pair("all and (min-monochrome: 2)", "(min-monochr ome: 2)")); | |
48 testCases.append(std::make_pair("print and (monochrome)", "")); | |
49 testCases.append(std::make_pair("handheld and (grid) and (max-width: 15em)", "")); | |
50 testCases.append(std::make_pair("handheld and (grid) and (device-max-height: 7em)", "")); | |
51 testCases.append(std::make_pair("screen and (max-width: 50%)", "")); | |
52 testCases.append(std::make_pair("tv and (scan: progressive)", "")); | |
53 testCases.append(std::make_pair("print and (min-resolution: 300dpi)", "")); | |
54 testCases.append(std::make_pair("print and (min-resolution: 118dpcm)", "")); | |
55 testCases.append(std::make_pair("handheld and (min-width: 20em), \nscreen an d (min-width: 20em)", "")); | |
56 testCases.append(std::make_pair("all and(color)", "not all")); | |
57 testCases.append(std::make_pair("test;,all", "not all")); | |
58 testCases.append(std::make_pair("(orientation: portrait)", "")); | |
59 testCases.append(std::make_pair("(min-orientation:portrait)", "")); | |
60 testCases.append(std::make_pair("all and (orientation:portrait)", "")); | |
61 testCases.append(std::make_pair("all and (orientation:landscape)", "")); | |
62 testCases.append(std::make_pair("(color:20example)", "")); | |
63 | |
64 for (size_t i = 0; i < testCases.size(); ++i) { | |
65 RefPtr<MediaQuerySet> querySet = MediaQueryParser::parse(testCases[i].fi rst); | |
66 String output; | |
67 size_t j = 0; | |
68 while (j < querySet->queryVector().size()) { | |
69 String queryText = querySet->queryVector()[j]->cssText(); | |
70 output.append(queryText); | |
71 ++j; | |
72 if (j >= querySet->queryVector().size()) | |
73 break; | |
74 output.append(", "); | |
75 } | |
76 | |
77 if (testCases[i].second != "") | |
78 ASSERT_EQ(testCases[i].second, output); | |
79 else | |
80 ASSERT_EQ(testCases[i].first, output); | |
81 } | |
82 } | |
83 | |
84 } // namespace | |
OLD | NEW |