Chromium Code Reviews| 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_CHAR_ARRAY_LEN 256 | |
|
abarth-chromium
2014/03/05 18:01:42
Please use a constant instead of a #define.
| |
| 14 | |
| 15 namespace WebCore { | |
| 16 | |
| 17 typedef struct { | |
| 18 const char* input; | |
| 19 const char* output; | |
| 20 } TestCase; | |
| 21 | |
| 22 int getCharArray(String str, char* output) | |
| 23 { | |
| 24 if (!str.impl()) | |
|
abarth-chromium
2014/03/05 18:01:42
if (str.isNull())
| |
| 25 return 0; | |
| 26 | |
| 27 unsigned i; | |
| 28 if (str.is8Bit()) { | |
| 29 for (i = 0; i < str.length(); ++i) | |
| 30 output[i] = str.characters8()[i]; | |
| 31 } else { | |
| 32 for (i = 0; i < str.length(); ++i) | |
| 33 output[i] = str.characters16()[i]; | |
| 34 } | |
| 35 output[i++] = 0; | |
| 36 return i; | |
| 37 } | |
| 38 | |
| 39 TEST(MediaQueryParserTest, Basic) | |
| 40 { | |
| 41 // The first string represents the input string. | |
| 42 // The second string represents the output string, if present. | |
| 43 // Otherwise, the output string is identical to the first string. | |
| 44 TestCase testCases[] = { | |
| 45 {"screen", 0}, | |
| 46 {"screen and (color)", 0}, | |
| 47 {"all and (min-width:500px)", "(min-width: 500px)"}, | |
| 48 {"(min-width:500px)", "(min-width: 500px)"}, | |
| 49 {"screen and (color), projection and (color)", 0}, | |
| 50 {"not screen and (color)", 0}, | |
| 51 {"only screen and (color)", 0}, | |
| 52 {"screen and (color), projection and (color)", 0}, | |
| 53 {"aural and (device-aspect-ratio: 16/9)", 0}, | |
| 54 {"speech and (min-device-width: 800px)", 0}, | |
| 55 {"example", 0}, | |
| 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)", 0}, | |
| 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)", 0}, | |
| 63 {"screen and (device-height: 60em)", 0}, | |
| 64 {"screen and (device-aspect-ratio: 16/9)", 0}, | |
| 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)", 0}, | |
| 78 {"handheld and (grid) and (max-width: 15em)", 0}, | |
| 79 {"handheld and (grid) and (max-device-height: 7em)", 0}, | |
| 80 {"screen and (max-width: 50%)", "not all"}, | |
| 81 {"screen and (max-WIDTH: 500px)", "screen and (max-width: 500px)"}, | |
| 82 {"screen and (max-width: 24.4em)", 0}, | |
| 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)", "not all"}, | |
| 86 {"screen and (max-width: 0)", 0}, | |
| 87 {"screen and (max-width: 1deg)", "not all"}, | |
| 88 {"handheld and (min-width: 20em), \nscreen and (min-width: 20em)", "hand held and (min-width: 20em), screen and (min-width: 20em)"}, | |
| 89 {"print and (min-resolution: 300dpi)", 0}, | |
| 90 {"print and (min-resolution: 118dpcm)", 0}, | |
| 91 {"(resolution: 0.83333333333333333333dppx)", "(resolution: 0.83333333333 33334dppx)"}, | |
| 92 {"(resolution: 2.4dppx)", 0}, | |
| 93 {"all and(color)", "not all"}, | |
| 94 {"all and (", "not all"}, | |
| 95 {"test;,all", "not all, all"}, | |
| 96 // {"(color:20example)", "not all"}, // BisonCSSParser fails to parse th at MQ, producing an infinitesimal float. | |
| 97 {"not braille", 0}, | |
| 98 {",screen", "not all, screen"}, | |
| 99 {",all", "not all, all"}, | |
| 100 {",,all,,", "not all, not all, all, not all, not all"}, | |
| 101 {",,all,, ", "not all, not all, all, not all, not all"}, | |
| 102 {",screen,,&invalid,,", "not all, screen, not all, not all, not all, not all"}, | |
| 103 {",screen,,(invalid,),,", "not all, screen, not all, not all, not all, n ot all"}, | |
| 104 {",(all,),,", "not all, not all, not all, not all"}, | |
| 105 {",", "not all, not all"}, | |
| 106 // {" ", ""}, // BisonCSSParser fails to parse that MQ, producing "not all, not all". | |
| 107 {"(color", "(color)"}, | |
| 108 {"(min-color: 2", "(min-color: 2)"}, | |
| 109 {"(orientation: portrait)", 0}, | |
| 110 {"tv and (scan: progressive)", 0}, | |
| 111 {"(pointer: coarse)", 0}, | |
| 112 {"(min-orientation:portrait)", "not all"}, | |
| 113 {"all and (orientation:portrait)", "(orientation: portrait)"}, | |
| 114 {"all and (orientation:landscape)", "(orientation: landscape)"}, | |
| 115 {"NOT braille, tv AND (max-width: 200px) and (min-WIDTH: 100px) and (ori entation: landscape), (color)", | |
| 116 "not braille, tv and (max-width: 200px) and (min-width: 100px) and ( orientation: landscape), (color)"}, | |
| 117 {0, 0} // Do not remove the terminator line. | |
| 118 }; | |
| 119 | |
| 120 unsigned i = 0; | |
| 121 while (testCases[i].input) { | |
| 122 RefPtr<MediaQuerySet> querySet = MediaQuerySet::create(testCases[i].inpu t); | |
| 123 String output; | |
| 124 char outputCharArray[OUTPUT_CHAR_ARRAY_LEN]; | |
| 125 size_t j = 0; | |
| 126 while (j < querySet->queryVector().size()) { | |
| 127 String queryText = querySet->queryVector()[j]->cssText(); | |
| 128 output.append(queryText); | |
|
abarth-chromium
2014/03/05 18:01:42
Please don't call String#append, even in tests. W
| |
| 129 ++j; | |
| 130 if (j >= querySet->queryVector().size()) | |
| 131 break; | |
| 132 output.append(", "); | |
| 133 } | |
| 134 ASSERT(output.length() < OUTPUT_CHAR_ARRAY_LEN); | |
| 135 getCharArray(output, outputCharArray); | |
| 136 if (testCases[i].output) | |
| 137 ASSERT_STREQ(testCases[i].output, outputCharArray); | |
| 138 else | |
| 139 ASSERT_STREQ(testCases[i].input, outputCharArray); | |
| 140 | |
| 141 ++i; | |
|
abarth-chromium
2014/03/05 18:01:42
Why not use a for loop?
| |
| 142 } | |
| 143 } | |
| 144 | |
| 145 } // namespace | |
| OLD | NEW |