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 | |
| 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()) { | |
|
kenneth.r.christiansen
2014/03/04 18:18:45
that normally wouldnt need braces
| |
| 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 // These are the test cases. | |
|
kenneth.r.christiansen
2014/03/04 18:18:45
kind of unneeded comment
| |
| 43 // The first string represents the input string. | |
| 44 // The second string represents the output string. | |
| 45 // If the second string is "", the output string is identical to the first s tring. | |
|
kenneth.r.christiansen
2014/03/04 18:18:45
An output string of "" represent identical input a
| |
| 46 TestCase testCases[] = { | |
| 47 {"screen", ""}, | |
| 48 {"screen and (color)", ""}, | |
| 49 {"all and (min-width:500px)", "(min-width: 500px)"}, | |
| 50 {"(min-width:500px)", "(min-width: 500px)"}, | |
| 51 {"screen and (color), projection and (color)", ""}, | |
| 52 {"not screen and (color)", ""}, | |
| 53 {"only screen and (color)", ""}, | |
| 54 {"screen and (color), projection and (color)", ""}, | |
| 55 {"aural and (device-aspect-ratio: 16/9)", ""}, | |
| 56 {"speech and (min-device-width: 800px)", ""}, | |
| 57 {"example", ""}, | |
| 58 {"screen and (max-weight: 3kg) and (color), (monochrome)", "not all, (mo nochrome)"}, | |
| 59 {"(min-width: -100px)", "not all"}, | |
| 60 {"(example, all,), speech", "not all, speech"}, | |
| 61 {"&test, screen", "not all, screen"}, | |
| 62 {"print and (min-width: 25cm)", ""}, | |
| 63 {"screen and (min-width: 400px) and (max-width: 700px)", "screen and (ma x-width: 700px) and (min-width: 400px)"}, | |
| 64 {"screen and (device-width: 800px)", ""}, | |
| 65 {"screen and (device-height: 60em)", ""}, | |
| 66 {"screen and (device-aspect-ratio: 16/9)", ""}, | |
| 67 {"(device-aspect-ratio: 16.0/9.0)", "not all"}, | |
| 68 {"(device-aspect-ratio: 16/ 9)", "(device-aspect-ratio: 16/9)"}, | |
| 69 {"(device-aspect-ratio: 16/\r9)", "(device-aspect-ratio: 16/9)"}, | |
| 70 {"all and (color)", "(color)"}, | |
| 71 {"all and (min-color: 1)", "(min-color: 1)"}, | |
| 72 {"all and (min-color: 1.0)", "not all"}, | |
| 73 {"all and (min-color: 2)", "(min-color: 2)"}, | |
| 74 {"all and (color-index)", "(color-index)"}, | |
| 75 {"all and (min-color-index: 1)", "(min-color-index: 1)"}, | |
| 76 {"all and (monochrome)", "(monochrome)"}, | |
| 77 {"all and (min-monochrome: 1)", "(min-monochrome: 1)"}, | |
| 78 {"all and (min-monochrome: 2)", "(min-monochrome: 2)"}, | |
| 79 {"print and (monochrome)", ""}, | |
| 80 {"handheld and (grid) and (max-width: 15em)", ""}, | |
| 81 {"handheld and (grid) and (max-device-height: 7em)", ""}, | |
| 82 {"screen and (max-width: 50%)", "not all"}, | |
| 83 {"screen and (max-WIDTH: 500px)", "screen and (max-width: 500px)"}, | |
| 84 {"screen and (max-width: 24.4em)", ""}, | |
| 85 {"screen and (max-width: 24.4EM)", "screen and (max-width: 24.4em)"}, | |
| 86 {"screen and (max-width: blabla)", "not all"}, | |
| 87 {"screen and (max-width: 1)", "not all"}, | |
| 88 {"screen and (max-width: 0)", ""}, | |
| 89 {"screen and (max-width: 1deg)", "not all"}, | |
| 90 {"handheld and (min-width: 20em), \nscreen and (min-width: 20em)", "hand held and (min-width: 20em), screen and (min-width: 20em)"}, | |
| 91 {"print and (min-resolution: 300dpi)", ""}, | |
| 92 {"print and (min-resolution: 118dpcm)", ""}, | |
| 93 {"(resolution: 0.83333333333333333333dppx)", "(resolution: 0.83333333333 33334dppx)"}, | |
| 94 {"(resolution: 2.4dppx)", ""}, | |
| 95 {"all and(color)", "not all"}, | |
| 96 {"all and (", "not all"}, | |
| 97 {"test;,all", "not all, all"}, | |
| 98 // {"(color:20example)", "not all"}, // BisonCSSParser fails to parse th at MQ, producing an infinitesimal float | |
| 99 {"not braille", ""}, | |
| 100 {",screen", "not all, screen"}, | |
| 101 {",all", "not all, all"}, | |
| 102 {",,all,,", "not all, not all, all, not all, not all"}, | |
| 103 {",,all,, ", "not all, not all, all, not all, not all"}, | |
| 104 {",screen,,&invalid,,", "not all, screen, not all, not all, not all, not all"}, | |
| 105 {",screen,,(invalid,),,", "not all, screen, not all, not all, not all, n ot all"}, | |
| 106 {",(all,),,", "not all, not all, not all, not all"}, | |
| 107 {",", "not all, not all"}, | |
| 108 {" ", ""}, | |
| 109 {"(color", "(color)"}, | |
| 110 {"(min-color: 2", "(min-color: 2)"}, | |
| 111 {"(orientation: portrait)", ""}, | |
| 112 {"tv and (scan: progressive)", ""}, | |
| 113 {"(pointer: coarse)", ""}, | |
| 114 {"(min-orientation:portrait)", "not all"}, | |
| 115 {"all and (orientation:portrait)", "(orientation: portrait)"}, | |
| 116 {"all and (orientation:landscape)", "(orientation: landscape)"}, | |
| 117 {"NOT braille, tv AND (max-width: 200px) and (min-WIDTH: 100px) and (ori entation: landscape), (color)", | |
| 118 "not braille, tv and (max-width: 200px) and (min-width: 100px) and ( orientation: landscape), (color)"}, | |
| 119 {0, 0} // That's here as a terminator for the loop. Do not remove! | |
|
kenneth.r.christiansen
2014/03/04 18:18:45
That should be obvious to most people now you use
| |
| 120 }; | |
| 121 | |
| 122 unsigned i = 0; | |
| 123 while (testCases[i].input) { | |
| 124 RefPtr<MediaQuerySet> querySet = MediaQuerySet::create(testCases[i].inpu t); | |
| 125 String output; | |
| 126 char outputCharArray[OUTPUT_CHAR_ARRAY_LEN]; | |
| 127 size_t j = 0; | |
| 128 while (j < querySet->queryVector().size()) { | |
| 129 String queryText = querySet->queryVector()[j]->cssText(); | |
| 130 output.append(queryText); | |
| 131 ++j; | |
| 132 if (j >= querySet->queryVector().size()) | |
| 133 break; | |
| 134 output.append(", "); | |
| 135 } | |
| 136 ASSERT(output.length() < OUTPUT_CHAR_ARRAY_LEN); | |
| 137 getCharArray(output, outputCharArray); | |
| 138 if (testCases[i].output[0]) | |
| 139 ASSERT_STREQ(testCases[i].output, outputCharArray); | |
| 140 else if (testCases[i].input[0] != ' ') | |
| 141 ASSERT_STREQ(testCases[i].input, outputCharArray); | |
| 142 else | |
| 143 ASSERT_EQ((unsigned)0, output.length()); | |
|
kenneth.r.christiansen
2014/03/04 18:18:45
static_cast instaed of C cast?
| |
| 144 | |
| 145 ++i; | |
| 146 } | |
| 147 } | |
| 148 | |
| 149 } // namespace | |
| OLD | NEW |