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